minerender 2.1.0-alpha.138 → 2.1.0-alpha.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2491,11 +2491,21 @@ interface Palette {
2491
2491
  };
2492
2492
  }
2493
2493
  interface PaletteEntry {
2494
- Name: {
2494
+ Name?: {
2495
2495
  type: "string";
2496
2496
  value: string;
2497
2497
  };
2498
- Properties: {
2498
+ id?: {
2499
+ type: "string";
2500
+ value: string;
2501
+ };
2502
+ Properties?: {
2503
+ type: "compound";
2504
+ value: {
2505
+ [property: string]: PalettePropertyValue;
2506
+ };
2507
+ };
2508
+ properties?: {
2499
2509
  type: "compound";
2500
2510
  value: {
2501
2511
  [property: string]: PalettePropertyValue;
@@ -21,13 +21,16 @@ var StructureParser = class {
21
21
  const blocks = nbt.blocks.value.value.map((block) => {
22
22
  const state = palette.value.value[block.state.value];
23
23
  if (!state) throw new MineRenderError(`Structure palette index ${block.state.value} does not exist`);
24
- if (["minecraft:air", "minecraft:cave_air", "minecraft:void_air"].includes(state.Name.value)) return void 0;
24
+ const name = (state.Name ?? state.id)?.value;
25
+ if (!name) throw new MineRenderError(`Structure palette entry ${block.state.value} has no block name`);
26
+ if (["minecraft:air", "minecraft:cave_air", "minecraft:void_air"].includes(name)) return void 0;
25
27
  const props = {};
26
- for (let k in state.Properties?.value) {
27
- props[k] = state.Properties.value[k].value;
28
+ const properties = (state.Properties ?? state.properties)?.value;
29
+ for (let k in properties) {
30
+ props[k] = properties[k].value;
28
31
  }
29
32
  return {
30
- type: state.Name.value,
33
+ type: name,
31
34
  properties: props,
32
35
  position: block.pos.value.value,
33
36
  nbt: block.nbt
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/model/multiblock/StructureParser.ts"],"sourcesContent":["import { MultiBlockBlock, MultiBlockStructure } from \"./MultiBlockStructure\";\nimport { TripleArray } from \"../Model\";\nimport type { NBT } from \"prismarine-nbt\";\nimport { MineRenderError } from \"../../error/MineRenderError\";\nimport { BlockStateProperties } from \"../block/BlockStateProperties\";\n\n/** Converts Java structure NBT into blocks and preserved entity data for world placement. */\nexport class StructureParser {\n\n /**\n * Parses decoded NBT, omitting air blocks.\n * @param _nbt - Structure data decoded by {@link NBTHelper.fromBuffer}.\n * @param paletteIndex - Palette to select when the structure has several. Defaults to 0.\n */\n public static async parse(_nbt: NBT, paletteIndex?: number): Promise<MultiBlockStructure> {\n const nbt = _nbt.value as unknown as StructureNBT;\n\n let palette: Palette;\n if (\"palette\" in nbt) {\n palette = nbt.palette!;\n } else if (\"palettes\" in nbt) {\n const selected = nbt.palettes!.value.value[paletteIndex ?? 0];\n if (!selected) throw new MineRenderError(`Structure palette ${paletteIndex ?? 0} does not exist`);\n palette = { type: \"list\", value: selected };\n } else {\n throw new MineRenderError(\"Structure does not have palette(s)\");\n }\n\n const blocks: MultiBlockBlock[] =\n nbt.blocks.value.value.map(block => {\n const state = palette.value.value[block.state.value];\n if (!state) throw new MineRenderError(`Structure palette index ${block.state.value} does not exist`);\n if ([\"minecraft:air\", \"minecraft:cave_air\", \"minecraft:void_air\"].includes(state.Name.value)) return undefined;\n\n const props: BlockStateProperties = {};\n for (let k in state.Properties?.value) {\n props[k] = state.Properties.value[k].value;\n }\n return <MultiBlockBlock>{\n type: state.Name.value,\n properties: props,\n position: block.pos.value.value,\n nbt: block.nbt\n }\n }).filter(m => typeof m !== \"undefined\") as MultiBlockBlock[] ;\n return {\n blocks: blocks,\n size: nbt.size.value.value,\n dataVersion: nbt.DataVersion?.value,\n entities: (nbt.entities?.value.value ?? []).map(entity => ({\n position: entity.pos.value.value,\n blockPosition: entity.blockPos.value.value,\n nbt: entity.nbt\n }))\n }\n }\n\n}\n\n/** Tagged NBT fields used by Java structure files. */\nexport interface StructureNBT {\n DataVersion?: {\n type: \"int\";\n value: number;\n }\n size: {\n type: \"list\";\n value: {\n type: \"int\";\n value: TripleArray;\n }\n }\n palette?: Palette;\n palettes?: {\n type: \"list\";\n value: { type: \"list\"; value: Palette[\"value\"][] };\n };\n blocks: {\n type: \"list\";\n value: {\n type: \"compound\";\n value: BlockEntry[];\n }\n }\n entities?: {\n type: \"list\";\n value: {\n type: \"compound\";\n value: {\n pos: { type: \"list\"; value: { type: \"double\"; value: TripleArray } };\n blockPos: { type: \"list\"; value: { type: \"int\"; value: TripleArray } };\n nbt: { type: \"compound\"; value: any };\n }[];\n };\n };\n}\n\ninterface Palette {\n type: \"list\";\n value: {\n type: \"compound\";\n value: PaletteEntry[]\n }\n}\n\ninterface PaletteEntry {\n Name: {\n type: \"string\";\n value: string;\n }\n Properties: {\n type: \"compound\";\n value: { [property: string]: PalettePropertyValue; };\n }\n}\n\ninterface PalettePropertyValue {\n type: string;\n value: string;\n}\n\ninterface BlockEntry {\n pos: {\n type: \"list\";\n value: {\n type: \"int\";\n value: TripleArray;\n }\n }\n state: {\n type: \"int\";\n value: number;\n }\n nbt: {\n type: \"compound\";\n value: any;\n }\n}\n"],"mappings":";AAGA,SAAS,uBAAuB;AAIzB,IAAM,kBAAN,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,aAAoB,MAAM,MAAW,cAAqD;AACtF,UAAM,MAAM,KAAK;AAEjB,QAAI;AACJ,QAAI,aAAa,KAAK;AAClB,gBAAU,IAAI;AAAA,IAClB,WAAW,cAAc,KAAK;AAC1B,YAAM,WAAW,IAAI,SAAU,MAAM,MAAM,gBAAgB,CAAC;AAC5D,UAAI,CAAC,SAAU,OAAM,IAAI,gBAAgB,qBAAqB,gBAAgB,CAAC,iBAAiB;AAChG,gBAAU,EAAE,MAAM,QAAQ,OAAO,SAAS;AAAA,IAC9C,OAAO;AACH,YAAM,IAAI,gBAAgB,oCAAoC;AAAA,IAClE;AAEA,UAAM,SACF,IAAI,OAAO,MAAM,MAAM,IAAI,WAAS;AAChC,YAAM,QAAQ,QAAQ,MAAM,MAAM,MAAM,MAAM,KAAK;AACnD,UAAI,CAAC,MAAO,OAAM,IAAI,gBAAgB,2BAA2B,MAAM,MAAM,KAAK,iBAAiB;AACnG,UAAI,CAAC,iBAAiB,sBAAsB,oBAAoB,EAAE,SAAS,MAAM,KAAK,KAAK,EAAG,QAAO;AAErG,YAAM,QAA8B,CAAC;AACrC,eAAS,KAAK,MAAM,YAAY,OAAO;AACnC,cAAM,CAAC,IAAI,MAAM,WAAW,MAAM,CAAC,EAAE;AAAA,MACzC;AACA,aAAwB;AAAA,QACpB,MAAM,MAAM,KAAK;AAAA,QACjB,YAAY;AAAA,QACZ,UAAU,MAAM,IAAI,MAAM;AAAA,QAC1B,KAAK,MAAM;AAAA,MACf;AAAA,IACJ,CAAC,EAAE,OAAO,OAAK,OAAO,MAAM,WAAW;AAC3C,WAAO;AAAA,MACH;AAAA,MACA,MAAM,IAAI,KAAK,MAAM;AAAA,MACrB,aAAa,IAAI,aAAa;AAAA,MAC9B,WAAW,IAAI,UAAU,MAAM,SAAS,CAAC,GAAG,IAAI,aAAW;AAAA,QACvD,UAAU,OAAO,IAAI,MAAM;AAAA,QAC3B,eAAe,OAAO,SAAS,MAAM;AAAA,QACrC,KAAK,OAAO;AAAA,MAChB,EAAE;AAAA,IACN;AAAA,EACJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/model/multiblock/StructureParser.ts"],"sourcesContent":["import { MultiBlockBlock, MultiBlockStructure } from \"./MultiBlockStructure\";\nimport { TripleArray } from \"../Model\";\nimport type { NBT } from \"prismarine-nbt\";\nimport { MineRenderError } from \"../../error/MineRenderError\";\nimport { BlockStateProperties } from \"../block/BlockStateProperties\";\n\n/** Converts Java structure NBT into blocks and preserved entity data for world placement. */\nexport class StructureParser {\n\n /**\n * Parses decoded NBT, omitting air blocks.\n * @param _nbt - Structure data decoded by {@link NBTHelper.fromBuffer}.\n * @param paletteIndex - Palette to select when the structure has several. Defaults to 0.\n */\n public static async parse(_nbt: NBT, paletteIndex?: number): Promise<MultiBlockStructure> {\n const nbt = _nbt.value as unknown as StructureNBT;\n\n let palette: Palette;\n if (\"palette\" in nbt) {\n palette = nbt.palette!;\n } else if (\"palettes\" in nbt) {\n const selected = nbt.palettes!.value.value[paletteIndex ?? 0];\n if (!selected) throw new MineRenderError(`Structure palette ${paletteIndex ?? 0} does not exist`);\n palette = { type: \"list\", value: selected };\n } else {\n throw new MineRenderError(\"Structure does not have palette(s)\");\n }\n\n const blocks: MultiBlockBlock[] =\n nbt.blocks.value.value.map(block => {\n const state = palette.value.value[block.state.value];\n if (!state) throw new MineRenderError(`Structure palette index ${block.state.value} does not exist`);\n const name = (state.Name ?? state.id)?.value;\n if (!name) throw new MineRenderError(`Structure palette entry ${block.state.value} has no block name`);\n if ([\"minecraft:air\", \"minecraft:cave_air\", \"minecraft:void_air\"].includes(name)) return undefined;\n\n const props: BlockStateProperties = {};\n const properties = (state.Properties ?? state.properties)?.value;\n for (let k in properties) {\n props[k] = properties[k].value;\n }\n return <MultiBlockBlock>{\n type: name,\n properties: props,\n position: block.pos.value.value,\n nbt: block.nbt\n }\n }).filter(m => typeof m !== \"undefined\") as MultiBlockBlock[] ;\n return {\n blocks: blocks,\n size: nbt.size.value.value,\n dataVersion: nbt.DataVersion?.value,\n entities: (nbt.entities?.value.value ?? []).map(entity => ({\n position: entity.pos.value.value,\n blockPosition: entity.blockPos.value.value,\n nbt: entity.nbt\n }))\n }\n }\n\n}\n\n/** Tagged NBT fields used by Java structure files. */\nexport interface StructureNBT {\n DataVersion?: {\n type: \"int\";\n value: number;\n }\n size: {\n type: \"list\";\n value: {\n type: \"int\";\n value: TripleArray;\n }\n }\n palette?: Palette;\n palettes?: {\n type: \"list\";\n value: { type: \"list\"; value: Palette[\"value\"][] };\n };\n blocks: {\n type: \"list\";\n value: {\n type: \"compound\";\n value: BlockEntry[];\n }\n }\n entities?: {\n type: \"list\";\n value: {\n type: \"compound\";\n value: {\n pos: { type: \"list\"; value: { type: \"double\"; value: TripleArray } };\n blockPos: { type: \"list\"; value: { type: \"int\"; value: TripleArray } };\n nbt: { type: \"compound\"; value: any };\n }[];\n };\n };\n}\n\ninterface Palette {\n type: \"list\";\n value: {\n type: \"compound\";\n value: PaletteEntry[]\n }\n}\n\n// Since DataVersion 5006 (26.3 snapshot 7), Minecraft saves these as `id` and `properties`; older versions use `Name` and `Properties`.\ninterface PaletteEntry {\n Name?: {\n type: \"string\";\n value: string;\n }\n id?: {\n type: \"string\";\n value: string;\n }\n Properties?: {\n type: \"compound\";\n value: { [property: string]: PalettePropertyValue; };\n }\n properties?: {\n type: \"compound\";\n value: { [property: string]: PalettePropertyValue; };\n }\n}\n\ninterface PalettePropertyValue {\n type: string;\n value: string;\n}\n\ninterface BlockEntry {\n pos: {\n type: \"list\";\n value: {\n type: \"int\";\n value: TripleArray;\n }\n }\n state: {\n type: \"int\";\n value: number;\n }\n nbt: {\n type: \"compound\";\n value: any;\n }\n}\n"],"mappings":";AAGA,SAAS,uBAAuB;AAIzB,IAAM,kBAAN,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,aAAoB,MAAM,MAAW,cAAqD;AACtF,UAAM,MAAM,KAAK;AAEjB,QAAI;AACJ,QAAI,aAAa,KAAK;AAClB,gBAAU,IAAI;AAAA,IAClB,WAAW,cAAc,KAAK;AAC1B,YAAM,WAAW,IAAI,SAAU,MAAM,MAAM,gBAAgB,CAAC;AAC5D,UAAI,CAAC,SAAU,OAAM,IAAI,gBAAgB,qBAAqB,gBAAgB,CAAC,iBAAiB;AAChG,gBAAU,EAAE,MAAM,QAAQ,OAAO,SAAS;AAAA,IAC9C,OAAO;AACH,YAAM,IAAI,gBAAgB,oCAAoC;AAAA,IAClE;AAEA,UAAM,SACF,IAAI,OAAO,MAAM,MAAM,IAAI,WAAS;AAChC,YAAM,QAAQ,QAAQ,MAAM,MAAM,MAAM,MAAM,KAAK;AACnD,UAAI,CAAC,MAAO,OAAM,IAAI,gBAAgB,2BAA2B,MAAM,MAAM,KAAK,iBAAiB;AACnG,YAAM,QAAQ,MAAM,QAAQ,MAAM,KAAK;AACvC,UAAI,CAAC,KAAM,OAAM,IAAI,gBAAgB,2BAA2B,MAAM,MAAM,KAAK,oBAAoB;AACrG,UAAI,CAAC,iBAAiB,sBAAsB,oBAAoB,EAAE,SAAS,IAAI,EAAG,QAAO;AAEzF,YAAM,QAA8B,CAAC;AACrC,YAAM,cAAc,MAAM,cAAc,MAAM,aAAa;AAC3D,eAAS,KAAK,YAAY;AACtB,cAAM,CAAC,IAAI,WAAW,CAAC,EAAE;AAAA,MAC7B;AACA,aAAwB;AAAA,QACpB,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,UAAU,MAAM,IAAI,MAAM;AAAA,QAC1B,KAAK,MAAM;AAAA,MACf;AAAA,IACJ,CAAC,EAAE,OAAO,OAAK,OAAO,MAAM,WAAW;AAC3C,WAAO;AAAA,MACH;AAAA,MACA,MAAM,IAAI,KAAK,MAAM;AAAA,MACrB,aAAa,IAAI,aAAa;AAAA,MAC9B,WAAW,IAAI,UAAU,MAAM,SAAS,CAAC,GAAG,IAAI,aAAW;AAAA,QACvD,UAAU,OAAO,IAAI,MAAM;AAAA,QAC3B,eAAe,OAAO,SAAS,MAAM;AAAA,QACrC,KAAK,OAAO;AAAA,MAChB,EAAE;AAAA,IACN;AAAA,EACJ;AAEJ;","names":[]}
@@ -2491,11 +2491,21 @@ interface Palette {
2491
2491
  };
2492
2492
  }
2493
2493
  interface PaletteEntry {
2494
- Name: {
2494
+ Name?: {
2495
2495
  type: "string";
2496
2496
  value: string;
2497
2497
  };
2498
- Properties: {
2498
+ id?: {
2499
+ type: "string";
2500
+ value: string;
2501
+ };
2502
+ Properties?: {
2503
+ type: "compound";
2504
+ value: {
2505
+ [property: string]: PalettePropertyValue;
2506
+ };
2507
+ };
2508
+ properties?: {
2499
2509
  type: "compound";
2500
2510
  value: {
2501
2511
  [property: string]: PalettePropertyValue;
@@ -13951,13 +13951,16 @@ var StructureParser = class {
13951
13951
  const blocks = nbt.blocks.value.value.map((block) => {
13952
13952
  const state = palette.value.value[block.state.value];
13953
13953
  if (!state) throw new MineRenderError(`Structure palette index ${block.state.value} does not exist`);
13954
- if (["minecraft:air", "minecraft:cave_air", "minecraft:void_air"].includes(state.Name.value)) return void 0;
13954
+ const name = (state.Name ?? state.id)?.value;
13955
+ if (!name) throw new MineRenderError(`Structure palette entry ${block.state.value} has no block name`);
13956
+ if (["minecraft:air", "minecraft:cave_air", "minecraft:void_air"].includes(name)) return void 0;
13955
13957
  const props = {};
13956
- for (let k in state.Properties?.value) {
13957
- props[k] = state.Properties.value[k].value;
13958
+ const properties = (state.Properties ?? state.properties)?.value;
13959
+ for (let k in properties) {
13960
+ props[k] = properties[k].value;
13958
13961
  }
13959
13962
  return {
13960
- type: state.Name.value,
13963
+ type: name,
13961
13964
  properties: props,
13962
13965
  position: block.pos.value.value,
13963
13966
  nbt: block.nbt