Search in sources :

Example 1 with ServerboundPackets1_16_2

use of com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2 in project ViaBackwards by ViaVersion.

the class Protocol1_16_4To1_17 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_17To1_16_4.class, MAPPINGS::load);
    translatableRewriter.registerChatMessage(ClientboundPackets1_17.CHAT_MESSAGE);
    translatableRewriter.registerBossBar(ClientboundPackets1_17.BOSSBAR);
    translatableRewriter.registerDisconnect(ClientboundPackets1_17.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_17.TAB_LIST);
    translatableRewriter.registerOpenWindow(ClientboundPackets1_17.OPEN_WINDOW);
    translatableRewriter.registerPing();
    blockItemPackets = new BlockItemPackets1_17(this);
    blockItemPackets.register();
    entityRewriter.register();
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_17.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_17.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_17.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_17.STOP_SOUND);
    TagRewriter tagRewriter = new TagRewriter(this);
    registerClientbound(ClientboundPackets1_17.TAGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Map<String, List<TagData>> tags = new HashMap<>();
                int length = wrapper.read(Type.VAR_INT);
                for (int i = 0; i < length; i++) {
                    String resourceKey = wrapper.read(Type.STRING);
                    if (resourceKey.startsWith("minecraft:")) {
                        resourceKey = resourceKey.substring(10);
                    }
                    List<TagData> tagList = new ArrayList<>();
                    tags.put(resourceKey, tagList);
                    int tagLength = wrapper.read(Type.VAR_INT);
                    for (int j = 0; j < tagLength; j++) {
                        String identifier = wrapper.read(Type.STRING);
                        int[] entries = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
                        tagList.add(new TagData(identifier, entries));
                    }
                }
                // Put them into the hardcoded order of Vanilla tags (and only those), rewrite ids
                for (RegistryType type : RegistryType.getValues()) {
                    List<TagData> tagList = tags.get(type.getResourceLocation());
                    IdRewriteFunction rewriter = tagRewriter.getRewriter(type);
                    wrapper.write(Type.VAR_INT, tagList.size());
                    for (TagData tagData : tagList) {
                        int[] entries = tagData.entries();
                        if (rewriter != null) {
                            // Handle id rewriting now
                            IntList idList = new IntArrayList(entries.length);
                            for (int id : entries) {
                                int mappedId = rewriter.rewrite(id);
                                if (mappedId != -1) {
                                    idList.add(mappedId);
                                }
                            }
                            entries = idList.toArray(EMPTY_ARRAY);
                        }
                        wrapper.write(Type.STRING, tagData.identifier());
                        wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, entries);
                    }
                    // Stop after the entity types
                    if (type == RegistryType.ENTITY) {
                        break;
                    }
                }
            });
        }
    });
    new StatisticsRewriter(this).register(ClientboundPackets1_17.STATISTICS);
    registerClientbound(ClientboundPackets1_17.RESOURCE_PACK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.STRING);
                wrapper.passthrough(Type.STRING);
                // Required
                wrapper.read(Type.BOOLEAN);
                // Prompt message
                wrapper.read(Type.OPTIONAL_COMPONENT);
            });
        }
    });
    registerClientbound(ClientboundPackets1_17.EXPLOSION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // X
            map(Type.FLOAT);
            // Y
            map(Type.FLOAT);
            // Z
            map(Type.FLOAT);
            // Strength
            map(Type.FLOAT);
            handler(wrapper -> {
                // Collection length
                wrapper.write(Type.INT, wrapper.read(Type.VAR_INT));
            });
        }
    });
    registerClientbound(ClientboundPackets1_17.SPAWN_POSITION, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            handler(wrapper -> {
                // Angle (which Mojang just forgot to write to the buffer, lol)
                wrapper.read(Type.FLOAT);
            });
        }
    });
    registerClientbound(ClientboundPackets1_17.PING, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.cancel();
                int id = wrapper.read(Type.INT);
                short shortId = (short) id;
                if (id == shortId && ViaBackwards.getConfig().handlePingsAsInvAcknowledgements()) {
                    wrapper.user().get(PingRequests.class).addId(shortId);
                    // Send inventory acknowledgement to replace ping packet functionality in the unsigned byte range
                    PacketWrapper acknowledgementPacket = wrapper.create(ClientboundPackets1_16_2.WINDOW_CONFIRMATION);
                    // Inventory id
                    acknowledgementPacket.write(Type.UNSIGNED_BYTE, (short) 0);
                    // Confirmation id
                    acknowledgementPacket.write(Type.SHORT, shortId);
                    // Accepted
                    acknowledgementPacket.write(Type.BOOLEAN, false);
                    acknowledgementPacket.send(Protocol1_16_4To1_17.class);
                    return;
                }
                // Plugins expecting a real response will have to handle this accordingly themselves
                PacketWrapper pongPacket = wrapper.create(ServerboundPackets1_17.PONG);
                pongPacket.write(Type.INT, id);
                pongPacket.sendToServer(Protocol1_16_4To1_17.class);
            });
        }
    });
    registerServerbound(ServerboundPackets1_16_2.CLIENT_SETTINGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Locale
            map(Type.STRING);
            // View distance
            map(Type.BYTE);
            // Chat mode
            map(Type.VAR_INT);
            // Chat colors
            map(Type.BOOLEAN);
            // Chat flags
            map(Type.UNSIGNED_BYTE);
            // Main hand
            map(Type.VAR_INT);
            handler(wrapper -> {
                // Text filtering
                wrapper.write(Type.BOOLEAN, false);
            });
        }
    });
    // TODO translatables
    mergePacket(ClientboundPackets1_17.TITLE_TEXT, ClientboundPackets1_16_2.TITLE, 0);
    mergePacket(ClientboundPackets1_17.TITLE_SUBTITLE, ClientboundPackets1_16_2.TITLE, 1);
    mergePacket(ClientboundPackets1_17.ACTIONBAR, ClientboundPackets1_16_2.TITLE, 2);
    mergePacket(ClientboundPackets1_17.TITLE_TIMES, ClientboundPackets1_16_2.TITLE, 3);
    registerClientbound(ClientboundPackets1_17.CLEAR_TITLES, ClientboundPackets1_16_2.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                if (wrapper.read(Type.BOOLEAN)) {
                    // Reset times
                    wrapper.write(Type.VAR_INT, 5);
                } else {
                    // Simple clear
                    wrapper.write(Type.VAR_INT, 4);
                }
            });
        }
    });
    cancelClientbound(ClientboundPackets1_17.ADD_VIBRATION_SIGNAL);
}
Also used : ClientboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) PingRequests(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests) IdRewriteFunction(com.viaversion.viaversion.rewriter.IdRewriteFunction) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) HashMap(java.util.HashMap) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) ArrayList(java.util.ArrayList) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Map(java.util.Map) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) TagData(com.viaversion.viaversion.api.minecraft.TagData) EntityPackets1_17(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) Protocol1_17To1_16_4(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4) BlockItemPackets1_17(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17) List(java.util.List) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) IntArrayList(com.viaversion.viaversion.libs.fastutil.ints.IntArrayList) ServerboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) IntList(com.viaversion.viaversion.libs.fastutil.ints.IntList) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) BlockItemPackets1_17(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) IntList(com.viaversion.viaversion.libs.fastutil.ints.IntList) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) TagData(com.viaversion.viaversion.api.minecraft.TagData) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) ArrayList(java.util.ArrayList) List(java.util.List) IntArrayList(com.viaversion.viaversion.libs.fastutil.ints.IntArrayList) IntList(com.viaversion.viaversion.libs.fastutil.ints.IntList) IdRewriteFunction(com.viaversion.viaversion.rewriter.IdRewriteFunction) IntArrayList(com.viaversion.viaversion.libs.fastutil.ints.IntArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServerboundPackets1_16_2

use of com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2 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 3 with ServerboundPackets1_16_2

use of com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2 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)

Example 4 with ServerboundPackets1_16_2

use of com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2 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 5 with ServerboundPackets1_16_2

use of com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
    registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_16.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
                wrapper.passthrough(Type.BOOLEAN);
                // Filter furnace
                wrapper.passthrough(Type.BOOLEAN);
                // Blast furnace / smoker
                wrapper.write(Type.BOOLEAN, false);
                wrapper.write(Type.BOOLEAN, false);
                wrapper.write(Type.BOOLEAN, false);
                wrapper.write(Type.BOOLEAN, false);
            });
        }
    });
    new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16.DECLARE_RECIPES);
    registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) Type(com.viaversion.viaversion.api.type.Type) Protocol1_16_2To1_16_1(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1) ServerboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)7 Type (com.viaversion.viaversion.api.type.Type)7 ServerboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2)6 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)5 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)4 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)4 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)3 RegistryType (com.viaversion.viaversion.api.minecraft.RegistryType)3 EntityRewriter (com.viaversion.viaversion.api.rewriter.EntityRewriter)3 EntityTrackerBase (com.viaversion.viaversion.data.entity.EntityTrackerBase)3 ClientboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16)3 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)3 TagRewriter (com.viaversion.viaversion.rewriter.TagRewriter)3 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)2 BackwardsMappings (com.viaversion.viabackwards.api.data.BackwardsMappings)2 SoundRewriter (com.viaversion.viabackwards.api.rewriters.SoundRewriter)2 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)2 PingRequests (com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests)2 Entity1_16_2Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types)2 ItemRewriter (com.viaversion.viaversion.api.rewriter.ItemRewriter)2