Search in sources :

Example 1 with ResourcePackTracker

use of com.viaversion.viaversion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker 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)

Aggregations

Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)1 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)1 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)1 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 ResourcePackTracker (com.viaversion.viaversion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker)1 Chunk1_9_3_4Type (com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type)1 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)1