Solved [Question] Schematic question

Discussion in 'Spigot Plugin Development' started by rodel77, May 31, 2016.

  1. Hi i want to paste one schematic with my plugin i try to use world edit to copy but some blocks copy incorrecly and coal blocks paste like sugar cane, i am using 1.9.4 and i am loading and pasting with nms NBTTag i try to make the schematic with mcedit and same, then i print the block list in console and some blocks are in negative

    [​IMG]

    Thanks, rodel77
     
    #1 rodel77, May 31, 2016
    Last edited: May 31, 2016
    • Like Like x 1
  2. What code are you using to read and place the schematics? Chances are you are incorrectly parsing it or using the wrong block data.
     
  3. Code (Text):
    package mx.com.rodel.utils;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;

    import org.bukkit.Location;
    import org.bukkit.block.Block;

    import net.minecraft.server.v1_9_R2.NBTCompressedStreamTools;
    import net.minecraft.server.v1_9_R2.NBTTagCompound;

    public class Schematic {
        private byte[] blocks;
        private byte[] data;
        private short width;
        private short length;
        private short height;
     
        public Schematic(InputStream file){
            try {
                NBTTagCompound schematic = new NBTCompressedStreamTools().a(file);
             
                blocks=schematic.getByteArray("Blocks");
                data=schematic.getByteArray("Data");
                width=schematic.getShort("Width");
                length=schematic.getShort("Length");
                height=schematic.getShort("Height");
             
                String test = "";
                for(byte b : blocks){
                     test += b+" ";
                 
                }
                System.out.println(test);
             
             
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
        @SuppressWarnings("deprecation")
        public ArrayList<Block> paste(Location location){
            ArrayList<Block> blocksl = new ArrayList<>();
            for (int x = 0; x < width; ++x) {
                for (int y = 0; y < height; ++y) {
                    for (int z = 0; z < length; ++z) {
                        int index = y * width * length + z * width + x;
                        Block block = new Location(location.getWorld(), x + location.getX(), y + location.getY(), z + location.getZ()).getBlock();
                        block.setTypeIdAndData(blocks[index], data[index], true);
                        blocksl.add(block);
                    }
                }
            }
            return blocksl;
        }
     
        public byte[] getBlocks() {
            return blocks;
        }
     
        public byte[] getData() {
            return data;
        }

        public short getWidth() {
            return width;
        }

        public short getLength() {
            return length;
        }

        public short getHeight() {
            return height;
        }
    }
     
    And here is the console out

    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 -83 -83 -83 -83 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 -83 -83 -83 -83 0 -83 -83 -83 -83 -83 76 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 -83 -83 0 114 0 114 0 -83 -83 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 109 44 44 44 109 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 -83 -83 0 41 0 41 0 -83 -83 0 0 0 0 0 -83 -83 102 102 102 102 102 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 102 102 102 102 102 -83 -83 0 -113 57 -113 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 42 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 102 102 102 102 102 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 102 102 102 102 102 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 76 76 76 76 76 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 76 0 0 0 76 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 76 0 0 0 76 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 76 0 0 0 76 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 -83 -83 -83 -83 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 -83 -83 -83 -83 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
     
  4. Incorrectly*
     
    • Informative Informative x 1
  5. This is binary rollover, you should be familiar with it. Look it up.
     
  6. Now i replace all buged blocks for other and replace it on paste but please if someone find the solution, i go to use it after end this plugin
     
  7. There are no "bugged" blocks, you are just using the numbers wrong..
     
  8. And how i can get good numbers i see the schematic with nbteditor and is the same then is we?

    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 -83 -83 -83
    -83 -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 -83 -83 -83 -83
    -83 0 -83 -83 -83 -83 -83 76 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 0 0 0 0 0 -83 -83 0 114 0 114 0 -83 -83
    0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 109 44 44
    44 109 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0
    -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83
    0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0
    0 -83 -83 0 41 0 41 0 -83 -83 0 0 0 0 0 -83
    -83 102 102 102 102 102 -83 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83
    102 102 102 102 102 -83 -83 0 -113 57 -113 0 -83 -83 0 0
    0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0
    0 -83 -83 0 0 42 0 0 -83 -83 0 0 0 0 0 -83
    -83 0 0 0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 0 0 0 0 0 -83 -83 0 0 0
    0 0 -83 -83 0 0 0 0 0 -83 -83 102 102 102 102 102
    -83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 -83 102 102 102 102 102 -83
    -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0
    0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0
    0 0 -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83 76 76
    76 76 76 -83 -83 -83 -83 -83 -83 -83 -83 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 -83 -83 -83 -83 -83 -83 -83 -83 76 0 0 0 76
    -83 -83 0 0 0 0 0 -83 -83 0 0 0 0 0 -83 -83
    76 0 0 0 76 -83 -83 0 0 0 0 0 -83 -83 0 0
    0 0 0 -83 -83 76 0 0 0 76 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 0 -83
    -83 -83 -83 -83 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 -83 -83
    -83 -83 -83 0 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
    -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83 -83
     
  9. In java all "byte"s are signed. This means that of the 256 numbers 128 are ysed for the positives and another 128 for the negative ones. This means that the -83 is actually a number that was larger than 127 and so it wrapped around into the negative numbers.

    In order to get the unsigned value you have to put it in something bigger like a short and use that value for setting the type.
    Code (Text):
    byte b = original byte from the schematic.
    short unsignedByte = b & 0xFF;
    Now you can use the unsignedByte as the type.
     
    #9 MrBlobman, Jun 1, 2016
    Last edited: Jun 1, 2016
    • Winner Winner x 1
  10. Thanks bro, you save my life haha :)
     
  11. This is part of why java is evil.
    Most other languages have "unsigned" integer types which use the full positive range, which saves a lot of monkeying around when trying to reduce memory.