Search in sources :

Example 1 with CommandRewriter1_16

use of com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16 in project ViaBackwards by ViaVersion.

the class Protocol1_15_2To1_16 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_16.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_16.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_16.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_16.TITLE);
    translatableRewriter.registerPing();
    new CommandRewriter1_16(this).registerDeclareCommands(ClientboundPackets1_16.DECLARE_COMMANDS);
    (blockItemPackets = new BlockItemPackets1_16(this)).register();
    entityRewriter.register();
    registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                String original = wrapper.passthrough(Type.STRING);
                JsonObject object = GsonUtil.getGson().fromJson(original, JsonObject.class);
                JsonElement description = object.get("description");
                if (description == null)
                    return;
                translatableRewriter.processText(description);
                wrapper.set(Type.STRING, 0, object.toString());
            });
        }
    });
    registerClientbound(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
            map(Type.BYTE);
            // Sender
            map(Type.UUID, Type.NOTHING);
        }
    });
    registerClientbound(ClientboundPackets1_16.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.VAR_INT);
            // Window Type
            map(Type.VAR_INT);
            handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
            handler(wrapper -> {
                int windowType = wrapper.get(Type.VAR_INT, 1);
                if (windowType == 20) {
                    // Smithing table
                    // Open anvil inventory
                    wrapper.set(Type.VAR_INT, 1, 7);
                } else if (windowType > 20) {
                    wrapper.set(Type.VAR_INT, 1, --windowType);
                }
            });
        }
    });
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND);
    // Login success
    registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Transform int array to plain string
                UUID uuid = wrapper.read(Type.UUID_INT_ARRAY);
                wrapper.write(Type.STRING, uuid.toString());
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
    registerServerbound(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // player id
                wrapper.passthrough(Type.VAR_INT);
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action == 0) {
                    wrapper.user().get(PlayerSneakStorage.class).setSneaking(true);
                } else if (action == 1) {
                    wrapper.user().get(PlayerSneakStorage.class).setSneaking(false);
                }
            });
        }
    });
    registerServerbound(ServerboundPackets1_14.INTERACT_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Entity Id
                wrapper.passthrough(Type.VAR_INT);
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action == 0 || action == 2) {
                    if (action == 2) {
                        // Location
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.passthrough(Type.FLOAT);
                    }
                    // Hand
                    wrapper.passthrough(Type.VAR_INT);
                }
                // New boolean: Whether the client is sneaking
                wrapper.write(Type.BOOLEAN, wrapper.user().get(PlayerSneakStorage.class).isSneaking());
            });
        }
    });
    registerServerbound(ServerboundPackets1_14.PLAYER_ABILITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                byte flags = wrapper.read(Type.BYTE);
                // Only take the isFlying value (everything else has been removed and wasn't used anyways)
                flags &= 2;
                wrapper.write(Type.BYTE, flags);
                wrapper.read(Type.FLOAT);
                wrapper.read(Type.FLOAT);
            });
        }
    });
    cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
Also used : TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) WorldNameTracker(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker) TranslatableRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat.TranslatableRewriter1_16) GsonUtil(com.viaversion.viaversion.util.GsonUtil) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Entity1_16Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) BackwardsMappings(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings) PlayerSneakStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) CommandRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16) State(com.viaversion.viaversion.api.protocol.packet.State) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) UUID(java.util.UUID) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) EntityPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BlockItemPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) BlockItemPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) CommandRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PlayerSneakStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) UUID(java.util.UUID)

Aggregations

BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)1 SoundRewriter (com.viaversion.viabackwards.api.rewriters.SoundRewriter)1 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)1 TranslatableRewriter1_16 (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat.TranslatableRewriter1_16)1 BackwardsMappings (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings)1 CommandRewriter1_16 (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16)1 WorldNameTracker (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker)1 BlockItemPackets1_16 (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16)1 EntityPackets1_16 (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16)1 PlayerSneakStorage (com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 RegistryType (com.viaversion.viaversion.api.minecraft.RegistryType)1 Entity1_16Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types)1 State (com.viaversion.viaversion.api.protocol.packet.State)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 EntityRewriter (com.viaversion.viaversion.api.rewriter.EntityRewriter)1 Type (com.viaversion.viaversion.api.type.Type)1 EntityTrackerBase (com.viaversion.viaversion.data.entity.EntityTrackerBase)1 JsonElement (com.viaversion.viaversion.libs.gson.JsonElement)1 JsonObject (com.viaversion.viaversion.libs.gson.JsonObject)1