title: How to rotate schematic with jnbt in minecraft?
body: <p>How to rotate schematics 90 or 180 degrees?  I create generator and I want to make auto schematic paste.  It's simple for paste schematic with standard rotation, but I need to rotate this 90 or 180 degrees.</p>
  
  <pre><code>public static void SyncPaste(World world, Location loc, File file, boolean air) {
      try {
          FileInputStream stream = new FileInputStream(file);
          NBTInputStream nbtStream = new NBTInputStream(stream);
          CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
          stream.close();
          nbtStream.close();
          if (!schematicTag.getName().equals("Schematic")) {
              throw new Exception("Tag \"Schematic\" does not exist or is not first");
          }
          Map&lt;String, Tag&gt; schematic = schematicTag.getValue();
          if (!schematic.containsKey("Blocks")) {
              throw new Exception("Schematic file is missing a \"Blocks\" tag");
          }
          String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
          if (!materials.equals("Alpha")) {
              throw new Exception("Schematic file is not an Alpha schematic");
          }
          short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
          short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
          short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
  
          int offsetX = getChildTag(schematic, "WEOffsetX", IntTag.class).getValue();
          int offsetY = getChildTag(schematic, "WEOffsetY", IntTag.class).getValue();
          int offsetZ = getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue();
  
          byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
          byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
  
          byte[] rot = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
  
  
          for (int x = 0; x &lt; width; ++x) {
              for (int y = 0; y &lt; height; ++y) {
                  for (int z = 0; z &lt; length; ++z) {
                      int index = y * width * length + z * width + x;
  
                      AffineTransform at = new AffineTransform();
                      at.translate(-(width/2), -(height/2));
  
                      Block block = new Location(world, at.getTranslateX() + offsetX + loc.getX(), at.getTranslateY() + offsetY + loc.getY(), z + offsetZ + loc.getZ()).getBlock();
                      if (air == false &amp;&amp; Material.getMaterial(blockData[index]) != Material.AIR) {
                          if (blocks[index] != 0) {
                              block.setTypeIdAndData(blocks[index], blockData[index], true);
                          } else {
                              throw new Exception("Blocks can't be 0");
                          }
                      } else {
                      }
                  }
              }
          }
      } catch (Exception exc) {
          exc.printStackTrace();
      }
  }
  
  private static &lt;T extends Tag&gt; T getChildTag(Map&lt;String, Tag&gt; items, String key, Class&lt;T&gt; expected)
          throws Exception {
      if (!items.containsKey(key)) {
          throw new Exception("Schematic file is missing a \"" + key + "\" tag");
      }
      Tag tag = items.get(key);
      if (!expected.isInstance(tag)) {
          throw new Exception(key + " tag is not of tag type " + expected.getName());
      }
      return expected.cast(tag);
  }
  
  }
  </code></pre>