Search in sources :

Example 6 with ServerboundPackets1_9_3

use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3 in project ViaBackwards by ViaVersion.

the class PlayerPackets1_11 method register.

public void register(Protocol1_10To1_11 protocol) {
    protocol.registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action
            map(Type.VAR_INT);
            handler(wrapper -> {
                int action = wrapper.get(Type.VAR_INT, 0);
                if (action == 2) {
                    // Handle the new ActionBar
                    JsonElement message = wrapper.read(Type.COMPONENT);
                    wrapper.clearPacket();
                    wrapper.setId(ClientboundPackets1_9_3.CHAT_MESSAGE.ordinal());
                    // https://bugs.mojang.com/browse/MC-119145to
                    String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
                    message = new JsonObject();
                    message.getAsJsonObject().addProperty("text", legacy);
                    wrapper.write(Type.COMPONENT, message);
                    wrapper.write(Type.BYTE, (byte) 2);
                } else if (action > 2) {
                    // Move everything one position down
                    wrapper.set(Type.VAR_INT, 0, action - 1);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Collected entity id
            map(Type.VAR_INT);
            // 1 - Collector entity id
            map(Type.VAR_INT);
            // Ignore item pickup count
            handler(wrapper -> wrapper.read(Type.VAR_INT));
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Location
            map(Type.POSITION);
            // 1 - Face
            map(Type.VAR_INT);
            // 2 - Hand
            map(Type.VAR_INT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) LegacyComponentSerializer(com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Type(com.viaversion.viaversion.api.type.Type) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ServerboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) GsonComponentSerializer(com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer) Protocol1_10To1_11(com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Aggregations

PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)6 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)6 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)5 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)5 Chunk1_9_3_4Type (com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type)5 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)5 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)3 Item (com.viaversion.viaversion.api.minecraft.item.Item)2 ValueTransformer (com.viaversion.viaversion.api.protocol.remapper.ValueTransformer)2 Type (com.viaversion.viaversion.api.type.Type)2 ClientboundPackets1_9_3 (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3)2 ServerboundPackets1_9_3 (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3)2 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)1 MappedLegacyBlockItem (com.viaversion.viabackwards.api.data.MappedLegacyBlockItem)1 Protocol1_10To1_11 (com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11)1 ChestedHorseStorage (com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage)1 WindowTracker (com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker)1 Via (com.viaversion.viaversion.api.Via)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1