import { type RESOURCE_PATHS } from 'sandstone/arguments' import { ContainerNode } from '../../../nodes' import type { SandstoneCore } from '../../../sandstoneCore' import type { ResourceClassArguments, ResourceNode } from '../../resource' import { JsonResource, ResourceClass, jsonStringify } from '../../resource' import type { JsonSymbolResource } from 'sandstone/arguments/generated/_json/dispatcher' export type AudibleVariantType = ( | 'cat' | 'chicken' | 'cow' | 'pig' | 'wolf' ) /** * All supported variant types. */ export type VariantType = ( | 'frog' | 'painting' | 'zombie_nautilus' | AudibleVariantType | `${AudibleVariantType}_sound` ) /** * Maps variant types to their SymbolResource keys. */ type VariantSymbolKey = `${T}_variant` /** * Gets the JSON type for a variant from SymbolResource. */ type VariantJSON = JsonSymbolResource[VariantSymbolKey] /** * A node representing a Minecraft entity variant. */ export class VariantNode extends ContainerNode implements ResourceNode> { constructor( sandstoneCore: SandstoneCore, public resource: VariantClass, ) { super(sandstoneCore) } getValue = () => jsonStringify(this.resource.json, this.resource._resourceType as keyof typeof RESOURCE_PATHS) } export type VariantClassArguments = { /** * The variant's JSON. */ variant: VariantJSON } & ResourceClassArguments<'default'> export class VariantClass extends ResourceClass> implements JsonResource { static readonly resourceType = 'variant' public json: NonNullable> constructor( sandstoneCore: SandstoneCore, public variantType: T, name: string, args: VariantClassArguments, ) { super( sandstoneCore, { packType: sandstoneCore.pack.dataPack(), extension: 'json' }, VariantNode, `${variantType}_${VariantClass.resourceType}`, sandstoneCore.pack.resourceToPath(name, [`${variantType}_${VariantClass.resourceType}`]), args, ) this.json = args.variant this.handleConflicts() } }