PrismarineJS / prismarine-schematic

Read and write schematic of any minecraft version, provide them in a convenient and stable API
https://prismarine.js.org/prismarine-schematic/
MIT License
21 stars 8 forks source link

Parsed palette for 1.12 can contain NaN #31

Closed IceTank closed 3 years ago

IceTank commented 3 years ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is.

Your current code

schematic = await Schematic.read(await fs.promises.readFile(pathToSchematic), version) // version is 1.12.2, Schematic is generated in 1.12.2 with Schematic.copy

Outputs:

Schematic {
  version: '1.12.2',
  size: Vec3 { x: 16, y: 1, z: 16 },
  offset: Vec3 { x: 0, y: 0, z: 0 },
  palette: [ NaN ],
  blocks: [
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0,
    ... 156 more items
  ],
  Block: [Function: Block] {
    fromStateId: [Function (anonymous)],
    fromProperties: [Function (anonymous)]
  }
}

Expected behavior

No NaN in output Palette

Additional context

The problem seams to be in this line https://github.com/PrismarineJS/prismarine-schematic/blob/8995a611440e9c06819d829193400ae818a6fee5/lib/states.js#L42

block does not contain .minStateId in 1.12. So Node.js adds undefined + 0 resulting in NaN