How can i rotate this schematic?

Discussion in 'Bukkit Help' started by darknoneee, Nov 15, 2019.

  1. Offline

    darknoneee

    Hey guys, i'm using this class for load and paste schematics and i really don't know how can i make it rotate to 90 degress and 270 and i really need it.


    Code:
    public class SchematicUtil {
        public String name;
        public short[] blocks;
        public byte[] data;
        public short width;
        public short lenght;
        public short height;
       
        public static SchematicUtil loadSchematic(String name) {
            if (!name.endsWith(".schematic"))
                name = name + ".schematic";
            File file = new File(APlugin.plugin.getDataFolder() + "/schematics/" + name);
            if (!file.exists())
                return null;
            try {
                FileInputStream stream = new FileInputStream(file);
                NBTTagCompound nbtdata = NBTCompressedStreamTools.a(stream);
    
                short width = nbtdata.getShort("Width");
                short height = nbtdata.getShort("Height");
                short length = nbtdata.getShort("Length");
    
                byte[] blocks = nbtdata.getByteArray("Blocks");
                byte[] data = nbtdata.getByteArray("Data");
    
                byte[] addId = new byte[0];
    
                if (nbtdata.hasKey("AddBlocks")) {
                    addId = nbtdata.getByteArray("AddBlocks");
                }
    
                short[] sblocks = new short[blocks.length];
                for (int index = 0; index < blocks.length; index++) {
                    if ((index >> 1) >= addId.length) {
                        sblocks[index] = (short) (blocks[index] & 0xFF);
                    } else {
                        if ((index & 1) == 0) {
                            sblocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blocks[index] & 0xFF));
                        } else {
                            sblocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blocks[index] & 0xFF));
                        }
                    }
                }
    
                stream.close();
                return new SchematicUtil(name, sblocks, data, width, length, height);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
       
        @SuppressWarnings("deprecation")
        public static void pasteSchematic(World world, Location loc, SchematicUtil schematic)
        {
            short[] blocks = schematic.getBlocks();
            byte[] blockData = schematic.getData();
            short length = schematic.getLenght();
            short width = schematic.getWidth();
            short height = schematic.getHeight();
            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(world, x + loc.getX(), y + loc.getY(), z + loc.getZ()).getBlock();
                        block.setTypeIdAndData(blocks[index], blockData[index], true);
                    }
                }
            }
        }
       
        public SchematicUtil(String name, short[] blocks, byte[] data, short width, short lenght, short height) {
            this.name = name;
            this.blocks = blocks;
            this.data = data;
            this.width = width;
            this.lenght = lenght;
            this.height = height;
        }
       
        public short[] getBlocks()
        {
            return blocks;
        }
        /**
        * @return the data
        */
        public byte[] getData()
        {
            return data;
        }
        /**
        * @return the width
        */
        public short getWidth()
        {
            return width;
        }
        /**
        * @return the lenght
        */
        public short getLenght()
        {
            return lenght;
        }
        /**
        * @return the height
        */
        public short getHeight()
        {
            return height;
        }
    
    PLEASE I NEED HELP! SORRY FOR MY BAD ENGLISH
     

Share This Page