I am parsing a schematic file
with the following structure
The .schematic file format was created by the munity to store sections of a Minecraft world for use with third-party programs. Schematics are in NBT format
The Named Binary Tag (NBT) file format is an extremely simple structured binary format used by the Minecraft game for a variety of things
Block Data Value
s define parts of the terrain in Minecraft.
I retrieving the block data
of every Minecraft Block, and need to figure out how to decode these bytes. This is an example for the Stairs
Minecraft Block
For example the stairs block data includes:
I can use nbt-js to parse the entire schematic file, which enables me to access the block data like this:
var b = schem.value.Data.value[index];
I decode the Stairs Block Data bits data with the following code
var facing = b & 0x03;
var half = (b >> 2) & 0x01;
var shape = (b >> 3) & 0x03;
These configuration values are essential to determine how the stair block should be rendered. For example, I use the facing value to rotate the block:
block.rotateX(facing);
However, the bits are interpreted differently for every block type, and this isn't defined anywhere that I can find.
I am parsing a schematic file
with the following structure
The .schematic file format was created by the munity to store sections of a Minecraft world for use with third-party programs. Schematics are in NBT format
The Named Binary Tag (NBT) file format is an extremely simple structured binary format used by the Minecraft game for a variety of things
Block Data Value
s define parts of the terrain in Minecraft.
I retrieving the block data
of every Minecraft Block, and need to figure out how to decode these bytes. This is an example for the Stairs
Minecraft Block
For example the stairs block data includes:
I can use nbt-js to parse the entire schematic file, which enables me to access the block data like this:
var b = schem.value.Data.value[index];
I decode the Stairs Block Data bits data with the following code
var facing = b & 0x03;
var half = (b >> 2) & 0x01;
var shape = (b >> 3) & 0x03;
These configuration values are essential to determine how the stair block should be rendered. For example, I use the facing value to rotate the block:
block.rotateX(facing);
However, the bits are interpreted differently for every block type, and this isn't defined anywhere that I can find.
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 23, 2019 at 17:46 lancewlancew 7704 silver badges23 bronze badges 9- 1 can you update your question with a clear reproducible or easy to understand example? – fabOnReact Commented Apr 26, 2019 at 12:35
- Done, see edit2. – lancew Commented Apr 26, 2019 at 12:45
-
1
I refactored your question, but it is still not clear: 1)
schem.value.Data.value[index];
what is the value of theb
variable and what is the value ofschem
etc... maybe you want to create afiddle
and stub the values so that we can quickly recreate your scenario. 2) what is the output offacing = data & 0x03;
and the rest of the code. Try to create some sort of fiddle or explain clearly the code. – fabOnReact Commented Apr 26, 2019 at 13:32 - 2 @lancew Have you already checked out npmjs./package/mc-schematic which builds upon npmjs./package/minecraft-data ? Looks pretty promising to me, – Fitzi Commented Apr 26, 2019 at 14:04
- @FabrizioBertoglio thank you, I can see that its much easier to read now. I edited further to retain the original purpose. – lancew Commented Apr 26, 2019 at 14:28
1 Answer
Reset to default 6 +100There does not exist a mapping that works for all blocks
And you'll just have to deal with it
This is the entire reason why 1.13 and The Flattening is removing metadata entirely resulting in all blockstates encoded as strings when serialized (NBT is a serialized data format and the one used for just about everything before reaching the Anvil format). At runtime these states are parsed and turned into true Object
instances, obviating the need for magic values.
So you won't have to work out that facing = b & 0x03;
you'll instead get {"facing":"east"}
Unfortunately, if you're working below 1.13, you will have to deal with metadata magic values and there is no solution unless you have runtime access to the game and can call getStateFromMeta()
(1.10 through 1.12; unsure where 1.8 and 1.9 sit, as I never modded for those versions).