Search in sources :

Example 1 with BlockChangeRecord1_8

use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaVersion by ViaVersion.

the class ConnectionData method updateChunkSectionNeighbours.

public static void updateChunkSectionNeighbours(UserConnection user, int chunkX, int chunkZ, int chunkSectionY) {
    for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) {
        for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
            if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0)
                continue;
            List<BlockChangeRecord1_8> updates = new ArrayList<>();
            if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) {
                // Corner
                for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
                    int blockPosX = chunkDeltaX == 1 ? 0 : 15;
                    int blockPosZ = chunkDeltaZ == 1 ? 0 : 15;
                    updateBlock(user, new Position(((chunkX + chunkDeltaX) << 4) + blockPosX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockPosZ), updates);
                }
            } else {
                for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
                    int xStart;
                    int xEnd;
                    int zStart;
                    int zEnd;
                    if (chunkDeltaX == 1) {
                        xStart = 0;
                        xEnd = 2;
                        zStart = 0;
                        zEnd = 16;
                    } else if (chunkDeltaX == -1) {
                        xStart = 14;
                        xEnd = 16;
                        zStart = 0;
                        zEnd = 16;
                    } else if (chunkDeltaZ == 1) {
                        xStart = 0;
                        xEnd = 16;
                        zStart = 0;
                        zEnd = 2;
                    } else {
                        xStart = 0;
                        xEnd = 16;
                        zStart = 14;
                        zEnd = 16;
                    }
                    for (int blockX = xStart; blockX < xEnd; blockX++) {
                        for (int blockZ = zStart; blockZ < zEnd; blockZ++) {
                            updateBlock(user, new Position(((chunkX + chunkDeltaX) << 4) + blockX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockZ), updates);
                        }
                    }
                }
            }
            if (!updates.isEmpty()) {
                PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.MULTI_BLOCK_CHANGE, null, user);
                wrapper.write(Type.INT, chunkX + chunkDeltaX);
                wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
                wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
                try {
                    wrapper.send(Protocol1_13To1_12_2.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Position(com.viaversion.viaversion.api.minecraft.Position) ArrayList(java.util.ArrayList)

Example 2 with BlockChangeRecord1_8

use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16_2 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
    registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
    registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.VAR_INT);
                // Open
                wrapper.passthrough(Type.BOOLEAN);
                // Filter
                wrapper.passthrough(Type.BOOLEAN);
                // Furnace Open
                wrapper.passthrough(Type.BOOLEAN);
                // Filter furnace
                wrapper.passthrough(Type.BOOLEAN);
                // Blast furnace / smoker
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
            });
        }
    });
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Chunk chunk = wrapper.read(new Chunk1_16_2Type());
                wrapper.write(new Chunk1_16Type(), chunk);
                chunk.setIgnoreOldLightData(true);
                for (int i = 0; i < chunk.getSections().length; i++) {
                    ChunkSection section = chunk.getSections()[i];
                    if (section == null)
                        continue;
                    for (int j = 0; j < section.getPaletteSize(); j++) {
                        int old = section.getPaletteEntry(j);
                        section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
                    }
                }
                for (CompoundTag blockEntity : chunk.getBlockEntities()) {
                    if (blockEntity != null) {
                        handleBlockEntity(blockEntity);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                handleBlockEntity(wrapper.passthrough(Type.NBT));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                long chunkPosition = wrapper.read(Type.LONG);
                // Ignore old light data
                wrapper.read(Type.BOOLEAN);
                int chunkX = (int) (chunkPosition >> 42);
                int chunkY = (int) (chunkPosition << 44 >> 44);
                int chunkZ = (int) (chunkPosition << 22 >> 42);
                wrapper.write(Type.INT, chunkX);
                wrapper.write(Type.INT, chunkZ);
                BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY);
                wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord);
                for (int i = 0; i < blockChangeRecord.length; i++) {
                    BlockChangeRecord record = blockChangeRecord[i];
                    int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
                    // Relative y -> absolute y
                    blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId);
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
    registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
    registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
}
Also used : BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Chunk1_16_2Type(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) Protocol1_16_1To1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_16_2Type(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 3 with BlockChangeRecord1_8

use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaVersion by ViaVersion.

the class ConnectionData method updateBlock.

public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord1_8> records) {
    int blockState = blockConnectionProvider.getBlockData(user, pos.x(), pos.y(), pos.z());
    ConnectionHandler handler = getConnectionHandler(blockState);
    if (handler == null)
        return;
    int newBlockState = handler.connect(user, pos, blockState);
    records.add(new BlockChangeRecord1_8(pos.x() & 0xF, pos.y(), pos.z() & 0xF, newBlockState));
}
Also used : BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8)

Aggregations

BlockChangeRecord1_8 (com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8)3 Protocol1_16_1To1_16_2 (com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2)1 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)1 Position (com.viaversion.viaversion.api.minecraft.Position)1 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)1 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)1 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 Type (com.viaversion.viaversion.api.type.Type)1 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)1 IntArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag)1 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)1 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)1 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)1 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)1 Chunk1_16_2Type (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type)1 ServerboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16)1 RecipeRewriter1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16)1 Chunk1_16Type (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type)1 BlockRewriter (com.viaversion.viaversion.rewriter.BlockRewriter)1