Search in sources :

Example 16 with BlockStorage

use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage in project DirtMultiversion by DirtPowered.

the class RotationUtil method fixBlockRotation.

public static byte fixBlockRotation(ServerSession session, int startX, int startY, int startZ) {
    BlockStorage blockStorage = session.getUserData().getProtocolStorage().get(BlockStorage.class);
    byte blockData = 3;
    if (blockStorage == null) {
        return blockData;
    }
    int rot1 = blockStorage.getBlockAt(startX, startY, startZ - 1);
    int rot2 = blockStorage.getBlockAt(startX, startY, startZ + 1);
    int rot3 = blockStorage.getBlockAt(startX - 1, startY, startZ);
    int rot4 = blockStorage.getBlockAt(startX + 1, startY, startZ);
    int rot5;
    if (rot3 == CHEST_BLOCK) {
        rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
    } else {
        rot5 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
    }
    int rot6;
    if (rot3 == CHEST_BLOCK) {
        rot6 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
    } else {
        rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
    }
    if (rot1 != CHEST_BLOCK && rot2 != CHEST_BLOCK) {
        if (rot3 != CHEST_BLOCK && rot4 != CHEST_BLOCK) {
            if (SolidBlockList.isSolid(rot2) && !SolidBlockList.isSolid(rot1)) {
                blockData = 2;
            }
            if (SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot4)) {
                blockData = 5;
            }
            if (SolidBlockList.isSolid(rot4) && !SolidBlockList.isSolid(rot3)) {
                blockData = 4;
            }
        } else {
            if (SolidBlockList.isSolid(rot2) || SolidBlockList.isSolid(rot6)) {
                if (!SolidBlockList.isSolid(rot1) && !SolidBlockList.isSolid(rot5)) {
                    blockData = 2;
                }
            }
        }
    } else {
        blockData = 5;
        if (rot1 == CHEST_BLOCK) {
            rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
        } else {
            rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
        }
        if (rot1 == CHEST_BLOCK) {
            rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
        } else {
            rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
        }
        if (SolidBlockList.isSolid(rot4) || SolidBlockList.isSolid(rot6)) {
            if (!SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot5)) {
                blockData = 4;
            }
        }
    }
    return blockData;
}
Also used : BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)

Example 17 with BlockStorage

use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage in project DirtMultiversion by DirtPowered.

the class WorldPackets method registerTranslators.

@Override
public void registerTranslators() {
    // block change
    addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage.getVersion() == getTo()) {
                int x = data.read(Type.INT, 0);
                byte y = data.read(Type.BYTE, 1);
                int z = data.read(Type.INT, 2);
                int chunkX = x >> 4;
                int chunkZ = z >> 4;
                short blockId = data.read(Type.SHORT, 3);
                if (shouldCache(blockId)) {
                    blockStorage.setBlockAt(chunkX, chunkZ, x, y, z, blockId);
                }
            }
            return data;
        }
    });
    addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage.getVersion() == getTo()) {
                int chunkX = data.read(Type.INT, 0);
                int chunkZ = data.read(Type.INT, 1);
                V1_2MultiBlockArray blocks = data.read(Type.V1_2MULTIBLOCK_ARRAY, 2);
                DataInput dis = new DataInputStream(new ByteArrayInputStream(blocks.getData()));
                for (int i = 0; i < blocks.getRecordCount(); i++) {
                    try {
                        short pos = dis.readShort();
                        int x = pos >> 12 & 15;
                        int y = pos & 255;
                        int z = pos >> 8 & 15;
                        int xPos = x + (chunkX << 4);
                        int zPos = z + (chunkZ << 4);
                        int blockId = dis.readShort() >> 4 & 4095;
                        if (shouldCache(blockId)) {
                            blockStorage.setBlockAt(chunkX, chunkZ, xPos, y, zPos, blockId);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return data;
        }
    });
    // chunk data
    addTranslator(0x33, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            V1_2Chunk chunk = data.read(Type.V1_2_CHUNK, 0);
            if (blockStorage.getVersion() == getTo()) {
                List<ExtendedBlockStorage> parts = new ArrayList<>();
                boolean skyLight = true;
                if (session.getStorage().hasObject(DimensionTracker.class)) {
                    DimensionTracker tracker = session.getStorage().get(DimensionTracker.class);
                    skyLight = tracker.getDimension() == 0;
                }
                // create chunk storage
                V1_2RChunkStorage storage = new V1_2RChunkStorage(skyLight, true, chunk.getChunkX(), chunk.getChunkZ());
                storage.readChunk(chunk.isGroundUp(), chunk.getPrimaryBitmap(), chunk.getUncompressedData());
                // cache for later use (r1.8 -> r1.7)
                chunk.setStorage(storage);
                ExtendedBlockStorage[] columns = storage.getColumnStorage();
                for (int i = 0; i < columns.length; ++i) {
                    ExtendedBlockStorage e = columns[i];
                    boolean f = e != null && !columns[i].isEmpty();
                    if (e != null && (chunk.getPrimaryBitmap() & 1 << i) != 0 && (!chunk.isGroundUp() || f)) {
                        parts.add(e);
                    }
                }
                for (int i = 0; i < parts.size(); ++i) {
                    byte[] blockArray = parts.get(i).getBlockLSBArray();
                    for (int j = 0; j < blockArray.length; ++j) {
                        int x = j & 15;
                        int y = (j >> 8) + i * 16 & 127;
                        int z = j >> 4 & 15;
                        int blockId = blockArray[j] & 255;
                        if (shouldCache(blockId)) {
                            blockStorage.setBlockAt(chunk.getChunkX(), chunk.getChunkZ(), x, y, z, blockId);
                        }
                    }
                }
            }
            return data;
        }
    });
}
Also used : ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) V1_2Chunk(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk) V1_2RChunkStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.V1_2RChunkStorage) DimensionTracker(com.github.dirtpowered.dirtmv.network.versions.Release28To23.chunk.DimensionTracker) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExtendedBlockStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.ExtendedBlockStorage) V1_2MultiBlockArray(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray) DataInput(java.io.DataInput) ExtendedBlockStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.ExtendedBlockStorage) BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) List(java.util.List) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Aggregations

BlockStorage (com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)9 BlockStorage (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage)7 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)6 Position (com.viaversion.viaversion.api.minecraft.Position)5 ArrayList (java.util.ArrayList)5 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)4 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)4 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)4 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)4 NumberTag (com.github.steveice10.opennbt.tag.builtin.NumberTag)4 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)4 List (java.util.List)4 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)3 V1_2Chunk (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk)3 V1_2MultiBlockArray (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray)3 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInput (java.io.DataInput)3 DataInputStream (java.io.DataInputStream)3