Search in sources :

Example 1 with RecipeRewriter1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol);
    // Remove new smithing type, only in this handler
    protocol.registerClientbound(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int size = wrapper.passthrough(Type.VAR_INT);
                int newSize = size;
                for (int i = 0; i < size; i++) {
                    String originalType = wrapper.read(Type.STRING);
                    String type = originalType.replace("minecraft:", "");
                    if (type.equals("smithing")) {
                        newSize--;
                        wrapper.read(Type.STRING);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM);
                        continue;
                    }
                    wrapper.write(Type.STRING, originalType);
                    // Recipe Identifier
                    String id = wrapper.passthrough(Type.STRING);
                    recipeRewriter.handle(wrapper, type);
                }
                wrapper.set(Type.VAR_INT, 0, newSize);
            });
        }
    });
    registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
    registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_16.MULTI_BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_16.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int entityId = wrapper.passthrough(Type.VAR_INT);
                List<EquipmentData> equipmentData = new ArrayList<>();
                byte slot;
                do {
                    slot = wrapper.read(Type.BYTE);
                    Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
                    int rawSlot = slot & 0x7F;
                    equipmentData.add(new EquipmentData(rawSlot, item));
                } while ((slot & 0xFFFFFF80) != 0);
                // Send first data in the current packet
                EquipmentData firstData = equipmentData.get(0);
                wrapper.write(Type.VAR_INT, firstData.slot);
                wrapper.write(Type.FLAT_VAR_INT_ITEM, firstData.item);
                // If there are more items, send new packets for them
                for (int i = 1; i < equipmentData.size(); i++) {
                    PacketWrapper equipmentPacket = wrapper.create(ClientboundPackets1_15.ENTITY_EQUIPMENT);
                    EquipmentData data = equipmentData.get(i);
                    equipmentPacket.write(Type.VAR_INT, entityId);
                    equipmentPacket.write(Type.VAR_INT, data.slot);
                    equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, data.item);
                    equipmentPacket.send(Protocol1_15_2To1_16.class);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.UPDATE_LIGHT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // x
            map(Type.VAR_INT);
            // y
            map(Type.VAR_INT);
            map(Type.BOOLEAN, Type.NOTHING);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Chunk chunk = wrapper.read(new Chunk1_16Type());
                wrapper.write(new Chunk1_15Type(), chunk);
                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));
                    }
                }
                CompoundTag heightMaps = chunk.getHeightMap();
                for (Tag heightMapTag : heightMaps.values()) {
                    LongArrayTag heightMap = (LongArrayTag) heightMapTag;
                    int[] heightMapData = new int[256];
                    CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
                    heightMap.setValue(CompactArrayUtil.createCompactArray(9, heightMapData.length, i -> heightMapData[i]));
                }
                if (chunk.isBiomeData()) {
                    for (int i = 0; i < 1024; i++) {
                        int biome = chunk.getBiomeData()[i];
                        switch(biome) {
                            // new nether biomes
                            case 170:
                            case 171:
                            case 172:
                            case 173:
                                chunk.getBiomeData()[i] = 8;
                                break;
                        }
                    }
                }
                if (chunk.getBlockEntities() == null)
                    return;
                for (CompoundTag blockEntity : chunk.getBlockEntities()) {
                    handleBlockEntity(blockEntity);
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
    registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
    protocol.registerClientbound(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window id
            map(Type.UNSIGNED_BYTE);
            // Property
            map(Type.SHORT);
            // Value
            map(Type.SHORT);
            handler(wrapper -> {
                short property = wrapper.get(Type.SHORT, 0);
                if (property >= 4 && property <= 6) {
                    // Enchantment id
                    short enchantmentId = wrapper.get(Type.SHORT, 1);
                    if (enchantmentId > 11) {
                        // soul_speed
                        wrapper.set(Type.SHORT, 1, --enchantmentId);
                    } else if (enchantmentId == 11) {
                        wrapper.set(Type.SHORT, 1, (short) 9);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.MAP_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Map ID
            map(Type.VAR_INT);
            // Scale
            map(Type.BYTE);
            // Tracking Position
            map(Type.BOOLEAN);
            // Locked
            map(Type.BOOLEAN);
            handler(MapColorRewriter.getRewriteHandler(MapColorRewrites::getMappedColor));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Position position = wrapper.passthrough(Type.POSITION1_14);
                short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
                CompoundTag tag = wrapper.passthrough(Type.NBT);
                handleBlockEntity(tag);
            });
        }
    });
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) ArrayList(java.util.ArrayList) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) Map(java.util.Map) MapColorRewrites(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) MapColorRewriter(com.viaversion.viabackwards.api.rewriters.MapColorRewriter) Position(com.viaversion.viaversion.api.minecraft.Position) EnchantmentRewriter(com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) UUID(java.util.UUID) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) CompactArrayUtil(com.viaversion.viaversion.util.CompactArrayUtil) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) List(java.util.List) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) Position(com.viaversion.viaversion.api.minecraft.Position) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) MapColorRewrites(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) ArrayList(java.util.ArrayList) List(java.util.List) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 2 with RecipeRewriter1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaBackwards by ViaVersion.

the class Protocol1_14_2To1_14_3 method registerPackets.

@Override
protected void registerPackets() {
    registerClientbound(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    wrapper.passthrough(Type.VAR_INT);
                    int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                    for (int i = 0; i < size; i++) {
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        if (wrapper.passthrough(Type.BOOLEAN)) {
                            wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        }
                        wrapper.passthrough(Type.BOOLEAN);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.FLOAT);
                    }
                    wrapper.passthrough(Type.VAR_INT);
                    wrapper.passthrough(Type.VAR_INT);
                    wrapper.passthrough(Type.BOOLEAN);
                    wrapper.read(Type.BOOLEAN);
                }
            });
        }
    });
    RecipeRewriter recipeHandler = new RecipeRewriter1_14(this);
    registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int size = wrapper.passthrough(Type.VAR_INT);
                int deleted = 0;
                for (int i = 0; i < size; i++) {
                    String fullType = wrapper.read(Type.STRING);
                    String type = fullType.replace("minecraft:", "");
                    // id
                    String id = wrapper.read(Type.STRING);
                    if (type.equals("crafting_special_repairitem")) {
                        deleted++;
                        continue;
                    }
                    wrapper.write(Type.STRING, fullType);
                    wrapper.write(Type.STRING, id);
                    recipeHandler.handle(wrapper, type);
                }
                wrapper.set(Type.VAR_INT, 0, size - deleted);
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) RecipeRewriter(com.viaversion.viaversion.rewriter.RecipeRewriter) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) RecipeRewriter(com.viaversion.viaversion.rewriter.RecipeRewriter)

Example 3 with RecipeRewriter1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
    registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_14.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipment(ClientboundPackets1_14.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_14.DECLARE_RECIPES);
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
Also used : RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14)

Example 4 with RecipeRewriter1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_15 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
    registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Chunk chunk = wrapper.read(new Chunk1_15Type());
                    wrapper.write(new Chunk1_14Type(), chunk);
                    if (chunk.isFullChunk()) {
                        int[] biomeData = chunk.getBiomeData();
                        int[] newBiomeData = new int[256];
                        for (int i = 0; i < 4; ++i) {
                            for (int j = 0; j < 4; ++j) {
                                int x = j << 2;
                                int z = i << 2;
                                int newIndex = z << 4 | x;
                                int oldIndex = i << 2 | j;
                                int biome = biomeData[oldIndex];
                                for (int k = 0; k < 4; k++) {
                                    int offX = newIndex + (k << 4);
                                    for (int l = 0; l < 4; l++) {
                                        newBiomeData[offX + l] = biome;
                                    }
                                }
                            }
                        }
                        chunk.setBiomeData(newBiomeData);
                    }
                    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);
                            int newId = protocol.getMappingData().getNewBlockStateId(old);
                            section.setPaletteEntry(j, newId);
                        }
                    }
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
    protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Particle ID
            map(Type.INT);
            // 1 - Long Distance
            map(Type.BOOLEAN);
            // 2 - X
            map(Type.DOUBLE, Type.FLOAT);
            // 3 - Y
            map(Type.DOUBLE, Type.FLOAT);
            // 4 - Z
            map(Type.DOUBLE, Type.FLOAT);
            // 5 - Offset X
            map(Type.FLOAT);
            // 6 - Offset Y
            map(Type.FLOAT);
            // 7 - Offset Z
            map(Type.FLOAT);
            // 8 - Particle Data
            map(Type.FLOAT);
            // 9 - Particle Count
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 3 || id == 23) {
                        int data = wrapper.passthrough(Type.VAR_INT);
                        wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
                    } else if (id == 32) {
                        Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
                        wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
                    }
                    int mappedId = protocol.getMappingData().getNewParticleId(id);
                    if (id != mappedId) {
                        wrapper.set(Type.INT, 0, mappedId);
                    }
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Chunk1_14Type(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type) Item(com.viaversion.viaversion.api.minecraft.item.Item) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Protocol1_14_4To1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) Chunk1_14Type(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 5 with RecipeRewriter1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    // clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing
    PacketHandler cursorRemapper = wrapper -> {
        PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT);
        clearPacket.write(Type.UNSIGNED_BYTE, (short) -1);
        clearPacket.write(Type.SHORT, (short) -1);
        clearPacket.write(Type.FLAT_VAR_INT_ITEM, null);
        clearPacket.send(Protocol1_16To1_15_2.class);
    };
    protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.VAR_INT);
            // Window Type
            map(Type.VAR_INT);
            // Window Title
            map(Type.COMPONENT);
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                int windowId = wrapper.get(Type.VAR_INT, 0);
                int windowType = wrapper.get(Type.VAR_INT, 1);
                if (windowType >= 20) {
                    // smithing added with id 20
                    wrapper.set(Type.VAR_INT, 1, ++windowType);
                }
                inventoryTracker.setInventory((short) windowId);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.WINDOW_PROPERTY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.UNSIGNED_BYTE);
            // Property
            map(Type.SHORT);
            // Value
            map(Type.SHORT);
            handler(wrapper -> {
                short property = wrapper.get(Type.SHORT, 0);
                if (property >= 4 && property <= 6) {
                    // Enchantment id
                    short enchantmentId = wrapper.get(Type.SHORT, 1);
                    if (enchantmentId >= 11) {
                        // soul_speed added with id 11
                        wrapper.set(Type.SHORT, 1, ++enchantmentId);
                    }
                }
            });
        }
    });
    registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
    registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            handler(wrapper -> {
                int slot = wrapper.read(Type.VAR_INT);
                wrapper.write(Type.BYTE, (byte) slot);
                handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
            });
        }
    });
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
    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.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) UUID(java.util.UUID) Item(com.viaversion.viaversion.api.minecraft.item.Item) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16)

Aggregations

RecipeRewriter1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14)5 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)4 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 Type (com.viaversion.viaversion.api.type.Type)4 Item (com.viaversion.viaversion.api.minecraft.item.Item)3 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)3 ServerboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14)3 ClientboundPackets1_15 (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15)3 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)2 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)2 UUIDIntArrayType (com.viaversion.viaversion.api.type.types.UUIDIntArrayType)2 Chunk1_15Type (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type)2 ClientboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16)2 BlockRewriter (com.viaversion.viaversion.rewriter.BlockRewriter)2 UUID (java.util.UUID)2 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)1 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)1 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)1 NumberTag (com.github.steveice10.opennbt.tag.builtin.NumberTag)1