Search in sources :

Example 71 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class EntityPackets1_18 method registerPackets.

@Override
protected void registerPackets() {
    registerMetadataRewriter(ClientboundPackets1_18.ENTITY_METADATA, Types1_18.METADATA_LIST, Types1_17.METADATA_LIST);
    protocol.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);
            // Worlds
            map(Type.STRING_ARRAY);
            // Dimension registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.VAR_INT);
            // Chunk radius
            map(Type.VAR_INT);
            // Read simulation distance
            read(Type.VAR_INT);
            handler(worldDataTrackerHandler(1));
            handler(wrapper -> {
                final CompoundTag registry = wrapper.get(Type.NBT, 0);
                final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
                final ListTag biomes = biomeRegistry.get("value");
                for (final Tag biome : biomes.getValue()) {
                    final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
                    final StringTag category = biomeCompound.get("category");
                    if (category.getValue().equals("mountain")) {
                        category.setValue("extreme_hills");
                    }
                    // The client just needs something
                    biomeCompound.put("depth", new FloatTag(0.125F));
                    biomeCompound.put("scale", new FloatTag(0.05F));
                }
                // Track amount of biomes sent
                tracker(wrapper.user()).setBiomesSent(biomes.size());
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            handler(worldDataTrackerHandler(0));
        }
    });
}
Also used : Particle(com.viaversion.viaversion.api.type.types.Particle) ClientboundPackets1_18(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) Types1_17(com.viaversion.viaversion.api.type.types.version.Types1_17) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Types1_18(com.viaversion.viaversion.api.type.types.version.Types1_18) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) Protocol1_17_1To1_18(com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) 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) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 72 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper 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)

Example 73 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16_2 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
    registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
    registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.VAR_INT);
                // Open
                wrapper.passthrough(Type.BOOLEAN);
                // Filter
                wrapper.passthrough(Type.BOOLEAN);
                // Furnace Open
                wrapper.passthrough(Type.BOOLEAN);
                // Filter furnace
                wrapper.passthrough(Type.BOOLEAN);
                // Blast furnace / smoker
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
                wrapper.read(Type.BOOLEAN);
            });
        }
    });
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Chunk chunk = wrapper.read(new Chunk1_16_2Type());
                wrapper.write(new Chunk1_16Type(), chunk);
                chunk.setIgnoreOldLightData(true);
                for (int i = 0; i < chunk.getSections().length; i++) {
                    ChunkSection section = chunk.getSections()[i];
                    if (section == null)
                        continue;
                    for (int j = 0; j < section.getPaletteSize(); j++) {
                        int old = section.getPaletteEntry(j);
                        section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
                    }
                }
                for (CompoundTag blockEntity : chunk.getBlockEntities()) {
                    if (blockEntity != null) {
                        handleBlockEntity(blockEntity);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                handleBlockEntity(wrapper.passthrough(Type.NBT));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                long chunkPosition = wrapper.read(Type.LONG);
                // Ignore old light data
                wrapper.read(Type.BOOLEAN);
                int chunkX = (int) (chunkPosition >> 42);
                int chunkY = (int) (chunkPosition << 44 >> 44);
                int chunkZ = (int) (chunkPosition << 22 >> 42);
                wrapper.write(Type.INT, chunkX);
                wrapper.write(Type.INT, chunkZ);
                BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY);
                wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord);
                for (int i = 0; i < blockChangeRecord.length; i++) {
                    BlockChangeRecord record = blockChangeRecord[i];
                    int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
                    // Relative y -> absolute y
                    blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId);
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
    registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
    registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
}
Also used : BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8) 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) BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Chunk1_16_2Type(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) Protocol1_16_1To1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) BlockChangeRecord1_8(com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_16_2Type(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 74 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class EntityPackets1_16_2 method registerPackets.

@Override
protected void registerPackets() {
    registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
    registerSpawnTracker(ClientboundPackets1_16_2.SPAWN_MOB);
    registerTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
    registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
    registerRemoveEntities(ClientboundPackets1_16_2.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_16.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            handler(wrapper -> {
                boolean hardcore = wrapper.read(Type.BOOLEAN);
                short gamemode = wrapper.read(Type.UNSIGNED_BYTE);
                if (hardcore) {
                    gamemode |= 0x08;
                }
                wrapper.write(Type.UNSIGNED_BYTE, gamemode);
            });
            // Previous Gamemode
            map(Type.BYTE);
            // World List
            map(Type.STRING_ARRAY);
            handler(wrapper -> {
                // Just screw the registry and write the defaults for 1.16 and 1.16.1 clients
                wrapper.read(Type.NBT);
                wrapper.write(Type.NBT, EntityPackets.DIMENSIONS_TAG);
                CompoundTag dimensionData = wrapper.read(Type.NBT);
                wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
            });
            // Dimension
            map(Type.STRING);
            // Seed
            map(Type.LONG);
            handler(wrapper -> {
                int maxPlayers = wrapper.read(Type.VAR_INT);
                wrapper.write(Type.UNSIGNED_BYTE, (short) Math.max(maxPlayers, 255));
            });
            // ...
            handler(getTrackerHandler(Entity1_16_2Types.PLAYER, Type.INT));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                CompoundTag dimensionData = wrapper.read(Type.NBT);
                wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
            });
        }
    });
}
Also used : Set(java.util.Set) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) Sets(com.google.common.collect.Sets) Entity1_16_2Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types) Types1_16(com.viaversion.viaversion.api.type.types.version.Types1_16) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) Protocol1_16_1To1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) EntityPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 75 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class EntityPackets1_13_1 method registerPackets.

@Override
protected void registerPackets() {
    protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // 1 - UUID
            map(Type.UUID);
            // 2 - Type
            map(Type.BYTE);
            // 3 - X
            map(Type.DOUBLE);
            // 4 - Y
            map(Type.DOUBLE);
            // 5 - Z
            map(Type.DOUBLE);
            // 6 - Pitch
            map(Type.BYTE);
            // 7 - Yaw
            map(Type.BYTE);
            // 8 - Data
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    byte type = wrapper.get(Type.BYTE, 0);
                    Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true);
                    if (entType == null) {
                        ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
                        return;
                    }
                    // Rewrite falling block
                    if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
                        int data = wrapper.get(Type.INT, 0);
                        wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
                    }
                    // Track Entity
                    tracker(wrapper.user()).addEntity(entityId, entType);
                }
            });
        }
    });
    registerTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, Entity1_13Types.EntityType.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, Entity1_13Types.EntityType.LIGHTNING_BOLT);
    protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Entity UUID
            map(Type.UUID);
            // 2 - Entity Type
            map(Type.VAR_INT);
            // 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_13.METADATA_LIST);
            // Track Entity
            handler(getTrackerHandler());
            // Rewrite Metadata
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadata = wrapper.get(Types1_13.METADATA_LIST, 0);
                    handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_13.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
            map(Types1_13.METADATA_LIST);
            handler(getTrackerAndMetaHandler(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
        }
    });
    registerTracker(ClientboundPackets1_13.SPAWN_PAINTING, Entity1_13Types.EntityType.PAINTING);
    registerJoinGame(ClientboundPackets1_13.JOIN_GAME, Entity1_13Types.EntityType.PLAYER);
    registerRespawn(ClientboundPackets1_13.RESPAWN);
    registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST);
}
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) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Entity1_13Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)109 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)78 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)65 Type (com.viaversion.viaversion.api.type.Type)64 Item (com.viaversion.viaversion.api.minecraft.item.Item)31 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)24 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)24 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)21 Via (com.viaversion.viaversion.api.Via)19 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)19 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)17 ArrayList (java.util.ArrayList)17 List (java.util.List)17 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)16 Position (com.viaversion.viaversion.api.minecraft.Position)14 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)14 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)14 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)13 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)13 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)13