Search in sources :

Example 6 with ClientboundPackets1_9_3

use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3 in project ViaVersion by ViaVersion.

the class Protocol1_10To1_9_3_4 method registerPackets.

@Override
protected void registerPackets() {
    itemRewriter.register();
    // Named sound effect
    registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sound name
            map(Type.STRING);
            // 1 - Sound Category
            map(Type.VAR_INT);
            // 2 - x
            map(Type.INT);
            // 3 - y
            map(Type.INT);
            // 4 - z
            map(Type.INT);
            // 5 - Volume
            map(Type.FLOAT);
            // 6 - Pitch
            map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
        }
    });
    // Sound effect
    registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sound name
            map(Type.VAR_INT);
            // 1 - Sound Category
            map(Type.VAR_INT);
            // 2 - x
            map(Type.INT);
            // 3 - y
            map(Type.INT);
            // 4 - z
            map(Type.INT);
            // 5 - Volume
            map(Type.FLOAT);
            // 6 - Pitch
            map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.VAR_INT, 0);
                    wrapper.set(Type.VAR_INT, 0, getNewSoundId(id));
                }
            });
        }
    });
    // Metadata packet
    registerClientbound(ClientboundPackets1_9_3.ENTITY_METADATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Metadata list
            map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
        }
    });
    // Spawn Mob
    registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // 1 - UUID
            map(Type.UUID);
            // 2 - Entity Type
            map(Type.UNSIGNED_BYTE);
            // 3 - X
            map(Type.DOUBLE);
            // 4 - Y
            map(Type.DOUBLE);
            // 5 - Z
            map(Type.DOUBLE);
            // 6 - Yaw
            map(Type.BYTE);
            // 7 - Pitch
            map(Type.BYTE);
            // 8 - Head Pitch
            map(Type.BYTE);
            // 9 - Velocity X
            map(Type.SHORT);
            // 10 - Velocity Y
            map(Type.SHORT);
            // 11 - Velocity Z
            map(Type.SHORT);
            // 12 - Metadata
            map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
        }
    });
    // Spawn Player
    registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Player UUID
            map(Type.UUID);
            // 2 - X
            map(Type.DOUBLE);
            // 3 - Y
            map(Type.DOUBLE);
            // 4 - Z
            map(Type.DOUBLE);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - Pitch
            map(Type.BYTE);
            // 7 - Metadata list
            map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
        }
    });
    // Join Game
    registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.INT);
            // 1 - Gamemode
            map(Type.UNSIGNED_BYTE);
            // 2 - Dimension
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    int dimensionId = wrapper.get(Type.INT, 1);
                    clientWorld.setEnvironment(dimensionId);
                }
            });
        }
    });
    // Respawn
    registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Dimension ID
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    int dimensionId = wrapper.get(Type.INT, 0);
                    clientWorld.setEnvironment(dimensionId);
                }
            });
        }
    });
    // Chunk Data
    registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk chunk = wrapper.passthrough(new Chunk1_9_3_4Type(clientWorld));
                    if (Via.getConfig().isReplacePistons()) {
                        int replacementId = Via.getConfig().getPistonReplacementId();
                        for (ChunkSection section : chunk.getSections()) {
                            if (section == null)
                                continue;
                            section.replacePaletteEntry(36, replacementId);
                        }
                    }
                }
            });
        }
    });
    // Packet Send ResourcePack
    registerClientbound(ClientboundPackets1_9_3.RESOURCE_PACK, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - URL
            map(Type.STRING);
            // 1 - Hash
            map(Type.STRING);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
                    // Store the hash for resourcepack status
                    tracker.setLastHash(wrapper.get(Type.STRING, 1));
                }
            });
        }
    });
    // Packet ResourcePack status
    registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
                    wrapper.write(Type.STRING, tracker.getLastHash());
                    wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT));
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ResourcePackTracker(com.viaversion.viaversion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 7 with ClientboundPackets1_9_3

use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_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)

Example 8 with ClientboundPackets1_9_3

use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3 in project ViaVersion by ViaVersion.

the class Protocol1_9_1_2To1_9_3_4 method registerPackets.

@Override
protected void registerPackets() {
    registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Position
            map(Type.POSITION);
            // Type
            map(Type.UNSIGNED_BYTE);
            // NBT
            map(Type.NBT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 9) {
                        Position position = wrapper.get(Type.POSITION, 0);
                        CompoundTag tag = wrapper.get(Type.NBT, 0);
                        // Clear the packet
                        wrapper.clearPacket();
                        // Update sign packet
                        wrapper.setId(ClientboundPackets1_9.UPDATE_SIGN.ordinal());
                        // Position
                        wrapper.write(Type.POSITION, position);
                        for (int i = 1; i < 5; i++) {
                            // Should technically be written as COMPONENT, but left as String for simplification/to remove redundant wrapping for VR
                            // Sign line
                            wrapper.write(Type.STRING, (String) tag.get("Text" + i).getValue());
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk1_9_3_4Type newType = new Chunk1_9_3_4Type(clientWorld);
                    // Get the old type to not write Block Entities
                    Chunk1_9_1_2Type oldType = new Chunk1_9_1_2Type(clientWorld);
                    Chunk chunk = wrapper.read(newType);
                    wrapper.write(oldType, chunk);
                    BlockEntity.handle(chunk.getBlockEntities(), wrapper.user());
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.INT);
            // 1 - Gamemode
            map(Type.UNSIGNED_BYTE);
            // 2 - Dimension
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
                    int dimensionId = wrapper.get(Type.INT, 1);
                    clientChunks.setEnvironment(dimensionId);
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Dimension ID
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    int dimensionId = wrapper.get(Type.INT, 0);
                    clientWorld.setEnvironment(dimensionId);
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Position(com.viaversion.viaversion.api.minecraft.Position) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_9_1_2Type(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Aggregations

PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)8 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)8 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)7 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)6 Chunk1_9_3_4Type (com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type)6 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)6 Type (com.viaversion.viaversion.api.type.Type)4 ClientboundPackets1_9_3 (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)3 ServerboundPackets1_9_3 (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3)3 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)2 Protocol1_10To1_11 (com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11)2 ChestedHorseStorage (com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage)2 Via (com.viaversion.viaversion.api.Via)2 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)2 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)2 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)2 Entity1_11Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types)2 Entity1_12Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types)2 AbstractProtocol (com.viaversion.viaversion.api.protocol.AbstractProtocol)2