Search in sources :

Example 11 with StatisticsRewriter

use of com.viaversion.viaversion.rewriter.StatisticsRewriter in project ViaVersion by ViaVersion.

the class Protocol1_14To1_13_2 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    WorldPackets.register(this);
    PlayerPackets.register(this);
    new SoundRewriter(this).registerSound(ClientboundPackets1_13.SOUND);
    new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
    ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
    componentRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE);
    CommandRewriter1_14 commandRewriter = new CommandRewriter1_14(this);
    commandRewriter.registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS);
    registerClientbound(ClientboundPackets1_13.TAGS, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int blockTagsSize = wrapper.read(Type.VAR_INT);
                    // block tags
                    wrapper.write(Type.VAR_INT, blockTagsSize + 6);
                    for (int i = 0; i < blockTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                        for (int j = 0; j < blockIds.length; j++) {
                            blockIds[j] = getMappingData().getNewBlockId(blockIds[j]);
                        }
                    }
                    // Minecraft crashes if we not send signs tags
                    wrapper.write(Type.STRING, "minecraft:signs");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(150), getMappingData().getNewBlockId(155) });
                    wrapper.write(Type.STRING, "minecraft:wall_signs");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(155) });
                    wrapper.write(Type.STRING, "minecraft:standing_signs");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(150) });
                    // Fences and walls tags - used for block connections
                    wrapper.write(Type.STRING, "minecraft:fences");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 189, 248, 472, 473, 474, 475 });
                    wrapper.write(Type.STRING, "minecraft:walls");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 271, 272 });
                    wrapper.write(Type.STRING, "minecraft:wooden_fences");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 189, 472, 473, 474, 475 });
                    int itemTagsSize = wrapper.read(Type.VAR_INT);
                    // item tags
                    wrapper.write(Type.VAR_INT, itemTagsSize + 2);
                    for (int i = 0; i < itemTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                        for (int j = 0; j < itemIds.length; j++) {
                            itemIds[j] = getMappingData().getNewItemId(itemIds[j]);
                        }
                    }
                    // Should fix fuel shift clicking
                    wrapper.write(Type.STRING, "minecraft:signs");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewItemId(541) });
                    // Arrows tag (used by bow)
                    wrapper.write(Type.STRING, "minecraft:arrows");
                    wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 526, 825, 826 });
                    // fluid tags
                    int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
                    for (int i = 0; i < fluidTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                    }
                    // new entity tags - do we need to send this?
                    wrapper.write(Type.VAR_INT, 0);
                }
            });
        }
    });
    // Set Difficulty packet added in 19w11a
    cancelServerbound(ServerboundPackets1_14.SET_DIFFICULTY);
    // Lock Difficulty packet added in 19w11a
    cancelServerbound(ServerboundPackets1_14.LOCK_DIFFICULTY);
    // Unknown packet added in 19w13a
    cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
Also used : StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ComponentRewriter(com.viaversion.viaversion.rewriter.ComponentRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) CommandRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.CommandRewriter1_14) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) ComponentRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.ComponentRewriter1_14)

Example 12 with StatisticsRewriter

use of com.viaversion.viaversion.rewriter.StatisticsRewriter in project ViaVersion by ViaVersion.

the class Protocol1_18To1_17_1 method registerPackets.

@Override
protected void registerPackets() {
    entityRewriter.register();
    itemRewriter.register();
    WorldPackets.register(this);
    final SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_17_1.ENTITY_SOUND);
    final TagRewriter tagRewriter = new TagRewriter(this);
    tagRewriter.registerGeneric(ClientboundPackets1_17_1.TAGS);
    tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:lava_pool_stone_cannot_replace", "minecraft:big_dripleaf_placeable", "minecraft:wolves_spawnable_on", "minecraft:rabbits_spawnable_on", "minecraft:polar_bears_spawnable_on_in_frozen_ocean", "minecraft:parrots_spawnable_on", "minecraft:mooshrooms_spawnable_on", "minecraft:goats_spawnable_on", "minecraft:foxes_spawnable_on", "minecraft:axolotls_spawnable_on", "minecraft:animals_spawnable_on", "minecraft:azalea_grows_on", "minecraft:azalea_root_replaceable", "minecraft:replaceable_plants", "minecraft:terracotta");
    tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:dirt", "minecraft:terracotta");
    new StatisticsRewriter(this).register(ClientboundPackets1_17_1.STATISTICS);
    registerServerbound(ServerboundPackets1_17.CLIENT_SETTINGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Language
            map(Type.STRING);
            // View distance
            map(Type.BYTE);
            // Chat visibility
            map(Type.VAR_INT);
            // Chat colors
            map(Type.BOOLEAN);
            // Model customization
            map(Type.UNSIGNED_BYTE);
            // Main hand
            map(Type.VAR_INT);
            // Text filtering enabled
            map(Type.BOOLEAN);
            // Allow listing in server list preview
            read(Type.BOOLEAN);
        }
    });
}
Also used : 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 13 with StatisticsRewriter

use of com.viaversion.viaversion.rewriter.StatisticsRewriter in project ViaVersion by ViaVersion.

the class Protocol1_13_1To1_13 method registerPackets.

@Override
protected void registerPackets() {
    entityRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    WorldPackets.register(this);
    registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {

                @Override
                public String transform(PacketWrapper wrapper, String inputValue) {
                    // 1.13 starts sending slash at start, so we remove it for compatibility
                    return inputValue.startsWith("/") ? inputValue.substring(1) : inputValue;
                }
            });
        }
    });
    registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.FLAT_ITEM);
            map(Type.BOOLEAN);
            handler(wrapper -> {
                Item item = wrapper.get(Type.FLAT_ITEM, 0);
                itemRewriter.handleItemToServer(item);
            });
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int hand = wrapper.read(Type.VAR_INT);
                    if (hand == 1) {
                        wrapper.cancel();
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Transaction id
            map(Type.VAR_INT);
            // Start
            map(Type.VAR_INT);
            // Length
            map(Type.VAR_INT);
            // Count
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int start = wrapper.get(Type.VAR_INT, 1);
                    // Offset by +1 to take into account / at beginning
                    wrapper.set(Type.VAR_INT, 1, start + 1);
                    // Passthrough suggestions
                    int count = wrapper.get(Type.VAR_INT, 3);
                    for (int i = 0; i < count; i++) {
                        wrapper.passthrough(Type.STRING);
                        boolean hasTooltip = wrapper.passthrough(Type.BOOLEAN);
                        if (hasTooltip) {
                            // JSON Tooltip
                            wrapper.passthrough(Type.STRING);
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int action = wrapper.get(Type.VAR_INT, 0);
                    if (action == 0) {
                        wrapper.passthrough(Type.COMPONENT);
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.passthrough(Type.VAR_INT);
                        wrapper.passthrough(Type.VAR_INT);
                        short flags = wrapper.read(Type.BYTE);
                        if ((flags & 0x02) != 0)
                            flags |= 0x04;
                        wrapper.write(Type.UNSIGNED_BYTE, flags);
                    }
                }
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
    new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
}
Also used : ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.InventoryPackets) MappingData(com.viaversion.viaversion.api.data.MappingData) EntityPackets(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.EntityPackets) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Entity1_13Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types) Item(com.viaversion.viaversion.api.minecraft.item.Item) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) MappingDataBase(com.viaversion.viaversion.api.data.MappingDataBase) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) 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) MetadataRewriter1_13_1To1_13(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13) ServerboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13) 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) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) WorldPackets(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.WorldPackets) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Item(com.viaversion.viaversion.api.minecraft.item.Item) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)13 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)13 TagRewriter (com.viaversion.viaversion.rewriter.TagRewriter)11 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)10 RegistryType (com.viaversion.viaversion.api.minecraft.RegistryType)10 EntityRewriter (com.viaversion.viaversion.api.rewriter.EntityRewriter)10 Type (com.viaversion.viaversion.api.type.Type)10 EntityTrackerBase (com.viaversion.viaversion.data.entity.EntityTrackerBase)10 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)7 ItemRewriter (com.viaversion.viaversion.api.rewriter.ItemRewriter)7 SoundRewriter (com.viaversion.viaversion.rewriter.SoundRewriter)6 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)5 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)5 BackwardsMappings (com.viaversion.viabackwards.api.data.BackwardsMappings)4 SoundRewriter (com.viaversion.viabackwards.api.rewriters.SoundRewriter)4 AbstractProtocol (com.viaversion.viaversion.api.protocol.AbstractProtocol)4 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)4 ServerboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14)4 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)3 ServerboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2)3