Search in sources :

Example 31 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
    registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_13.OPEN_WINDOW, null, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Short windowId = wrapper.read(Type.UNSIGNED_BYTE);
                    String type = wrapper.read(Type.STRING);
                    JsonElement title = wrapper.read(Type.COMPONENT);
                    COMPONENT_REWRITER.processText(title);
                    Short slots = wrapper.read(Type.UNSIGNED_BYTE);
                    if (type.equals("EntityHorse")) {
                        wrapper.setId(0x1F);
                        int entityId = wrapper.read(Type.INT);
                        wrapper.write(Type.UNSIGNED_BYTE, windowId);
                        wrapper.write(Type.VAR_INT, slots.intValue());
                        wrapper.write(Type.INT, entityId);
                    } else {
                        wrapper.setId(0x2E);
                        wrapper.write(Type.VAR_INT, windowId.intValue());
                        int typeId = -1;
                        switch(type) {
                            case "minecraft:crafting_table":
                                typeId = 11;
                                break;
                            case "minecraft:furnace":
                                typeId = 13;
                                break;
                            case "minecraft:dropper":
                            case "minecraft:dispenser":
                                typeId = 6;
                                break;
                            case "minecraft:enchanting_table":
                                typeId = 12;
                                break;
                            case "minecraft:brewing_stand":
                                typeId = 10;
                                break;
                            case "minecraft:villager":
                                typeId = 18;
                                break;
                            case "minecraft:beacon":
                                typeId = 8;
                                break;
                            case "minecraft:anvil":
                                typeId = 7;
                                break;
                            case "minecraft:hopper":
                                typeId = 15;
                                break;
                            case "minecraft:shulker_box":
                                typeId = 19;
                                break;
                            case "minecraft:container":
                            case "minecraft:chest":
                            default:
                                if (slots > 0 && slots <= 54) {
                                    typeId = slots / 9 - 1;
                                }
                                break;
                        }
                        if (typeId == -1) {
                            Via.getPlatform().getLogger().warning("Can't open inventory for 1.14 player! Type: " + type + " Size: " + slots);
                        }
                        wrapper.write(Type.VAR_INT, typeId);
                        wrapper.write(Type.COMPONENT, title);
                    }
                }
            });
        }
    });
    registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Channel
            map(Type.STRING);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    String channel = wrapper.get(Type.STRING, 0);
                    if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
                        wrapper.setId(0x27);
                        wrapper.resetReader();
                        // Remove channel
                        wrapper.read(Type.STRING);
                        int windowId = wrapper.read(Type.INT);
                        EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
                        tracker.setLatestTradeWindowId(windowId);
                        wrapper.write(Type.VAR_INT, windowId);
                        int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                        for (int i = 0; i < size; i++) {
                            // Input Item
                            handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
                            // Output Item
                            handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
                            // Has second item
                            boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
                            if (secondItem) {
                                // Second Item
                                handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
                            }
                            // Trade disabled
                            wrapper.passthrough(Type.BOOLEAN);
                            // Number of tools uses
                            wrapper.passthrough(Type.INT);
                            // Maximum number of trade uses
                            wrapper.passthrough(Type.INT);
                            wrapper.write(Type.INT, 0);
                            wrapper.write(Type.INT, 0);
                            wrapper.write(Type.FLOAT, 0f);
                        }
                        wrapper.write(Type.VAR_INT, 0);
                        wrapper.write(Type.VAR_INT, 0);
                        wrapper.write(Type.BOOLEAN, false);
                    } else if (channel.equals("minecraft:book_open") || channel.equals("book_open")) {
                        int hand = wrapper.read(Type.VAR_INT);
                        wrapper.clearPacket();
                        wrapper.setId(0x2D);
                        wrapper.write(Type.VAR_INT, hand);
                    }
                }
            });
        }
    });
    registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    RecipeRewriter recipeRewriter = new RecipeRewriter1_13_2(protocol);
    protocol.registerClientbound(ClientboundPackets1_13.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++) {
                    // Recipe Identifier
                    String id = wrapper.read(Type.STRING);
                    String type = wrapper.read(Type.STRING);
                    if (REMOVED_RECIPE_TYPES.contains(type)) {
                        deleted++;
                        continue;
                    }
                    wrapper.write(Type.STRING, type);
                    wrapper.write(Type.STRING, id);
                    recipeRewriter.handle(wrapper, type);
                }
                wrapper.set(Type.VAR_INT, 0, size - deleted);
            });
        }
    });
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_14.SELECT_TRADE, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // Selecting trade now moves the items, we need to resync the inventory
                    PacketWrapper resyncPacket = wrapper.create(0x08);
                    EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
                    // 0 - Window ID
                    resyncPacket.write(Type.UNSIGNED_BYTE, ((short) tracker.getLatestTradeWindowId()));
                    // 1 - Slot
                    resyncPacket.write(Type.SHORT, ((short) -999));
                    // 2 - Button - End left click
                    resyncPacket.write(Type.BYTE, (byte) 2);
                    // 3 - Action number
                    resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt()));
                    // 4 - Mode - Drag
                    resyncPacket.write(Type.VAR_INT, 5);
                    CompoundTag tag = new CompoundTag();
                    // Tags with NaN are not equal
                    tag.put("force_resync", new DoubleTag(Double.NaN));
                    // 5 - Clicked Item
                    resyncPacket.write(Type.FLAT_VAR_INT_ITEM, new DataItem(1, (byte) 1, (short) 0, tag));
                    resyncPacket.scheduleSendToServer(Protocol1_14To1_13_2.class);
                }
            });
        }
    });
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.FLOAT);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ComponentRewriter(com.viaversion.viaversion.rewriter.ComponentRewriter) JsonObject(com.google.gson.JsonObject) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Item(com.viaversion.viaversion.api.minecraft.item.Item) JsonElement(com.google.gson.JsonElement) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Protocol1_14To1_13_2(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) EntityTracker1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) Set(java.util.Set) RecipeRewriter1_13_2(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2) Via(com.viaversion.viaversion.api.Via) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) Sets(com.google.common.collect.Sets) RecipeRewriter(com.viaversion.viaversion.rewriter.RecipeRewriter) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) ClientboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) ChatRewriter(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter) DoubleTag(com.github.steveice10.opennbt.tag.builtin.DoubleTag) EntityTracker1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) RecipeRewriter(com.viaversion.viaversion.rewriter.RecipeRewriter) RecipeRewriter1_13_2(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2) DoubleTag(com.github.steveice10.opennbt.tag.builtin.DoubleTag) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.google.gson.JsonElement) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 32 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaVersion by ViaVersion.

the class EntityPackets method register.

public static void register(Protocol1_15To1_14_4 protocol) {
    MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
    metadataRewriter.registerTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Entity UUID
            map(Type.UUID);
            // 2 - Entity Type
            map(Type.VAR_INT);
            // 3 - X
            map(Type.DOUBLE);
            // 4 - Y
            map(Type.DOUBLE);
            // 5 - Z
            map(Type.DOUBLE);
            // 6 - Yaw
            map(Type.BYTE);
            // 7 - Pitch
            map(Type.BYTE);
            // 8 - Head Pitch
            map(Type.BYTE);
            // 9 - Velocity X
            map(Type.SHORT);
            // 10 - Velocity Y
            map(Type.SHORT);
            // 11 - Velocity Z
            map(Type.SHORT);
            handler(metadataRewriter.trackerHandler());
            handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Type.VAR_INT, 0), metadataRewriter));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Player UUID
            map(Type.UUID);
            // 2 - X
            map(Type.DOUBLE);
            // 3 - Y
            map(Type.DOUBLE);
            // 4 - Z
            map(Type.DOUBLE);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - Pitch
            map(Type.BYTE);
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class).addEntity(entityId, Entity1_15Types.PLAYER);
                sendMetadataPacket(wrapper, entityId, metadataRewriter);
            });
        }
    });
    metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
    metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) Type(com.viaversion.viaversion.api.type.Type) List(java.util.List) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4) Protocol1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4)

Example 33 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaVersion by ViaVersion.

the class Protocol1_16_2To1_16_1 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    WorldPackets.register(this);
    tagRewriter = new TagRewriter(this);
    tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
    // Recipe book data has been split into 2 separate packets
    registerServerbound(ServerboundPackets1_16_2.RECIPE_BOOK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int recipeType = wrapper.read(Type.VAR_INT);
                boolean open = wrapper.read(Type.BOOLEAN);
                boolean filter = wrapper.read(Type.BOOLEAN);
                // Settings
                wrapper.write(Type.VAR_INT, 1);
                // Crafting
                wrapper.write(Type.BOOLEAN, recipeType == 0 && open);
                wrapper.write(Type.BOOLEAN, filter);
                // Furnace
                wrapper.write(Type.BOOLEAN, recipeType == 1 && open);
                wrapper.write(Type.BOOLEAN, filter);
                // Blast Furnace
                wrapper.write(Type.BOOLEAN, recipeType == 2 && open);
                wrapper.write(Type.BOOLEAN, filter);
                // Smoker
                wrapper.write(Type.BOOLEAN, recipeType == 3 && open);
                wrapper.write(Type.BOOLEAN, filter);
            });
        }
    });
    registerServerbound(ServerboundPackets1_16_2.SEEN_RECIPE, ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                String recipe = wrapper.read(Type.STRING);
                // Shown
                wrapper.write(Type.VAR_INT, 0);
                wrapper.write(Type.STRING, recipe);
            });
        }
    });
}
Also used : EntityPackets(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.EntityPackets) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) MetadataRewriter1_16_2To1_16_1(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1) Entity1_16_2Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types) WorldPackets(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.WorldPackets) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) MappingData(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data.MappingData) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter)

Example 34 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaVersion by ViaVersion.

the class PlayerPackets method register.

public static void register(Protocol protocol) {
    protocol.registerClientbound(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION, Type.POSITION1_14);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.QUERY_BLOCK_NBT, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                    protocol.getItemRewriter().handleItemToServer(item);
                    if (item == null)
                        return;
                    CompoundTag tag = item.tag();
                    if (tag == null)
                        return;
                    Tag pages = tag.get("pages");
                    // Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
                    if (pages == null) {
                        tag.put("pages", new ListTag(Collections.singletonList(new StringTag())));
                    }
                    // Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit
                    if (Via.getConfig().isTruncate1_14Books() && pages instanceof ListTag) {
                        ListTag listTag = (ListTag) pages;
                        if (listTag.size() > 50) {
                            listTag.setValue(listTag.getValue().subList(0, 50));
                        }
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.PLAYER_DIGGING, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Action
            map(Type.VAR_INT);
            // Position
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.RECIPE_BOOK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.get(Type.VAR_INT, 0);
                    if (type == 0) {
                        wrapper.passthrough(Type.STRING);
                    } else if (type == 1) {
                        // Crafting Recipe Book Open
                        wrapper.passthrough(Type.BOOLEAN);
                        // Crafting Recipe Filter Active
                        wrapper.passthrough(Type.BOOLEAN);
                        // Smelting Recipe Book Open
                        wrapper.passthrough(Type.BOOLEAN);
                        // Smelting Recipe Filter Active
                        wrapper.passthrough(Type.BOOLEAN);
                        // Unknown new booleans
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_COMMAND_BLOCK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_SIGN, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int hand = wrapper.read(Type.VAR_INT);
                    Position position = wrapper.read(Type.POSITION1_14);
                    int face = wrapper.read(Type.VAR_INT);
                    float x = wrapper.read(Type.FLOAT);
                    float y = wrapper.read(Type.FLOAT);
                    float z = wrapper.read(Type.FLOAT);
                    // new unknown boolean
                    wrapper.read(Type.BOOLEAN);
                    wrapper.write(Type.POSITION, position);
                    wrapper.write(Type.VAR_INT, face);
                    wrapper.write(Type.VAR_INT, hand);
                    wrapper.write(Type.FLOAT, x);
                    wrapper.write(Type.FLOAT, y);
                    wrapper.write(Type.FLOAT, z);
                }
            });
        }
    });
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Position(com.viaversion.viaversion.api.minecraft.Position) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 35 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaVersion by ViaVersion.

the class Protocol1_15To1_14_4 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    PlayerPackets.register(this);
    WorldPackets.register(this);
    SoundRewriter soundRewriter = new SoundRewriter(this);
    // Entity Sound Effect (added somewhere in 1.14)
    soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND);
    soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
    new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
    registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> itemRewriter.handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    tagRewriter = new TagRewriter(this);
    tagRewriter.register(ClientboundPackets1_14.TAGS, RegistryType.ENTITY);
}
Also used : InventoryPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) MappingData(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data.MappingData) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4) EntityPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) Type(com.viaversion.viaversion.api.type.Type) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) PlayerPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets) WorldPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)109 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)78 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)65 Type (com.viaversion.viaversion.api.type.Type)64 Item (com.viaversion.viaversion.api.minecraft.item.Item)31 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)24 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)24 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)21 Via (com.viaversion.viaversion.api.Via)19 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)19 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)17 ArrayList (java.util.ArrayList)17 List (java.util.List)17 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)16 Position (com.viaversion.viaversion.api.minecraft.Position)14 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)14 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)14 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)13 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)13 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)13