Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.Map;
- import org.jnbt.ByteArrayTag;
- import org.jnbt.CompoundTag;
- import org.jnbt.NBTInputStream;
- import org.jnbt.NBTUtils;
- import org.jnbt.ShortTag;
- import org.jnbt.StringTag;
- import org.jnbt.Tag;
- public class HelloWorld {
- public static void main(String[] args) {
- // Prints "Hello, World" in the terminal window.
- // File f = new File("statu.schematic");
- try {
- System.out.println("statu.schematic");
- Path path = Paths.get("statu.schematic");
- byte[] data = Files.readAllBytes(path);
- NBTInputStream nbt = new NBTInputStream(new ByteArrayInputStream(data));
- CompoundTag rootTag = (CompoundTag) nbt.readTag();
- Map<String, Tag> schematic = rootTag.getValue();
- short width = NBTUtils.getChildTag(schematic, "Width", ShortTag.class).getValue();
- short length = NBTUtils.getChildTag(schematic, "Length", ShortTag.class).getValue();
- short height = NBTUtils.getChildTag(schematic, "Height", ShortTag.class).getValue();
- byte[] blockId = NBTUtils.getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
- data = NBTUtils.getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
- short[] blocks = new short[blockId.length];
- short[] datas = new short[data.length];
- byte[] addId = new byte[0];
- addId = NBTUtils.getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
- Map<String, Tag> blockIDs = NBTUtils.getChildTag(schematic, "BlockIDs", CompoundTag.class).getValue();
- for (int index = 0; index < blockId.length; index++) {
- if ((index >> 1) >= addId.length) { // No corresponding
- // AddBlocks index
- blocks[index] = (short) (blockId[index] & 0xFF);
- } else {
- if ((index & 1) == 0) {
- blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
- } else {
- blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
- }
- }
- }
- for (int index4 = 0; index4 < data.length; index4++) {
- if ((index4 >> 1) >= addId.length) { // No corresponding
- // AddBlocks index
- datas[index4] = (short) (data[index4] & 0xFF);
- } else {
- if ((index4 & 1) == 0) {
- datas[index4] = (short) (((addId[index4 >> 1] & 0x0F) << 8) + (data[index4] & 0xFF));
- } else {
- datas[index4] = (short) (((addId[index4 >> 1] & 0xF0) << 4) + (data[index4] & 0xFF));
- }
- }
- }
- File f = new File("json");
- FileWriter fw = new FileWriter(f);
- fw.write("block={");
- fw.write("\r\n");
- String typeBlock = "";
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x) {
- for (int z = 0; z < length; ++z) {
- int index1 = y * width * length + z * width + x;
- if (blocks[index1] != 0 && blocks[index1] != 71) {
- //System.out.println(blocks[index1]);
- if (blocks[index1] == 327 || blocks[index1] == 256 || blocks[index1] == 415 || blocks[index1] == 261) {
- fw.write("{" + x + "," + y + "," + z + ",\"Mekanism:PlasticBloc\",0},");
- } else {
- typeBlock = (String) blockIDs.get(Short.toString(blocks[index1])).getValue();
- fw.write("{" + x + "," + y + "," + z + ",\"" + typeBlock + "\"," + datas[index1] + "},");
- }
- fw.write("\r\n");
- }
- }
- }
- }
- fw.write("}");
- fw.close();
- } catch (IOException e) {
- System.out.println("rater");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement