Search in sources :

Example 11 with PacketRemapper

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

the class PlayerPackets1_14 method registerPackets.

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

        @Override
        public void registerMap() {
            map(Type.UNSIGNED_BYTE);
            // Locked
            map(Type.BOOLEAN, Type.NOTHING);
            handler(wrapper -> {
                byte difficulty = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
                wrapper.user().get(DifficultyStorage.class).setDifficulty(difficulty);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.OPEN_SIGN_EDITOR, new // c
    PacketRemapper() {

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

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

        @Override
        public void registerMap() {
            // Action
            map(Type.VAR_INT);
            // Position
            map(Type.POSITION, Type.POSITION1_14);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_13.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);
                        // Blast furnace/smoker data
                        wrapper.write(Type.BOOLEAN, false);
                        wrapper.write(Type.BOOLEAN, false);
                        wrapper.write(Type.BOOLEAN, false);
                        wrapper.write(Type.BOOLEAN, false);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, new PacketRemapper() {

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

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

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

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Position position = wrapper.read(Type.POSITION);
                    int face = wrapper.read(Type.VAR_INT);
                    int hand = wrapper.read(Type.VAR_INT);
                    float x = wrapper.read(Type.FLOAT);
                    float y = wrapper.read(Type.FLOAT);
                    float z = wrapper.read(Type.FLOAT);
                    wrapper.write(Type.VAR_INT, hand);
                    wrapper.write(Type.POSITION1_14, position);
                    wrapper.write(Type.VAR_INT, face);
                    wrapper.write(Type.FLOAT, x);
                    wrapper.write(Type.FLOAT, y);
                    wrapper.write(Type.FLOAT, z);
                    // Inside block
                    wrapper.write(Type.BOOLEAN, false);
                }
            });
        }
    });
}
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) Position(com.viaversion.viaversion.api.minecraft.Position) ServerboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13) DifficultyStorage(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) RewriterBase(com.viaversion.viaversion.api.rewriter.RewriterBase) 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)

Example 12 with PacketRemapper

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

the class SoundPackets1_14 method registerPackets.

@Override
protected void registerPackets() {
    SoundRewriter soundRewriter = new SoundRewriter(protocol);
    soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_14.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_14.STOP_SOUND);
    // Entity Sound Effect
    protocol.registerClientbound(ClientboundPackets1_14.ENTITY_SOUND, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.cancel();
                int soundId = wrapper.read(Type.VAR_INT);
                int newId = protocol.getMappingData().getSoundMappings().getNewId(soundId);
                if (newId == -1)
                    return;
                int category = wrapper.read(Type.VAR_INT);
                int entityId = wrapper.read(Type.VAR_INT);
                StoredEntityData storedEntity = wrapper.user().getEntityTracker(protocol.getClass()).entityData(entityId);
                EntityPositionStorage1_14 entityStorage;
                if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
                    ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
                    return;
                }
                float volume = wrapper.read(Type.FLOAT);
                float pitch = wrapper.read(Type.FLOAT);
                int x = (int) (entityStorage.getX() * 8D);
                int y = (int) (entityStorage.getY() * 8D);
                int z = (int) (entityStorage.getZ() * 8D);
                PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_13.SOUND);
                soundPacket.write(Type.VAR_INT, newId);
                soundPacket.write(Type.VAR_INT, category);
                soundPacket.write(Type.INT, x);
                soundPacket.write(Type.INT, y);
                soundPacket.write(Type.INT, z);
                soundPacket.write(Type.FLOAT, volume);
                soundPacket.write(Type.FLOAT, pitch);
                soundPacket.send(Protocol1_13_2To1_14.class);
            });
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13) Type(com.viaversion.viaversion.api.type.Type) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14) EntityPositionStorage1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) RewriterBase(com.viaversion.viaversion.api.rewriter.RewriterBase) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) EntityPositionStorage1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14)

Example 13 with PacketRemapper

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

the class Protocol1_17To1_17_1 method registerPackets.

@Override
protected void registerPackets() {
    registerClientbound(ClientboundPackets1_17_1.REMOVE_ENTITIES, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
                wrapper.cancel();
                for (int entityId : entityIds) {
                    // Send individual remove packets
                    PacketWrapper newPacket = wrapper.create(ClientboundPackets1_17.REMOVE_ENTITY);
                    newPacket.write(Type.VAR_INT, entityId);
                    newPacket.send(Protocol1_17To1_17_1.class);
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_17_1.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
                wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
            });
        }
    });
    registerClientbound(ClientboundPackets1_17_1.SET_SLOT, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
                int stateId = wrapper.read(Type.VAR_INT);
                wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
            });
        }
    });
    registerClientbound(ClientboundPackets1_17_1.WINDOW_ITEMS, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
                int stateId = wrapper.read(Type.VAR_INT);
                wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
                // Length is encoded as a var int in 1.17.1
                wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT));
                // Carried item - should work without adding it to the array above
                wrapper.read(Type.FLAT_VAR_INT_ITEM);
            });
        }
    });
    registerServerbound(ServerboundPackets1_17.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
                wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
            });
        }
    });
    registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
                int stateId = wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
                wrapper.write(Type.VAR_INT, stateId == Integer.MAX_VALUE ? 0 : stateId);
            });
        }
    });
    registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
                boolean signing = wrapper.read(Type.BOOLEAN);
                // Slot comes first
                wrapper.passthrough(Type.VAR_INT);
                CompoundTag tag = item.tag();
                ListTag pagesTag;
                StringTag titleTag = null;
                // Sanity checks
                if (tag == null || (pagesTag = tag.get("pages")) == null || (signing && (titleTag = tag.get("title")) == null)) {
                    // Pages length
                    wrapper.write(Type.VAR_INT, 0);
                    // Optional title
                    wrapper.write(Type.BOOLEAN, false);
                    return;
                }
                // Write pages - limit them first
                if (pagesTag.size() > MAX_PAGES) {
                    pagesTag = new ListTag(pagesTag.getValue().subList(0, MAX_PAGES));
                }
                wrapper.write(Type.VAR_INT, pagesTag.size());
                for (Tag pageTag : pagesTag) {
                    String page = ((StringTag) pageTag).getValue();
                    // Limit page length
                    if (page.length() > MAX_PAGE_LENGTH) {
                        page = page.substring(0, MAX_PAGE_LENGTH);
                    }
                    wrapper.write(Type.STRING, page);
                }
                // Write optional title
                wrapper.write(Type.BOOLEAN, signing);
                if (signing) {
                    if (titleTag == null) {
                        titleTag = tag.get("title");
                    }
                    // Limit title length
                    String title = titleTag.getValue();
                    if (title.length() > MAX_TITLE_LENGTH) {
                        title = title.substring(0, MAX_TITLE_LENGTH);
                    }
                    wrapper.write(Type.STRING, title);
                }
            });
        }
    });
}
Also used : ClientboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ClientboundPackets1_17_1(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) InventoryStateIds(com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.storage.InventoryStateIds) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 14 with PacketRemapper

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

the class Protocol1_16_1To1_16_2 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_16_2To1_16_1.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_16_2.BOSSBAR);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_16_2.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_16_2.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_16_2.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_16_2.TITLE);
    translatableRewriter.registerOpenWindow(ClientboundPackets1_16_2.OPEN_WINDOW);
    translatableRewriter.registerPing();
    new CommandRewriter1_16_2(this).registerDeclareCommands(ClientboundPackets1_16_2.DECLARE_COMMANDS);
    (blockItemPackets = new BlockItemPackets1_16_2(this)).register();
    entityRewriter.register();
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_16_2.STOP_SOUND);
    registerClientbound(ClientboundPackets1_16_2.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                JsonElement message = wrapper.passthrough(Type.COMPONENT);
                translatableRewriter.processText(message);
                byte position = wrapper.passthrough(Type.BYTE);
                if (position == 2) {
                    // https://bugs.mojang.com/browse/MC-119145
                    wrapper.clearPacket();
                    wrapper.setId(ClientboundPackets1_16.TITLE.ordinal());
                    wrapper.write(Type.VAR_INT, 2);
                    wrapper.write(Type.COMPONENT, message);
                }
            });
        }
    });
    // Recipe book data has been split into 2 separate packets
    registerServerbound(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.read(Type.VAR_INT);
                    if (type == 0) {
                        // Shown, change to its own packet
                        // Recipe
                        wrapper.passthrough(Type.STRING);
                        wrapper.setId(ServerboundPackets1_16_2.SEEN_RECIPE.ordinal());
                    } else {
                        wrapper.cancel();
                        // Settings
                        for (int i = 0; i < 3; i++) {
                            sendSeenRecipePacket(i, wrapper);
                        }
                    }
                }

                private void sendSeenRecipePacket(int recipeType, PacketWrapper wrapper) throws Exception {
                    boolean open = wrapper.read(Type.BOOLEAN);
                    boolean filter = wrapper.read(Type.BOOLEAN);
                    PacketWrapper newPacket = wrapper.create(ServerboundPackets1_16_2.RECIPE_BOOK_DATA);
                    newPacket.write(Type.VAR_INT, recipeType);
                    newPacket.write(Type.BOOLEAN, open);
                    newPacket.write(Type.BOOLEAN, filter);
                    newPacket.sendToServer(Protocol1_16_1To1_16_2.class);
                }
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_16_2.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_16_2.STATISTICS);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) Protocol1_16_2To1_16_1(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) Entity1_16_2Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) 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) ServerboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) BlockItemPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) CommandRewriter1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandRewriter1_16_2) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) EntityPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2) CommandRewriter1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandRewriter1_16_2) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) BlockItemPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter)

Example 15 with PacketRemapper

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

the class Protocol1_16_3To1_16_4 method registerPackets.

@Override
protected void registerPackets() {
    registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.FLAT_VAR_INT_ITEM);
            map(Type.BOOLEAN);
            handler(wrapper -> {
                int slot = wrapper.read(Type.VAR_INT);
                if (slot == 1) {
                    // offhand
                    wrapper.write(Type.VAR_INT, 40);
                } else {
                    wrapper.write(Type.VAR_INT, wrapper.user().get(PlayerHandStorage.class).getCurrentHand());
                }
            });
        }
    });
    registerServerbound(ServerboundPackets1_16_2.HELD_ITEM_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                short slot = wrapper.passthrough(Type.SHORT);
                wrapper.user().get(PlayerHandStorage.class).setCurrentHand(slot);
            });
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) PlayerHandStorage(com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.storage.PlayerHandStorage) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) PlayerHandStorage(com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.storage.PlayerHandStorage) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

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