Advertisement
AdslHouba

Schematic ves lua

Apr 12th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1. import java.io.ByteArrayInputStream;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Path;
  7. import java.nio.file.Paths;
  8. import java.util.Map;
  9.  
  10. import org.jnbt.ByteArrayTag;
  11. import org.jnbt.CompoundTag;
  12. import org.jnbt.NBTInputStream;
  13. import org.jnbt.NBTUtils;
  14. import org.jnbt.ShortTag;
  15. import org.jnbt.StringTag;
  16. import org.jnbt.Tag;
  17.  
  18. public class HelloWorld {
  19.     public static void main(String[] args) {
  20.         // Prints "Hello, World" in the terminal window.
  21.         // File f = new File("statu.schematic");
  22.         try {
  23.             System.out.println("statu.schematic");
  24.             Path path = Paths.get("statu.schematic");
  25.             byte[] data = Files.readAllBytes(path);
  26.  
  27.             NBTInputStream nbt = new NBTInputStream(new ByteArrayInputStream(data));
  28.             CompoundTag rootTag = (CompoundTag) nbt.readTag();
  29.             Map<String, Tag> schematic = rootTag.getValue();
  30.  
  31.             short width = NBTUtils.getChildTag(schematic, "Width", ShortTag.class).getValue();
  32.             short length = NBTUtils.getChildTag(schematic, "Length", ShortTag.class).getValue();
  33.             short height = NBTUtils.getChildTag(schematic, "Height", ShortTag.class).getValue();
  34.  
  35.             byte[] blockId = NBTUtils.getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
  36.             data = NBTUtils.getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
  37.             short[] blocks = new short[blockId.length];
  38.             short[] datas = new short[data.length];
  39.  
  40.             byte[] addId = new byte[0];
  41.             addId = NBTUtils.getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
  42.  
  43.             Map<String, Tag> blockIDs = NBTUtils.getChildTag(schematic, "BlockIDs", CompoundTag.class).getValue();
  44.  
  45.             for (int index = 0; index < blockId.length; index++) {
  46.                 if ((index >> 1) >= addId.length) { // No corresponding
  47.                     // AddBlocks index
  48.                     blocks[index] = (short) (blockId[index] & 0xFF);
  49.                 } else {
  50.                     if ((index & 1) == 0) {
  51.                         blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
  52.                     } else {
  53.                         blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
  54.                     }
  55.                 }
  56.             }
  57.             for (int index4 = 0; index4 < data.length; index4++) {
  58.                 if ((index4 >> 1) >= addId.length) { // No corresponding
  59.                     // AddBlocks index
  60.                     datas[index4] = (short) (data[index4] & 0xFF);
  61.                 } else {
  62.                     if ((index4 & 1) == 0) {
  63.                         datas[index4] = (short) (((addId[index4 >> 1] & 0x0F) << 8) + (data[index4] & 0xFF));
  64.                     } else {
  65.                         datas[index4] = (short) (((addId[index4 >> 1] & 0xF0) << 4) + (data[index4] & 0xFF));
  66.                     }
  67.                 }
  68.             }
  69.             File f = new File("json");
  70.             FileWriter fw = new FileWriter(f);
  71.             fw.write("block={");
  72.             fw.write("\r\n");
  73.             String typeBlock = "";
  74.  
  75.             for (int y = 0; y < height; ++y) {
  76.                 for (int x = 0; x < width; ++x) {
  77.                     for (int z = 0; z < length; ++z) {
  78.                         int index1 = y * width * length + z * width + x;
  79.                         if (blocks[index1] != 0 && blocks[index1] != 71) {
  80.                             //System.out.println(blocks[index1]);
  81.                             if (blocks[index1] == 327 || blocks[index1] == 256 || blocks[index1] == 415 || blocks[index1] == 261) {
  82.                                
  83.                                 fw.write("{" + x + "," + y + "," + z + ",\"Mekanism:PlasticBloc\",0},");
  84.                             } else {
  85.                                 typeBlock = (String) blockIDs.get(Short.toString(blocks[index1])).getValue();
  86.                                 fw.write("{" + x + "," + y + "," + z + ",\"" + typeBlock + "\"," + datas[index1] + "},");
  87.                             }
  88.                            
  89.                             fw.write("\r\n");
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.             fw.write("}");
  95.             fw.close();
  96.  
  97.         } catch (IOException e) {
  98.             System.out.println("rater");
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement