import { RESOURCE_PATHS } from 'sandstone/arguments' import { ContainerNode } from '../../nodes' import type { SandstoneCore } from '../../sandstoneCore' import type { ListResource, ResourceClassArguments, ResourceNode } from '../resource' import { JsonResource, ResourceClass, jsonStringify } from '../resource' import type { AllKeys } from 'sandstone/utils' import type { JsonSymbolResource } from 'sandstone/arguments/generated/_json/dispatcher' export type BlockStateDefinitionJSON = NonNullable export type BlockStateDefinitionType = AllKeys /** * A node representing a Minecraft block state definition. */ export class BlockStateDefinitionNode extends ContainerNode implements ResourceNode> { constructor( sandstoneCore: SandstoneCore, public resource: BlockStateDefinitionClass, ) { super(sandstoneCore) } getValue = () => jsonStringify(this.resource.json, this.resource._resourceType as keyof typeof RESOURCE_PATHS) } export type BlockStateDefinitionArguments = { /** * The block state definition's JSON. */ json: JSON } & ResourceClassArguments<'list'> export class BlockStateDefinitionClass, BlockStateDefinitionType>> extends ResourceClass> implements JsonResource, ListResource { static readonly resourceType = 'block_definition' json: JSON type: Type constructor( core: SandstoneCore, name: string, args: BlockStateDefinitionArguments, ) { super( core, { packType: core.pack.resourcePack() }, BlockStateDefinitionNode, BlockStateDefinitionClass.resourceType, core.pack.resourceToPath(name, RESOURCE_PATHS[BlockStateDefinitionClass.resourceType].path), args, ) this.json = args.json this.type = Object.keys(this.json)[0] as Type this.handleConflicts() } push(...states: BlockStateDefinitionClass[] | BlockStateDefinitionJSON[]) { if (this.type === 'variants') { if (states[0] instanceof BlockStateDefinitionClass) { for (const state of states) { /** @ts-ignore */ this.json.variants = { ...this.json.variants, ...state.blockStateDefinitionJSON.variants } } } else { for (const state of states) { /** @ts-ignore */ this.json.variants = { ...this.json.variants, ...state.variants } } } } if (this.type === 'multipart') { if (states[0] instanceof BlockStateDefinitionClass) { for (const state of states) { /** @ts-ignore */ this.json.multipart.push(...state.blockStateDefinitionJSON.multipart) } } else { for (const state of states) { /** @ts-ignore */ this.json.multipart.push(...state.multipart) } } } } unshift(...states: BlockStateDefinitionClass[] | BlockStateDefinitionJSON[]) { if (this.type === 'variants') { if (states[0] instanceof BlockStateDefinitionClass) { for (const state of states) { /** @ts-ignore */ this.json.variants = { ...state.blockStateDefinitionJSON.variants, ...this.json.variants } } } else { for (const state of states) { /** @ts-ignore */ this.json.variants = { ...state.variants, ...this.json.variants } } } } if (this.type === 'multipart') { if (states[0] instanceof BlockStateDefinitionClass) { for (const state of states) { /** @ts-ignore */ this.json.multipart.unshift(...state.blockStateDefinitionJSON.multipart) } } else { for (const state of states) { /** @ts-ignore */ this.json.multipart.unshift(...state.multipart) } } } } async load() {} }