Search in sources :

Example 1 with ClientboundPackets1_15

use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol);
    // Remove new smithing type, only in this handler
    protocol.registerClientbound(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int size = wrapper.passthrough(Type.VAR_INT);
                int newSize = size;
                for (int i = 0; i < size; i++) {
                    String originalType = wrapper.read(Type.STRING);
                    String type = originalType.replace("minecraft:", "");
                    if (type.equals("smithing")) {
                        newSize--;
                        wrapper.read(Type.STRING);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
                        wrapper.read(Type.FLAT_VAR_INT_ITEM);
                        continue;
                    }
                    wrapper.write(Type.STRING, originalType);
                    // Recipe Identifier
                    String id = wrapper.passthrough(Type.STRING);
                    recipeRewriter.handle(wrapper, type);
                }
                wrapper.set(Type.VAR_INT, 0, newSize);
            });
        }
    });
    registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
    registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_16.MULTI_BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_16.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int entityId = wrapper.passthrough(Type.VAR_INT);
                List<EquipmentData> equipmentData = new ArrayList<>();
                byte slot;
                do {
                    slot = wrapper.read(Type.BYTE);
                    Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
                    int rawSlot = slot & 0x7F;
                    equipmentData.add(new EquipmentData(rawSlot, item));
                } while ((slot & 0xFFFFFF80) != 0);
                // Send first data in the current packet
                EquipmentData firstData = equipmentData.get(0);
                wrapper.write(Type.VAR_INT, firstData.slot);
                wrapper.write(Type.FLAT_VAR_INT_ITEM, firstData.item);
                // If there are more items, send new packets for them
                for (int i = 1; i < equipmentData.size(); i++) {
                    PacketWrapper equipmentPacket = wrapper.create(ClientboundPackets1_15.ENTITY_EQUIPMENT);
                    EquipmentData data = equipmentData.get(i);
                    equipmentPacket.write(Type.VAR_INT, entityId);
                    equipmentPacket.write(Type.VAR_INT, data.slot);
                    equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, data.item);
                    equipmentPacket.send(Protocol1_15_2To1_16.class);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.UPDATE_LIGHT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // x
            map(Type.VAR_INT);
            // y
            map(Type.VAR_INT);
            map(Type.BOOLEAN, Type.NOTHING);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Chunk chunk = wrapper.read(new Chunk1_16Type());
                wrapper.write(new Chunk1_15Type(), chunk);
                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));
                    }
                }
                CompoundTag heightMaps = chunk.getHeightMap();
                for (Tag heightMapTag : heightMaps.values()) {
                    LongArrayTag heightMap = (LongArrayTag) heightMapTag;
                    int[] heightMapData = new int[256];
                    CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
                    heightMap.setValue(CompactArrayUtil.createCompactArray(9, heightMapData.length, i -> heightMapData[i]));
                }
                if (chunk.isBiomeData()) {
                    for (int i = 0; i < 1024; i++) {
                        int biome = chunk.getBiomeData()[i];
                        switch(biome) {
                            // new nether biomes
                            case 170:
                            case 171:
                            case 172:
                            case 173:
                                chunk.getBiomeData()[i] = 8;
                                break;
                        }
                    }
                }
                if (chunk.getBlockEntities() == null)
                    return;
                for (CompoundTag blockEntity : chunk.getBlockEntities()) {
                    handleBlockEntity(blockEntity);
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
    registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
    protocol.registerClientbound(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window id
            map(Type.UNSIGNED_BYTE);
            // Property
            map(Type.SHORT);
            // Value
            map(Type.SHORT);
            handler(wrapper -> {
                short property = wrapper.get(Type.SHORT, 0);
                if (property >= 4 && property <= 6) {
                    // Enchantment id
                    short enchantmentId = wrapper.get(Type.SHORT, 1);
                    if (enchantmentId > 11) {
                        // soul_speed
                        wrapper.set(Type.SHORT, 1, --enchantmentId);
                    } else if (enchantmentId == 11) {
                        wrapper.set(Type.SHORT, 1, (short) 9);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.MAP_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Map ID
            map(Type.VAR_INT);
            // Scale
            map(Type.BYTE);
            // Tracking Position
            map(Type.BOOLEAN);
            // Locked
            map(Type.BOOLEAN);
            handler(MapColorRewriter.getRewriteHandler(MapColorRewrites::getMappedColor));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Position position = wrapper.passthrough(Type.POSITION1_14);
                short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
                CompoundTag tag = wrapper.passthrough(Type.NBT);
                handleBlockEntity(tag);
            });
        }
    });
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) ArrayList(java.util.ArrayList) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) Map(java.util.Map) MapColorRewrites(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) MapColorRewriter(com.viaversion.viabackwards.api.rewriters.MapColorRewriter) Position(com.viaversion.viaversion.api.minecraft.Position) EnchantmentRewriter(com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) UUID(java.util.UUID) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) CompactArrayUtil(com.viaversion.viaversion.util.CompactArrayUtil) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) List(java.util.List) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) Position(com.viaversion.viaversion.api.minecraft.Position) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) MapColorRewrites(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) ArrayList(java.util.ArrayList) List(java.util.List) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 2 with ClientboundPackets1_15

use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaBackwards by ViaVersion.

the class EntityPackets1_16 method registerPackets.

@Override
protected void registerPackets() {
    protocol.registerClientbound(ClientboundPackets1_16.SPAWN_ENTITY, 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 - Pitch
            map(Type.BYTE);
            // 7 - Yaw
            map(Type.BYTE);
            // 8 - Data
            map(Type.INT);
            handler(wrapper -> {
                EntityType entityType = typeFromId(wrapper.get(Type.VAR_INT, 1));
                if (entityType == Entity1_16Types.LIGHTNING_BOLT) {
                    // Map to old weather entity packet
                    wrapper.cancel();
                    PacketWrapper spawnLightningPacket = wrapper.create(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY);
                    // Entity id
                    spawnLightningPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
                    // Lightning type
                    spawnLightningPacket.write(Type.BYTE, (byte) 1);
                    // X
                    spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 0));
                    // Y
                    spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 1));
                    // Z
                    spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 2));
                    spawnLightningPacket.send(Protocol1_15_2To1_16.class);
                }
            });
            handler(getSpawnTrackerWithDataHandler(Entity1_16Types.FALLING_BLOCK));
        }
    });
    registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB);
    protocol.registerClientbound(ClientboundPackets1_16.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Dimension Type
            map(dimensionTransformer);
            handler(wrapper -> {
                // Grab the tracker for world names
                WorldNameTracker worldNameTracker = wrapper.user().get(WorldNameTracker.class);
                // World Name
                String nextWorldName = wrapper.read(Type.STRING);
                // Seed
                wrapper.passthrough(Type.LONG);
                // Gamemode
                wrapper.passthrough(Type.UNSIGNED_BYTE);
                // Previous gamemode
                wrapper.read(Type.BYTE);
                // Grab client world
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                int dimension = wrapper.get(Type.INT, 0);
                // Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
                if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId() && (wrapper.user().isClientSide() || Via.getPlatform().isProxy() || // Hotfix for https://github.com/ViaVersion/ViaBackwards/issues/381
                wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_12_2.getVersion() || !nextWorldName.equals(worldNameTracker.getWorldName()))) {
                    PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN);
                    packet.write(Type.INT, dimension == 0 ? -1 : 0);
                    packet.write(Type.LONG, 0L);
                    packet.write(Type.UNSIGNED_BYTE, (short) 0);
                    packet.write(Type.STRING, "default");
                    packet.send(Protocol1_15_2To1_16.class);
                }
                clientWorld.setEnvironment(dimension);
                // Level type
                wrapper.write(Type.STRING, "default");
                // Debug
                wrapper.read(Type.BOOLEAN);
                if (wrapper.read(Type.BOOLEAN)) {
                    wrapper.set(Type.STRING, 0, "flat");
                }
                // Keep all playerdata
                wrapper.read(Type.BOOLEAN);
                // Finally update the world name
                worldNameTracker.setWorldName(nextWorldName);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            // Previous gamemode
            map(Type.BYTE, Type.NOTHING);
            // World list
            map(Type.STRING_ARRAY, Type.NOTHING);
            // whatever this is
            map(Type.NBT, Type.NOTHING);
            // Dimension Type
            map(dimensionTransformer);
            handler(wrapper -> {
                WorldNameTracker worldNameTracker = wrapper.user().get(WorldNameTracker.class);
                // Save the world name
                worldNameTracker.setWorldName(wrapper.read(Type.STRING));
            });
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
                clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
                tracker(wrapper.user()).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
                // Level type
                wrapper.write(Type.STRING, "default");
                // View distance
                wrapper.passthrough(Type.VAR_INT);
                // Reduced debug info
                wrapper.passthrough(Type.BOOLEAN);
                // Show death screen
                wrapper.passthrough(Type.BOOLEAN);
                // Debug
                wrapper.read(Type.BOOLEAN);
                if (wrapper.read(Type.BOOLEAN)) {
                    wrapper.set(Type.STRING, 0, "flat");
                }
            });
        }
    });
    registerTracker(ClientboundPackets1_16.SPAWN_EXPERIENCE_ORB, Entity1_16Types.EXPERIENCE_ORB);
    // F Spawn Global Object, it is no longer with us :(
    registerTracker(ClientboundPackets1_16.SPAWN_PAINTING, Entity1_16Types.PAINTING);
    registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16Types.PLAYER);
    registerRemoveEntities(ClientboundPackets1_16.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_16.METADATA_LIST, Types1_14.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_16.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.VAR_INT);
                int size = wrapper.passthrough(Type.INT);
                for (int i = 0; i < size; i++) {
                    String attributeIdentifier = wrapper.read(Type.STRING);
                    String oldKey = protocol.getMappingData().getAttributeMappings().get(attributeIdentifier);
                    wrapper.write(Type.STRING, oldKey != null ? oldKey : attributeIdentifier.replace("minecraft:", ""));
                    wrapper.passthrough(Type.DOUBLE);
                    int modifierSize = wrapper.passthrough(Type.VAR_INT);
                    for (int j = 0; j < modifierSize; j++) {
                        wrapper.passthrough(Type.UUID);
                        wrapper.passthrough(Type.DOUBLE);
                        wrapper.passthrough(Type.BYTE);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16.PLAYER_INFO, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(packetWrapper -> {
                int action = packetWrapper.passthrough(Type.VAR_INT);
                int playerCount = packetWrapper.passthrough(Type.VAR_INT);
                for (int i = 0; i < playerCount; i++) {
                    packetWrapper.passthrough(Type.UUID);
                    if (action == 0) {
                        // Add
                        packetWrapper.passthrough(Type.STRING);
                        int properties = packetWrapper.passthrough(Type.VAR_INT);
                        for (int j = 0; j < properties; j++) {
                            packetWrapper.passthrough(Type.STRING);
                            packetWrapper.passthrough(Type.STRING);
                            if (packetWrapper.passthrough(Type.BOOLEAN)) {
                                packetWrapper.passthrough(Type.STRING);
                            }
                        }
                        packetWrapper.passthrough(Type.VAR_INT);
                        packetWrapper.passthrough(Type.VAR_INT);
                        if (packetWrapper.passthrough(Type.BOOLEAN)) {
                            // Display Name
                            protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.COMPONENT));
                        }
                    } else if (action == 1) {
                        // Update Game Mode
                        packetWrapper.passthrough(Type.VAR_INT);
                    } else if (action == 2) {
                        // Update Ping
                        packetWrapper.passthrough(Type.VAR_INT);
                    } else if (action == 3) {
                        // Update Display Name
                        if (packetWrapper.passthrough(Type.BOOLEAN)) {
                            // Display name
                            protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.COMPONENT));
                        }
                    }
                // 4 = Remove Player
                }
            });
        }
    });
}
Also used : Particle(com.viaversion.viaversion.api.type.types.Particle) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) WorldNameTracker(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker) WolfDataMaskStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.WolfDataMaskStorage) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) Via(com.viaversion.viaversion.api.Via) Item(com.viaversion.viaversion.api.minecraft.item.Item) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) Types1_16(com.viaversion.viaversion.api.type.types.version.Types1_16) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) Type(com.viaversion.viaversion.api.type.Type) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) Entity1_16Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) WorldNameTracker(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)

Example 3 with ClientboundPackets1_15

use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaBackwards by ViaVersion.

the class EntityPackets1_15 method registerPackets.

@Override
protected void registerPackets() {
    protocol.registerClientbound(ClientboundPackets1_15.UPDATE_HEALTH, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                float health = wrapper.passthrough(Type.FLOAT);
                if (health > 0)
                    return;
                if (!wrapper.user().get(ImmediateRespawn.class).isImmediateRespawn())
                    return;
                // Instantly request respawn when 1.15 gamerule is set
                PacketWrapper statusPacket = wrapper.create(ServerboundPackets1_14.CLIENT_STATUS);
                statusPacket.write(Type.VAR_INT, 0);
                statusPacket.sendToServer(Protocol1_14_4To1_15.class);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.GAME_EVENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.UNSIGNED_BYTE);
            map(Type.FLOAT);
            handler(wrapper -> {
                if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) {
                    wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.get(Type.FLOAT, 0) == 1);
                }
            });
        }
    });
    registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
    protocol.registerClientbound(ClientboundPackets1_15.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);
            // Metadata is no longer sent in 1.15, so we have to send an empty one
            handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>()));
            handler(wrapper -> {
                int type = wrapper.get(Type.VAR_INT, 1);
                EntityType entityType = Entity1_15Types.getTypeFromId(type);
                tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
                wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.INT);
            // Seed
            map(Type.LONG, Type.NOTHING);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.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);
            // Seed
            map(Type.LONG, Type.NOTHING);
            // 3 - Max Players
            map(Type.UNSIGNED_BYTE);
            // 4 - Level Type
            map(Type.STRING);
            // 5 - View Distance
            map(Type.VAR_INT);
            // 6 - Reduce Debug Info
            map(Type.BOOLEAN);
            handler(getTrackerHandler(Entity1_15Types.PLAYER, Type.INT));
            handler(wrapper -> {
                // Inverted
                boolean immediateRespawn = !wrapper.read(Type.BOOLEAN);
                wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(immediateRespawn);
            });
        }
    });
    registerTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, Entity1_15Types.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, Entity1_15Types.LIGHTNING_BOLT);
    registerTracker(ClientboundPackets1_15.SPAWN_PAINTING, Entity1_15Types.PAINTING);
    protocol.registerClientbound(ClientboundPackets1_15.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);
            // Metadata is no longer sent in 1.15, so we have to send an empty one
            handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>()));
            handler(getTrackerHandler(Entity1_15Types.PLAYER, Type.VAR_INT));
        }
    });
    registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
    // Attributes (get rid of generic.flyingSpeed for the Bee remap)
    protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.INT);
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                EntityType entityType = tracker(wrapper.user()).entityType(entityId);
                if (entityType != Entity1_15Types.BEE)
                    return;
                int size = wrapper.get(Type.INT, 0);
                int newSize = size;
                for (int i = 0; i < size; i++) {
                    String key = wrapper.read(Type.STRING);
                    if (key.equals("generic.flyingSpeed")) {
                        newSize--;
                        wrapper.read(Type.DOUBLE);
                        int modSize = wrapper.read(Type.VAR_INT);
                        for (int j = 0; j < modSize; j++) {
                            wrapper.read(Type.UUID);
                            wrapper.read(Type.DOUBLE);
                            wrapper.read(Type.BYTE);
                        }
                    } else {
                        wrapper.write(Type.STRING, key);
                        wrapper.passthrough(Type.DOUBLE);
                        int modSize = wrapper.passthrough(Type.VAR_INT);
                        for (int j = 0; j < modSize; j++) {
                            wrapper.passthrough(Type.UUID);
                            wrapper.passthrough(Type.DOUBLE);
                            wrapper.passthrough(Type.BYTE);
                        }
                    }
                }
                if (newSize != size) {
                    wrapper.set(Type.INT, 0, newSize);
                }
            });
        }
    });
}
Also used : Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) EntityTypeMapping(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) ArrayList(java.util.ArrayList) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ImmediateRespawn(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn) Protocol1_14_4To1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) ImmediateRespawn(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn) Protocol1_14_4To1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

Example 4 with ClientboundPackets1_15

use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaVersion by ViaVersion.

the class Protocol1_16To1_15_2 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    WorldPackets.register(this);
    tagRewriter = new TagRewriter(this);
    tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
    // Login Success
    registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Transform string to int array
                UUID uuid = UUID.fromString(wrapper.read(Type.STRING));
                wrapper.write(Type.UUID_INT_ARRAY, uuid);
            });
        }
    });
    // Motd Status - line breaks are no longer allowed for player samples
    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);
                JsonObject players = object.getAsJsonObject("players");
                if (players == null)
                    return;
                JsonArray sample = players.getAsJsonArray("sample");
                if (sample == null)
                    return;
                JsonArray splitSamples = new JsonArray();
                for (JsonElement element : sample) {
                    JsonObject playerInfo = element.getAsJsonObject();
                    String name = playerInfo.getAsJsonPrimitive("name").getAsString();
                    if (name.indexOf('\n') == -1) {
                        splitSamples.add(playerInfo);
                        continue;
                    }
                    String id = playerInfo.getAsJsonPrimitive("id").getAsString();
                    for (String s : name.split("\n")) {
                        JsonObject newSample = new JsonObject();
                        newSample.addProperty("name", s);
                        newSample.addProperty("id", id);
                        splitSamples.add(newSample);
                    }
                }
                // Replace data if changed
                if (splitSamples.size() != sample.size()) {
                    players.add("sample", splitSamples);
                    wrapper.set(Type.STRING, 0, object.toString());
                }
            });
        }
    });
    ComponentRewriter componentRewriter = new TranslationMappings(this);
    // Handle (relevant) component cases for translatable and score changes
    registerClientbound(ClientboundPackets1_15.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.COMPONENT);
            map(Type.BYTE);
            handler(wrapper -> {
                componentRewriter.processText(wrapper.get(Type.COMPONENT, 0));
                // Sender uuid - always send as 'system'
                wrapper.write(Type.UUID, ZERO_UUID);
            });
        }
    });
    componentRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
    componentRewriter.registerTitle(ClientboundPackets1_15.TITLE);
    componentRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
    registerServerbound(ServerboundPackets1_16.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/pressing shift
                wrapper.read(Type.BOOLEAN);
            });
        }
    });
    if (Via.getConfig().isIgnoreLong1_16ChannelNames()) {
        registerServerbound(ServerboundPackets1_16.PLUGIN_MESSAGE, new PacketRemapper() {

            @Override
            public void registerMap() {
                handler(wrapper -> {
                    String channel = wrapper.passthrough(Type.STRING);
                    if (channel.length() > 32) {
                        if (!Via.getConfig().isSuppressConversionWarnings()) {
                            Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel, as it is longer than 32 characters: " + channel);
                        }
                        wrapper.cancel();
                    } else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
                        String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
                        List<String> checkedChannels = new ArrayList<>(channels.length);
                        for (String registeredChannel : channels) {
                            if (registeredChannel.length() > 32) {
                                if (!Via.getConfig().isSuppressConversionWarnings()) {
                                    Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel register of '" + registeredChannel + "', as it is longer than 32 characters");
                                }
                                continue;
                            }
                            checkedChannels.add(registeredChannel);
                        }
                        if (checkedChannels.isEmpty()) {
                            wrapper.cancel();
                            return;
                        }
                        wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(checkedChannels).getBytes(StandardCharsets.UTF_8));
                    }
                });
            }
        });
    }
    registerServerbound(ServerboundPackets1_16.PLAYER_ABILITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.BYTE);
                // Flying and walking speed - not important anyways
                wrapper.write(Type.FLOAT, 0.05F);
                wrapper.write(Type.FLOAT, 0.1F);
            });
        }
    });
    cancelServerbound(ServerboundPackets1_16.GENERATE_JIGSAW);
    cancelServerbound(ServerboundPackets1_16.UPDATE_JIGSAW_BLOCK);
}
Also used : ComponentRewriter(com.viaversion.viaversion.rewriter.ComponentRewriter) JsonObject(com.google.gson.JsonObject) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) ParticleType(com.viaversion.viaversion.api.type.types.minecraft.ParticleType) GsonUtil(com.viaversion.viaversion.util.GsonUtil) Types1_16(com.viaversion.viaversion.api.type.types.version.Types1_16) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) 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) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) MetadataRewriter1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2) EntityPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets) MappingData(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.MappingData) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets) State(com.viaversion.viaversion.api.protocol.packet.State) UUID(java.util.UUID) Via(com.viaversion.viaversion.api.Via) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) StandardCharsets(java.nio.charset.StandardCharsets) JsonArray(com.google.gson.JsonArray) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) List(java.util.List) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) TranslationMappings(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.TranslationMappings) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) WorldPackets(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets) Joiner(com.google.common.base.Joiner) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) ComponentRewriter(com.viaversion.viaversion.rewriter.ComponentRewriter) JsonElement(com.google.gson.JsonElement) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) TranslationMappings(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.TranslationMappings) UUID(java.util.UUID)

Example 5 with ClientboundPackets1_15

use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_15 method registerPackets.

@Override
protected void registerPackets() {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
    registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
    blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
    protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Chunk chunk = wrapper.read(new Chunk1_15Type());
                    wrapper.write(new Chunk1_14Type(), chunk);
                    if (chunk.isFullChunk()) {
                        int[] biomeData = chunk.getBiomeData();
                        int[] newBiomeData = new int[256];
                        for (int i = 0; i < 4; ++i) {
                            for (int j = 0; j < 4; ++j) {
                                int x = j << 2;
                                int z = i << 2;
                                int newIndex = z << 4 | x;
                                int oldIndex = i << 2 | j;
                                int biome = biomeData[oldIndex];
                                for (int k = 0; k < 4; k++) {
                                    int offX = newIndex + (k << 4);
                                    for (int l = 0; l < 4; l++) {
                                        newBiomeData[offX + l] = biome;
                                    }
                                }
                            }
                        }
                        chunk.setBiomeData(newBiomeData);
                    }
                    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);
                            int newId = protocol.getMappingData().getNewBlockStateId(old);
                            section.setPaletteEntry(j, newId);
                        }
                    }
                }
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
    protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Particle ID
            map(Type.INT);
            // 1 - Long Distance
            map(Type.BOOLEAN);
            // 2 - X
            map(Type.DOUBLE, Type.FLOAT);
            // 3 - Y
            map(Type.DOUBLE, Type.FLOAT);
            // 4 - Z
            map(Type.DOUBLE, Type.FLOAT);
            // 5 - Offset X
            map(Type.FLOAT);
            // 6 - Offset Y
            map(Type.FLOAT);
            // 7 - Offset Z
            map(Type.FLOAT);
            // 8 - Particle Data
            map(Type.FLOAT);
            // 9 - Particle Count
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 3 || id == 23) {
                        int data = wrapper.passthrough(Type.VAR_INT);
                        wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
                    } else if (id == 32) {
                        Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
                        wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
                    }
                    int mappedId = protocol.getMappingData().getNewParticleId(id);
                    if (id != mappedId) {
                        wrapper.set(Type.INT, 0, mappedId);
                    }
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Chunk1_14Type(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type) Item(com.viaversion.viaversion.api.minecraft.item.Item) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Protocol1_14_4To1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) Chunk1_14Type(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)9 Type (com.viaversion.viaversion.api.type.Type)9 ClientboundPackets1_15 (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15)9 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)6 ServerboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14)5 UUID (java.util.UUID)5 Item (com.viaversion.viaversion.api.minecraft.item.Item)4 ClientboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)3 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)3 Via (com.viaversion.viaversion.api.Via)3 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)3 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)3 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)3 Protocol1_16To1_15_2 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2)3 ArrayList (java.util.ArrayList)3 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)2 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)2 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)2 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)2