Search in sources :

Example 96 with PacketRemapper

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

the class Protocol1_18To1_17_1 method registerPackets.

@Override
protected void registerPackets() {
    entityRewriter.register();
    itemRewriter.register();
    WorldPackets.register(this);
    final SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_17_1.ENTITY_SOUND);
    final TagRewriter tagRewriter = new TagRewriter(this);
    tagRewriter.registerGeneric(ClientboundPackets1_17_1.TAGS);
    tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:lava_pool_stone_cannot_replace", "minecraft:big_dripleaf_placeable", "minecraft:wolves_spawnable_on", "minecraft:rabbits_spawnable_on", "minecraft:polar_bears_spawnable_on_in_frozen_ocean", "minecraft:parrots_spawnable_on", "minecraft:mooshrooms_spawnable_on", "minecraft:goats_spawnable_on", "minecraft:foxes_spawnable_on", "minecraft:axolotls_spawnable_on", "minecraft:animals_spawnable_on", "minecraft:azalea_grows_on", "minecraft:azalea_root_replaceable", "minecraft:replaceable_plants", "minecraft:terracotta");
    tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:dirt", "minecraft:terracotta");
    new StatisticsRewriter(this).register(ClientboundPackets1_17_1.STATISTICS);
    registerServerbound(ServerboundPackets1_17.CLIENT_SETTINGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Language
            map(Type.STRING);
            // View distance
            map(Type.BYTE);
            // Chat visibility
            map(Type.VAR_INT);
            // Chat colors
            map(Type.BOOLEAN);
            // Model customization
            map(Type.UNSIGNED_BYTE);
            // Main hand
            map(Type.VAR_INT);
            // Text filtering enabled
            map(Type.BOOLEAN);
            // Allow listing in server list preview
            read(Type.BOOLEAN);
        }
    });
}
Also used : StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter)

Example 97 with PacketRemapper

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

the class EntityPackets method registerPackets.

@Override
public void registerPackets() {
    registerMetadataRewriter(ClientboundPackets1_17_1.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_18.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_17_1.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);
            // World
            map(Type.STRING);
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.VAR_INT);
            handler(wrapper -> {
                int chunkRadius = wrapper.passthrough(Type.VAR_INT);
                // Simulation distance
                wrapper.write(Type.VAR_INT, chunkRadius);
            });
            handler(worldDataTrackerHandler(1));
            handler(biomeSizeTracker());
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Current dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            handler(wrapper -> {
                final String world = wrapper.get(Type.STRING, 0);
                final EntityTracker tracker = tracker(wrapper.user());
                if (!world.equals(tracker.currentWorld())) {
                    wrapper.user().get(ChunkLightStorage.class).clear();
                }
            });
            handler(worldDataTrackerHandler(0));
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) Type(com.viaversion.viaversion.api.type.Type) Particle(com.viaversion.viaversion.api.type.types.Particle) Types1_18(com.viaversion.viaversion.api.type.types.version.Types1_18) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) ChunkLightStorage(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage) ClientboundPackets1_17_1(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) Types1_17(com.viaversion.viaversion.api.type.types.version.Types1_17) Protocol1_18To1_17_1(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

Example 98 with PacketRemapper

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

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_17_1.COOLDOWN);
    registerWindowItems1_17_1(ClientboundPackets1_17_1.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_17_1.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot1_17_1(ClientboundPackets1_17_1.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_17_1.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipmentArray(ClientboundPackets1_17_1.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_17_1.EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Effect id
            map(Type.INT);
            // Location
            map(Type.POSITION1_14);
            // Data
            map(Type.INT);
            handler(wrapper -> {
                int id = wrapper.get(Type.INT, 0);
                int data = wrapper.get(Type.INT, 1);
                if (id == 1010) {
                    // Play record
                    wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.SPAWN_PARTICLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Particle id
            map(Type.INT);
            // Override limiter
            map(Type.BOOLEAN);
            // X
            map(Type.DOUBLE);
            // Y
            map(Type.DOUBLE);
            // Z
            map(Type.DOUBLE);
            // Offset X
            map(Type.FLOAT);
            // Offset Y
            map(Type.FLOAT);
            // Offset Z
            map(Type.FLOAT);
            // Max speed
            map(Type.FLOAT);
            // Particle Count
            map(Type.INT);
            handler(wrapper -> {
                int id = wrapper.get(Type.INT, 0);
                if (id == 2) {
                    // Barrier
                    // Block marker
                    wrapper.set(Type.INT, 0, 3);
                    wrapper.write(Type.VAR_INT, 7754);
                    return;
                } else if (id == 3) {
                    // Light block
                    wrapper.write(Type.VAR_INT, 7786);
                    return;
                }
                ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
                if (mappings.isBlockParticle(id)) {
                    int data = wrapper.passthrough(Type.VAR_INT);
                    wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
                } else if (mappings.isItemParticle(id)) {
                    handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
                }
                int newId = protocol.getMappingData().getNewParticleId(id);
                if (newId != id) {
                    wrapper.set(Type.INT, 0, newId);
                }
            });
        }
    });
    new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_17_1.DECLARE_RECIPES);
    registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) Type(com.viaversion.viaversion.api.type.Type) ParticleMappings(com.viaversion.viaversion.api.data.ParticleMappings) ClientboundPackets1_17_1(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) Protocol1_18To1_17_1(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ParticleMappings(com.viaversion.viaversion.api.data.ParticleMappings)

Example 99 with PacketRemapper

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

the class WorldPackets method register.

public static void register(final Protocol1_18To1_17_1 protocol) {
    protocol.registerClientbound(ClientboundPackets1_17_1.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            handler(wrapper -> {
                final short id = wrapper.read(Type.UNSIGNED_BYTE);
                final int newId = BlockEntityIds.newId(id);
                wrapper.write(Type.VAR_INT, newId);
                handleSpawners(newId, wrapper.passthrough(Type.NBT));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.UPDATE_LIGHT, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                final int chunkX = wrapper.passthrough(Type.VAR_INT);
                final int chunkZ = wrapper.passthrough(Type.VAR_INT);
                if (wrapper.user().get(ChunkLightStorage.class).isLoaded(chunkX, chunkZ)) {
                    if (!Via.getConfig().cache1_17Light()) {
                        // Light packets updating already sent chunks are the same as before
                        return;
                    }
                // Pass through and cache light data
                } else {
                    // Cancel and cache the light data
                    wrapper.cancel();
                }
                final boolean trustEdges = wrapper.passthrough(Type.BOOLEAN);
                final long[] skyLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
                final long[] blockLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
                final long[] emptySkyLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
                final long[] emptyBlockLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
                final int skyLightLenght = wrapper.passthrough(Type.VAR_INT);
                final byte[][] skyLight = new byte[skyLightLenght][];
                for (int i = 0; i < skyLightLenght; i++) {
                    skyLight[i] = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
                }
                final int blockLightLength = wrapper.passthrough(Type.VAR_INT);
                final byte[][] blockLight = new byte[blockLightLength][];
                for (int i = 0; i < blockLightLength; i++) {
                    blockLight[i] = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
                }
                final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
                lightStorage.storeLight(chunkX, chunkZ, new ChunkLightStorage.ChunkLight(trustEdges, skyLightMask, blockLightMask, emptySkyLightMask, emptyBlockLightMask, skyLight, blockLight));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
                final Chunk oldChunk = wrapper.read(new Chunk1_17Type(tracker.currentWorldSectionHeight()));
                final List<BlockEntity> blockEntities = new ArrayList<>(oldChunk.getBlockEntities().size());
                for (final CompoundTag tag : oldChunk.getBlockEntities()) {
                    final NumberTag xTag = tag.get("x");
                    final NumberTag yTag = tag.get("y");
                    final NumberTag zTag = tag.get("z");
                    final StringTag idTag = tag.get("id");
                    if (xTag == null || yTag == null || zTag == null || idTag == null) {
                        continue;
                    }
                    final String id = idTag.getValue();
                    final int typeId = protocol.getMappingData().blockEntityIds().getInt(id.replace("minecraft:", ""));
                    if (typeId == -1) {
                        Via.getPlatform().getLogger().warning("Unknown block entity: " + id);
                    }
                    handleSpawners(typeId, tag);
                    final byte packedXZ = (byte) ((xTag.asInt() & 15) << 4 | (zTag.asInt() & 15));
                    blockEntities.add(new BlockEntityImpl(packedXZ, yTag.asShort(), typeId, tag));
                }
                final int[] biomeData = oldChunk.getBiomeData();
                final ChunkSection[] sections = oldChunk.getSections();
                for (int i = 0; i < sections.length; i++) {
                    ChunkSection section = sections[i];
                    if (section == null) {
                        // There's no section mask anymore
                        section = new ChunkSectionImpl();
                        sections[i] = section;
                        section.setNonAirBlocksCount(0);
                        final DataPaletteImpl blockPalette = new DataPaletteImpl(ChunkSection.SIZE);
                        blockPalette.addId(0);
                        section.addPalette(PaletteType.BLOCKS, blockPalette);
                    }
                    // Fill biome palette
                    final DataPaletteImpl biomePalette = new DataPaletteImpl(ChunkSection.BIOME_SIZE);
                    section.addPalette(PaletteType.BIOMES, biomePalette);
                    final int offset = i * ChunkSection.BIOME_SIZE;
                    for (int biomeIndex = 0, biomeArrayIndex = offset; biomeIndex < ChunkSection.BIOME_SIZE; biomeIndex++, biomeArrayIndex++) {
                        // Also catch invalid biomes with id -1
                        final int biome = biomeData[biomeArrayIndex];
                        biomePalette.setIdAt(biomeIndex, biome != -1 ? biome : 0);
                    }
                }
                final Chunk chunk = new Chunk1_18(oldChunk.getX(), oldChunk.getZ(), sections, oldChunk.getHeightMap(), blockEntities);
                wrapper.write(new Chunk1_18Type(tracker.currentWorldSectionHeight(), MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), MathUtil.ceilLog2(tracker.biomesSent())), chunk);
                final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
                final boolean alreadyLoaded = !lightStorage.addLoadedChunk(chunk.getX(), chunk.getZ());
                // Append light data to chunk packet
                final ChunkLightStorage.ChunkLight light = Via.getConfig().cache1_17Light() ? lightStorage.getLight(chunk.getX(), chunk.getZ()) : lightStorage.removeLight(chunk.getX(), chunk.getZ());
                if (light == null) {
                    Via.getPlatform().getLogger().warning("No light data found for chunk at " + chunk.getX() + ", " + chunk.getZ() + ". Chunk was already loaded: " + alreadyLoaded);
                    final BitSet emptyLightMask = new BitSet();
                    emptyLightMask.set(0, tracker.currentWorldSectionHeight() + 2);
                    wrapper.write(Type.BOOLEAN, false);
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
                    wrapper.write(Type.VAR_INT, 0);
                    wrapper.write(Type.VAR_INT, 0);
                } else {
                    wrapper.write(Type.BOOLEAN, light.trustEdges());
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.skyLightMask());
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.blockLightMask());
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.emptySkyLightMask());
                    wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.emptyBlockLightMask());
                    wrapper.write(Type.VAR_INT, light.skyLight().length);
                    for (final byte[] skyLight : light.skyLight()) {
                        wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, skyLight);
                    }
                    wrapper.write(Type.VAR_INT, light.blockLight().length);
                    for (final byte[] blockLight : light.blockLight()) {
                        wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, blockLight);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.UNLOAD_CHUNK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                final int chunkX = wrapper.passthrough(Type.INT);
                final int chunkZ = wrapper.passthrough(Type.INT);
                wrapper.user().get(ChunkLightStorage.class).clear(chunkX, chunkZ);
            });
        }
    });
}
Also used : BlockEntityImpl(com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl) MathUtil(com.viaversion.viaversion.util.MathUtil) ChunkLightStorage(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) Via(com.viaversion.viaversion.api.Via) Protocol1_18To1_17_1(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1) com.viaversion.viaversion.api.minecraft.chunks(com.viaversion.viaversion.api.minecraft.chunks) ArrayList(java.util.ArrayList) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk1_17Type(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type) List(java.util.List) ClientboundPackets1_17_1(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) BitSet(java.util.BitSet) BlockEntityIds(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.BlockEntityIds) Chunk1_18Type(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type) BlockEntity(com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Chunk1_17Type(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) BitSet(java.util.BitSet) BlockEntityImpl(com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl) Chunk1_18Type(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type) ChunkLightStorage(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) ArrayList(java.util.ArrayList) List(java.util.List) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 100 with PacketRemapper

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

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    // clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing
    PacketHandler cursorRemapper = wrapper -> {
        PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT);
        clearPacket.write(Type.UNSIGNED_BYTE, (short) -1);
        clearPacket.write(Type.SHORT, (short) -1);
        clearPacket.write(Type.FLAT_VAR_INT_ITEM, null);
        clearPacket.send(Protocol1_16To1_15_2.class);
    };
    protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.VAR_INT);
            // Window Type
            map(Type.VAR_INT);
            // Window Title
            map(Type.COMPONENT);
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                int windowId = wrapper.get(Type.VAR_INT, 0);
                int windowType = wrapper.get(Type.VAR_INT, 1);
                if (windowType >= 20) {
                    // smithing added with id 20
                    wrapper.set(Type.VAR_INT, 1, ++windowType);
                }
                inventoryTracker.setInventory((short) windowId);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.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 added with id 11
                        wrapper.set(Type.SHORT, 1, ++enchantmentId);
                    }
                }
            });
        }
    });
    registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
    registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            handler(wrapper -> {
                int slot = wrapper.read(Type.VAR_INT);
                wrapper.write(Type.BYTE, (byte) slot);
                handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
            });
        }
    });
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
    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.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) UUID(java.util.UUID) Item(com.viaversion.viaversion.api.minecraft.item.Item) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) 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) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16)

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