Search in sources :

Example 1 with ClientboundPackets1_9_3

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

the class BlockItemPackets1_10 method registerPackets.

@Override
protected void registerPackets() {
    registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
    registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
    // Entity Equipment Packet
    registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
    protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
                        // Passthrough Window ID
                        wrapper.passthrough(Type.INT);
                        int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                        for (int i = 0; i < size; i++) {
                            // Input Item
                            wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            // Output Item
                            wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            // Has second item
                            boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
                            if (secondItem) {
                                // Second Item
                                wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            }
                            // Trade disabled
                            wrapper.passthrough(Type.BOOLEAN);
                            // Number of tools uses
                            wrapper.passthrough(Type.INT);
                            // Maximum number of trade uses
                            wrapper.passthrough(Type.INT);
                        }
                    }
                }
            });
        }
    });
    registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
    registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
    protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
                    Chunk chunk = wrapper.passthrough(type);
                    handleChunk(chunk);
                }
            });
        }
    });
    // Block Change Packet
    protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Block Position
            map(Type.POSITION);
            // 1 - Block
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int idx = wrapper.get(Type.VAR_INT, 0);
                    wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
                }
            });
        }
    });
    // Multi Block Change Packet
    protocol.registerClientbound(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Chunk X
            map(Type.INT);
            // 1 - Chunk Z
            map(Type.INT);
            map(Type.BLOCK_CHANGE_RECORD_ARRAY);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
                        record.setBlockId(handleBlockID(record.getBlockId()));
                    }
                }
            });
        }
    });
    // Rewrite metadata items
    protocol.getEntityRewriter().filter().handler((event, meta) -> {
        if (// Is Item
        meta.metaType().type().equals(Type.ITEM))
            meta.setValue(handleItemToClient((Item) meta.getValue()));
    });
    // Particle
    protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PARTICLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.INT);
            map(Type.BOOLEAN);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 46) {
                        // new falling_dust
                        // -> block_dust
                        wrapper.set(Type.INT, 0, 38);
                    }
                }
            });
        }
    });
}
Also used : BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type)

Example 2 with ClientboundPackets1_9_3

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

the class BlockItemPackets1_11 method registerPackets.

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

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Slot ID
            map(Type.SHORT);
            // 2 - Slot Value
            map(Type.ITEM);
            handler(itemToClientHandler(Type.ITEM));
            // Handle Llama
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (isLlama(wrapper.user())) {
                        Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
                        if (!horse.isPresent())
                            return;
                        ChestedHorseStorage storage = horse.get();
                        int currentSlot = wrapper.get(Type.SHORT, 0);
                        wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
                        wrapper.set(Type.ITEM, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM, 0)));
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.WINDOW_ITEMS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Window Values
            map(Type.ITEM_ARRAY);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
                    for (int i = 0; i < stacks.length; i++) stacks[i] = handleItemToClient(stacks[i]);
                    if (isLlama(wrapper.user())) {
                        Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
                        if (!horse.isPresent())
                            return;
                        ChestedHorseStorage storage = horse.get();
                        stacks = Arrays.copyOf(stacks, !storage.isChested() ? 38 : 53);
                        for (int i = stacks.length - 1; i >= 0; i--) {
                            stacks[getNewSlotId(storage, i)] = stacks[i];
                            stacks[i] = getNewItem(storage, i, stacks[i]);
                        }
                        wrapper.set(Type.ITEM_ARRAY, 0, stacks);
                    }
                }
            });
        }
    });
    registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
    // Plugin message Packet -> Trading
    protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
                        // Passthrough Window ID
                        wrapper.passthrough(Type.INT);
                        int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                        for (int i = 0; i < size; i++) {
                            // Input Item
                            wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            // Output Item
                            wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            // Has second item
                            boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
                            if (secondItem) {
                                // Second Item
                                wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM)));
                            }
                            // Trade disabled
                            wrapper.passthrough(Type.BOOLEAN);
                            // Number of tools uses
                            wrapper.passthrough(Type.INT);
                            // Maximum number of trade uses
                            wrapper.passthrough(Type.INT);
                        }
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9_3.CLICK_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Slot
            map(Type.SHORT);
            // 2 - Button
            map(Type.BYTE);
            // 3 - Action number
            map(Type.SHORT);
            // 4 - Mode
            map(Type.VAR_INT);
            // 5 - Clicked Item
            map(Type.ITEM);
            handler(itemToServerHandler(Type.ITEM));
            // Llama slot
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (isLlama(wrapper.user())) {
                        Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
                        if (!horse.isPresent())
                            return;
                        ChestedHorseStorage storage = horse.get();
                        int clickSlot = wrapper.get(Type.SHORT, 0);
                        int correctSlot = getOldSlotId(storage, clickSlot);
                        wrapper.set(Type.SHORT, 0, ((Integer) correctSlot).shortValue());
                    }
                }
            });
        }
    });
    registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
    protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    // Use the 1.10 Chunk type since nothing changed.
                    Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
                    Chunk chunk = wrapper.passthrough(type);
                    handleChunk(chunk);
                    // only patch it for signs for now
                    for (CompoundTag tag : chunk.getBlockEntities()) {
                        Tag idTag = tag.get("id");
                        if (!(idTag instanceof StringTag))
                            continue;
                        String id = (String) idTag.getValue();
                        if (id.equals("minecraft:sign")) {
                            ((StringTag) idTag).setValue("Sign");
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Block Position
            map(Type.POSITION);
            // 1 - Block
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int idx = wrapper.get(Type.VAR_INT, 0);
                    wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Chunk X
            map(Type.INT);
            // 1 - Chunk Z
            map(Type.INT);
            map(Type.BLOCK_CHANGE_RECORD_ARRAY);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
                        record.setBlockId(handleBlockID(record.getBlockId()));
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // Remove on shulkerbox decleration
                    if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 10) {
                        wrapper.cancel();
                    }
                    // Handler Spawners
                    if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) {
                        CompoundTag tag = wrapper.get(Type.NBT, 0);
                        EntityIdRewriter.toClientSpawner(tag, true);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Window Type
            map(Type.STRING);
            // 2 - Title
            map(Type.COMPONENT);
            // 3 - Slots
            map(Type.UNSIGNED_BYTE);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityId = -1;
                    // Passthrough Entity ID
                    if (wrapper.get(Type.STRING, 0).equals("EntityHorse")) {
                        entityId = wrapper.passthrough(Type.INT);
                    }
                    // Track Inventory
                    String inventory = wrapper.get(Type.STRING, 0);
                    WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
                    windowTracker.setInventory(inventory);
                    windowTracker.setEntityId(entityId);
                    // Change llama slotcount to the donkey one
                    if (isLlama(wrapper.user())) {
                        wrapper.set(Type.UNSIGNED_BYTE, 1, (short) 17);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Inventory tracking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
                    windowTracker.setInventory(null);
                    windowTracker.setEntityId(-1);
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9_3.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Inventory tracking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
                    windowTracker.setInventory(null);
                    windowTracker.setEntityId(-1);
                }
            });
        }
    });
    protocol.getEntityRewriter().filter().handler((event, meta) -> {
        if (// Is Item
        meta.metaType().type().equals(Type.ITEM))
            meta.setValue(handleItemToClient((Item) meta.getValue()));
    });
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) WindowTracker(com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) ChestedHorseStorage(com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) Item(com.viaversion.viaversion.api.minecraft.item.Item) MappedLegacyBlockItem(com.viaversion.viabackwards.api.data.MappedLegacyBlockItem) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) BlockChangeRecord(com.viaversion.viaversion.api.minecraft.BlockChangeRecord) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 3 with ClientboundPackets1_9_3

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

the class EntityPackets1_11 method registerPackets.

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

        @Override
        public void registerMap() {
            map(Type.INT);
            map(Type.POSITION);
            map(Type.INT);
            handler(wrapper -> {
                int type = wrapper.get(Type.INT, 0);
                if (type == 2002 || type == 2007) {
                    // 2007 potion id doesn't exist in 1.10
                    if (type == 2007) {
                        wrapper.set(Type.INT, 0, 2002);
                    }
                    int mappedData = PotionSplashHandler.getOldData(wrapper.get(Type.INT, 1));
                    if (mappedData != -1) {
                        wrapper.set(Type.INT, 1, mappedData);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.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);
            // Track Entity
            handler(getObjectTrackerHandler());
            handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
            // Handle FallingBlock blocks
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Optional<Entity1_12Types.ObjectType> type = Entity1_12Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
                    if (type.isPresent() && type.get() == Entity1_12Types.ObjectType.FALLING_BLOCK) {
                        int objectData = wrapper.get(Type.INT, 0);
                        int objType = objectData & 4095;
                        int data = objectData >> 12 & 15;
                        Block block = protocol.getItemRewriter().handleBlock(objType, data);
                        if (block == null)
                            return;
                        wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
                    }
                }
            });
        }
    });
    registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
    protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // 1 - UUID
            map(Type.UUID);
            // 2 - Entity Type
            map(Type.VAR_INT, Type.UNSIGNED_BYTE);
            // 3 - X
            map(Type.DOUBLE);
            // 4 - Y
            map(Type.DOUBLE);
            // 5 - Z
            map(Type.DOUBLE);
            // 6 - Yaw
            map(Type.BYTE);
            // 7 - Pitch
            map(Type.BYTE);
            // 8 - Head Pitch
            map(Type.BYTE);
            // 9 - Velocity X
            map(Type.SHORT);
            // 10 - Velocity Y
            map(Type.SHORT);
            // 11 - Velocity Z
            map(Type.SHORT);
            // 12 - Metadata
            map(Types1_9.METADATA_LIST);
            // Track entity
            handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
            // Rewrite entity type / metadata
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                EntityType type = tracker(wrapper.user()).entityType(entityId);
                List<Metadata> list = wrapper.get(Types1_9.METADATA_LIST, 0);
                handleMetadata(wrapper.get(Type.VAR_INT, 0), list, wrapper.user());
                EntityData entityData = entityDataForType(type);
                if (entityData != null) {
                    wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
                    if (entityData.hasBaseMeta()) {
                        entityData.defaultMeta().createMeta(new WrappedMetadata(list));
                    }
                }
                // Sub 1.11 clients will error if the list is empty
                if (list.isEmpty()) {
                    list.add(new Metadata(0, MetaType1_9.Byte, (byte) 0));
                }
            });
        }
    });
    registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
    registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_11Types.EntityType.PLAYER);
    registerRespawn(ClientboundPackets1_9_3.RESPAWN);
    protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Player UUID
            map(Type.UUID);
            // 2 - X
            map(Type.DOUBLE);
            // 3 - Y
            map(Type.DOUBLE);
            // 4 - Z
            map(Type.DOUBLE);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - Pitch
            map(Type.BYTE);
            // 7 - Metadata list
            map(Types1_9.METADATA_LIST);
            handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
            handler(wrapper -> {
                // Sub 1.11 clients will cry if the list is empty
                List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
                if (metadata.isEmpty()) {
                    metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0));
                }
            });
        }
    });
    registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_9_3.ENTITY_STATUS, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    byte b = wrapper.get(Type.BYTE, 0);
                    if (b == 35) {
                        wrapper.clearPacket();
                        // Change Game State
                        wrapper.setId(0x1E);
                        // Play Elder Guardian animation
                        wrapper.write(Type.UNSIGNED_BYTE, (short) 10);
                        wrapper.write(Type.FLOAT, 0F);
                    }
                }
            });
        }
    });
}
Also used : EntityData(com.viaversion.viabackwards.api.entities.storage.EntityData) Entity1_12Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) LegacyEntityRewriter(com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter) WrappedMetadata(com.viaversion.viabackwards.api.entities.storage.WrappedMetadata) ChestedHorseStorage(com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage) PotionSplashHandler(com.viaversion.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) MetaType1_9(com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9) Block(com.viaversion.viabackwards.utils.Block) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) List(java.util.List) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) Types1_9(com.viaversion.viaversion.api.type.types.version.Types1_9) Optional(java.util.Optional) Entity1_11Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) Protocol1_10To1_11(com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) EntityData(com.viaversion.viabackwards.api.entities.storage.EntityData) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) WrappedMetadata(com.viaversion.viabackwards.api.entities.storage.WrappedMetadata) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) WrappedMetadata(com.viaversion.viabackwards.api.entities.storage.WrappedMetadata) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Block(com.viaversion.viabackwards.utils.Block) List(java.util.List)

Example 4 with ClientboundPackets1_9_3

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

the class Protocol1_11To1_10 method registerPackets.

@Override
protected void registerPackets() {
    entityRewriter.register();
    itemRewriter.register();
    registerClientbound(ClientboundPackets1_9_3.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);
            // Track Entity
            handler(entityRewriter.objectTrackerHandler());
        }
    });
    registerClientbound(ClientboundPackets1_9_3.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.UNSIGNED_BYTE, 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_9.METADATA_LIST);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    // Change Type :)
                    int type = wrapper.get(Type.VAR_INT, 1);
                    Entity1_11Types.EntityType entType = MetadataRewriter1_11To1_10.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
                    if (entType != null) {
                        wrapper.set(Type.VAR_INT, 1, entType.getId());
                        // Register Type ID
                        wrapper.user().getEntityTracker(Protocol1_11To1_10.class).addEntity(entityId, entType);
                        entityRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
                    }
                }
            });
        }
    });
    new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
    registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Collected entity id
            map(Type.VAR_INT);
            // 1 - Collector entity id
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // 2 - Pickup Count
                    wrapper.write(Type.VAR_INT, 1);
                }
            });
        }
    });
    entityRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
    registerClientbound(ClientboundPackets1_9_3.ENTITY_TELEPORT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // 1 - x
            map(Type.DOUBLE);
            // 2 - y
            map(Type.DOUBLE);
            // 3 - z
            map(Type.DOUBLE);
            // 4 - yaw
            map(Type.BYTE);
            // 5 - pitch
            map(Type.BYTE);
            // 6 - onGround
            map(Type.BOOLEAN);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    if (Via.getConfig().isHologramPatch()) {
                        EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_11To1_10.class);
                        if (tracker.isHologram(entityID)) {
                            Double newValue = wrapper.get(Type.DOUBLE, 1);
                            newValue -= (Via.getConfig().getHologramYOffset());
                            wrapper.set(Type.DOUBLE, 1, newValue);
                        }
                    }
                }
            });
        }
    });
    entityRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
    registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int action = wrapper.get(Type.VAR_INT, 0);
                    // Handle the new ActionBar
                    if (action >= 2) {
                        wrapper.set(Type.VAR_INT, 0, action + 1);
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.BLOCK_ACTION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Position
            map(Type.POSITION);
            // 1 - Action ID
            map(Type.UNSIGNED_BYTE);
            // 2 - Action Param
            map(Type.UNSIGNED_BYTE);
            // 3 - Block Type
            map(Type.VAR_INT);
            // Cheap hack to ensure it's always right block
            handler(new PacketHandler() {

                @Override
                public void handle(final PacketWrapper actionWrapper) throws Exception {
                    if (Via.getConfig().isPistonAnimationPatch()) {
                        int id = actionWrapper.get(Type.VAR_INT, 0);
                        if (id == 33 || id == 29) {
                            actionWrapper.cancel();
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Position
            map(Type.POSITION);
            // 1 - Action
            map(Type.UNSIGNED_BYTE);
            // 2 - NBT data
            map(Type.NBT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    CompoundTag tag = wrapper.get(Type.NBT, 0);
                    if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
                        EntityIdRewriter.toClientSpawner(tag);
                    if (tag.contains("id"))
                        // Handle new identifier
                        ((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk chunk = wrapper.passthrough(new Chunk1_9_3_4Type(clientWorld));
                    if (chunk.getBlockEntities() == null)
                        return;
                    for (CompoundTag tag : chunk.getBlockEntities()) {
                        if (tag.contains("id")) {
                            String identifier = ((StringTag) tag.get("id")).getValue();
                            if (identifier.equals("MobSpawner")) {
                                EntityIdRewriter.toClientSpawner(tag);
                            }
                            // Handle new identifier
                            ((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.INT);
            // 1 - Gamemode
            map(Type.UNSIGNED_BYTE);
            // 2 - Dimension
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.INT, 1);
                clientChunks.setEnvironment(dimensionId);
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.INT, 0);
                clientWorld.setEnvironment(dimensionId);
            });
        }
    });
    this.registerClientbound(ClientboundPackets1_9_3.EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // effectID
            this.map(Type.INT);
            // pos
            this.map(Type.POSITION);
            // effectData
            this.map(Type.INT);
            // serverwide / global
            this.map(Type.BOOLEAN);
            handler(packetWrapper -> {
                int effectID = packetWrapper.get(Type.INT, 0);
                if (effectID == 2002) {
                    int data = packetWrapper.get(Type.INT, 1);
                    boolean isInstant = false;
                    Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data);
                    if (newData == null) {
                        Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
                        data = 0;
                    } else {
                        data = newData.key();
                        isInstant = newData.value();
                    }
                    if (isInstant) {
                        packetWrapper.set(Type.INT, 0, 2007);
                    }
                    packetWrapper.set(Type.INT, 1, data);
                }
            });
        }
    });
    /*
            INCOMING PACKETS
        */
    registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Location
            map(Type.POSITION);
            // 1 - Face
            map(Type.VAR_INT);
            // 2 - Hand
            map(Type.VAR_INT);
            map(Type.FLOAT, toOldByte);
            map(Type.FLOAT, toOldByte);
            map(Type.FLOAT, toOldByte);
        }
    });
    registerServerbound(ServerboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // 100 character limit on older servers
                    String msg = wrapper.get(Type.STRING, 0);
                    if (msg.length() > 100) {
                        wrapper.set(Type.STRING, 0, msg.substring(0, 100));
                    }
                }
            });
        }
    });
}
Also used : EntityTracker1_11(com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) ServerboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) MetadataRewriter1_11To1_10(com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10) Via(com.viaversion.viaversion.api.Via) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Types1_9(com.viaversion.viaversion.api.type.types.version.Types1_9) PotionColorMapping(com.viaversion.viaversion.protocols.protocol1_11to1_10.data.PotionColorMapping) Pair(com.viaversion.viaversion.util.Pair) EntityTracker1_11(com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11) Entity1_11Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_11to1_10.packets.InventoryPackets) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) Entity1_11Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) Pair(com.viaversion.viaversion.util.Pair)

Example 5 with ClientboundPackets1_9_3

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

the class Protocol1_12To1_11_1 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    registerClientbound(ClientboundPackets1_9_3.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);
            // Track Entity
            handler(metadataRewriter.objectTrackerHandler());
        }
    });
    registerClientbound(ClientboundPackets1_9_3.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_12.METADATA_LIST);
            // Track mob and rewrite metadata
            handler(metadataRewriter.trackerAndRewriterHandler(Types1_12.METADATA_LIST));
        }
    });
    registerClientbound(ClientboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (!Via.getConfig().is1_12NBTArrayFix())
                        return;
                    try {
                        JsonElement obj = Protocol1_9To1_8.FIX_JSON.transform(null, wrapper.passthrough(Type.COMPONENT).toString());
                        TranslateRewriter.toClient(obj, wrapper.user());
                        ChatItemRewriter.toClient(obj, wrapper.user());
                        wrapper.set(Type.COMPONENT, 0, obj);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
                    Chunk chunk = wrapper.passthrough(type);
                    for (int i = 0; i < chunk.getSections().length; i++) {
                        ChunkSection section = chunk.getSections()[i];
                        if (section == null)
                            continue;
                        for (int y = 0; y < 16; y++) {
                            for (int z = 0; z < 16; z++) {
                                for (int x = 0; x < 16; x++) {
                                    int block = section.getBlockWithoutData(x, y, z);
                                    // Is this a bed?
                                    if (block == 26) {
                                        // NBT -> { color:14, x:132, y:64, z:222, id:"minecraft:bed" } (Debug output)
                                        CompoundTag tag = new CompoundTag();
                                        // Set color to red (Default in previous versions)
                                        tag.put("color", new IntTag(14));
                                        tag.put("x", new IntTag(x + (chunk.getX() << 4)));
                                        tag.put("y", new IntTag(y + (i << 4)));
                                        tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
                                        tag.put("id", new StringTag("minecraft:bed"));
                                        // Add a fake block entity
                                        chunk.getBlockEntities().add(tag);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
    });
    metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
    metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST);
    registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.INT);
            map(Type.UNSIGNED_BYTE);
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.INT, 1);
                clientChunks.setEnvironment(dimensionId);
            });
        }
    });
    registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.INT, 0);
                clientWorld.setEnvironment(dimensionId);
            });
        }
    });
    new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
    // New packet at 0x01
    cancelServerbound(ServerboundPackets1_12.PREPARE_CRAFTING_GRID);
    // Client Settings (max length changed)
    registerServerbound(ServerboundPackets1_12.CLIENT_SETTINGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Locale
            map(Type.STRING);
            // 1 - view distance
            map(Type.BYTE);
            // 2 - chat mode
            map(Type.VAR_INT);
            // 3 - chat colors
            map(Type.BOOLEAN);
            // 4 - chat flags
            map(Type.UNSIGNED_BYTE);
            // 5 - main hand
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // As part of the fix for MC-111054, the max length of
                    // the locale was raised to 16 (from 7), and the client
                    // now makes sure that resource packs have names in that
                    // length.  However, for older servers, it is still 7,
                    // and thus the server will reject it (and the client
                    // won't know that the pack's invalid).
                    // The fix is to just silently lower the length.  The
                    // server doesn't actually use the locale anywhere, so
                    // this is fine.
                    String locale = wrapper.get(Type.STRING, 0);
                    if (locale.length() > 7) {
                        wrapper.set(Type.STRING, 0, locale.substring(0, 7));
                    }
                }
            });
        }
    });
    // New packet at 0x17
    cancelServerbound(ServerboundPackets1_12.RECIPE_BOOK_DATA);
    // New packet 0x19
    cancelServerbound(ServerboundPackets1_12.ADVANCEMENT_TAB);
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Types1_12(com.viaversion.viaversion.api.type.types.version.Types1_12) JsonElement(com.google.gson.JsonElement) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) MetadataRewriter1_12To1_11_1(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) Entity1_12Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) ServerboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3) ViaProviders(com.viaversion.viaversion.api.platform.providers.ViaProviders) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) InventoryPackets(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets.InventoryPackets) Via(com.viaversion.viaversion.api.Via) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) InventoryQuickMoveProvider(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Chunk1_9_3_4Type(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.google.gson.JsonElement) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag)

Aggregations

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