title: How to decode Data (ie block state) bytes in Minecraft schematic (nbt) file?
body: <p>I am parsing a <code>schematic file</code> with the <a href="https://minecraft.gamepedia.com/Schematic_file_format" rel="nofollow noreferrer">following structure</a></p>
  <blockquote>
  <p>The <strong>.schematic file format</strong> was created by the community to store sections of a Minecraft world for use with third-party programs. Schematics are in <a href="https://wiki.vg/NBT" rel="nofollow noreferrer">NBT format</a></p>
  <p>The <a href="https://wiki.vg/NBT" rel="nofollow noreferrer">Named Binary Tag (NBT) file format</a> is an extremely simple structured binary format used by the Minecraft game for a variety of things</p>
  </blockquote>
  <p>Block <a href="https://minecraft.gamepedia.com/Data_values" rel="nofollow noreferrer"><code>Data Value</code>s</a> define parts of the terrain in Minecraft.</p>
  <p>I retrieving <a href="https://minecraft.gamepedia.com/Block_states" rel="nofollow noreferrer">the <code>block data</code></a> of every Minecraft Block, and need to figure out how to decode these bytes. This is <a href="https://minecraft.gamepedia.com/Stairs#Block_data" rel="nofollow noreferrer">an example for the <code>Stairs</code> Minecraft Block</a></p>
  <p>For example <a href="https://minecraft.gamepedia.com/Stairs#Block_data" rel="nofollow noreferrer">the stairs block data</a> includes:</p>
  <p><a href="https://i.stack.imgur.com/FfOFK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FfOFK.png" alt="enter image description here" /></a></p>
  <p>I can use <a href="https://github.com/sjmulder/nbt-js" rel="nofollow noreferrer">nbt-js</a> to parse the entire schematic file, which enables me to access the block data like this:</p>
  <pre><code>var b = schem.value.Data.value[index];
  </code></pre>
  <p>I decode the <strong>Stairs Block Data</strong> bits data with the following code</p>
  <pre><code>var facing = b &amp; 0x03;
  var half = (b &gt;&gt; 2) &amp; 0x01;
  var shape = (b &gt;&gt; 3) &amp; 0x03;
  </code></pre>
  <p>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:</p>
  <pre><code>block.rotateX(facing);
  </code></pre>
  <p>However, the bits are interpreted differently for every block type, and this isn't defined anywhere that I can find.</p>