Search in sources :

Example 1 with CommandRewriter1_18_2

use of com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2 in project ViaBackwards by ViaVersion.

the class Protocol1_18To1_18_2 method registerPackets.

@Override
protected void registerPackets() {
    new CommandRewriter1_18_2(this).registerDeclareCommands(ClientboundPackets1_18.DECLARE_COMMANDS);
    final PacketHandler entityEffectIdHandler = wrapper -> {
        final int id = wrapper.read(Type.VAR_INT);
        if ((byte) id != id) {
            if (!Via.getConfig().isSuppressConversionWarnings()) {
                ViaBackwards.getPlatform().getLogger().warning("Cannot send entity effect id " + id + " to old client");
            }
            wrapper.cancel();
            return;
        }
        wrapper.write(Type.BYTE, (byte) id);
    };
    registerClientbound(ClientboundPackets1_18.ENTITY_EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(entityEffectIdHandler);
        }
    });
    registerClientbound(ClientboundPackets1_18.REMOVE_ENTITY_EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(entityEffectIdHandler);
        }
    });
    registerClientbound(ClientboundPackets1_18.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Hardcore
            map(Type.BOOLEAN);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            // Previous Gamemode
            map(Type.BYTE);
            // World List
            map(Type.STRING_ARRAY);
            // Registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            handler(wrapper -> {
                final CompoundTag registry = wrapper.get(Type.NBT, 0);
                final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
                final ListTag dimensions = dimensionsHolder.get("value");
                for (final Tag dimension : dimensions) {
                    removeTagPrefix(((CompoundTag) dimension).get("element"));
                }
                removeTagPrefix(wrapper.get(Type.NBT, 1));
            });
        }
    });
    registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> removeTagPrefix(wrapper.passthrough(Type.NBT)));
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ClientboundPackets1_18(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CommandRewriter1_18_2(com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2) Via(com.viaversion.viaversion.api.Via) 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) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) CommandRewriter1_18_2(com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2) 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)

Aggregations

ViaBackwards (com.viaversion.viabackwards.ViaBackwards)1 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)1 CommandRewriter1_18_2 (com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2)1 Via (com.viaversion.viaversion.api.Via)1 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 Type (com.viaversion.viaversion.api.type.Type)1 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)1 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)1 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)1 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)1 ServerboundPackets1_17 (com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17)1 ClientboundPackets1_18 (com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18)1