Search in sources :

Example 6 with ClientboundPackets1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 in project ViaVersion by ViaVersion.

the class EntityPackets method register.

public static void register(Protocol1_15To1_14_4 protocol) {
    MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
    metadataRewriter.registerTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
    protocol.registerClientbound(ClientboundPackets1_14.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);
            handler(metadataRewriter.trackerHandler());
            handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Type.VAR_INT, 0), metadataRewriter));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.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);
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class).addEntity(entityId, Entity1_15Types.PLAYER);
                sendMetadataPacket(wrapper, entityId, metadataRewriter);
            });
        }
    });
    metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
    metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) Type(com.viaversion.viaversion.api.type.Type) List(java.util.List) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4) Protocol1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4)

Example 7 with ClientboundPackets1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
    registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_14.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipment(ClientboundPackets1_14.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_14.DECLARE_RECIPES);
    registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
Also used : RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14)

Example 8 with ClientboundPackets1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 in project ViaVersion by ViaVersion.

the class Protocol1_15To1_14_4 method registerPackets.

@Override
protected void registerPackets() {
    metadataRewriter.register();
    itemRewriter.register();
    EntityPackets.register(this);
    PlayerPackets.register(this);
    WorldPackets.register(this);
    SoundRewriter soundRewriter = new SoundRewriter(this);
    // Entity Sound Effect (added somewhere in 1.14)
    soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND);
    soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
    new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
    registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> itemRewriter.handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    tagRewriter = new TagRewriter(this);
    tagRewriter.register(ClientboundPackets1_14.TAGS, RegistryType.ENTITY);
}
Also used : InventoryPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) SoundRewriter(com.viaversion.viaversion.rewriter.SoundRewriter) MappingData(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data.MappingData) MetadataRewriter1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4) EntityPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) Type(com.viaversion.viaversion.api.type.Type) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) PlayerPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets) WorldPackets(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets) 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 9 with ClientboundPackets1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 in project ViaBackwards by ViaVersion.

the class EntityPackets1_14 method registerPackets.

@Override
protected void registerPackets() {
    positionHandler = new EntityPositionHandler(this, EntityPositionStorage1_14.class, EntityPositionStorage1_14::new);
    protocol.registerClientbound(ClientboundPackets1_14.ENTITY_STATUS, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int entityId = wrapper.passthrough(Type.INT);
                byte status = wrapper.passthrough(Type.BYTE);
                // Check for death status
                if (status != 3)
                    return;
                EntityTracker tracker = tracker(wrapper.user());
                EntityType entityType = tracker.entityType(entityId);
                if (entityType != Entity1_14Types.PLAYER)
                    return;
                // Remove equipment, else the client will see ghost items
                for (int i = 0; i <= 5; i++) {
                    PacketWrapper equipmentPacket = wrapper.create(ClientboundPackets1_13.ENTITY_EQUIPMENT);
                    equipmentPacket.write(Type.VAR_INT, entityId);
                    equipmentPacket.write(Type.VAR_INT, i);
                    equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, null);
                    equipmentPacket.send(Protocol1_13_2To1_14.class);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.ENTITY_TELEPORT, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, false, false));
        }
    });
    PacketRemapper relativeMoveHandler = new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.SHORT);
            map(Type.SHORT);
            map(Type.SHORT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    double x = wrapper.get(Type.SHORT, 0) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
                    double y = wrapper.get(Type.SHORT, 1) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
                    double z = wrapper.get(Type.SHORT, 2) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
                    positionHandler.cacheEntityPosition(wrapper, x, y, z, false, true);
                }
            });
        }
    };
    protocol.registerClientbound(ClientboundPackets1_14.ENTITY_POSITION, relativeMoveHandler);
    protocol.registerClientbound(ClientboundPackets1_14.ENTITY_POSITION_AND_ROTATION, relativeMoveHandler);
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // 1 - UUID
            map(Type.UUID);
            // 2 - Type
            map(Type.VAR_INT, 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);
            // 9 - Velocity X
            map(Type.SHORT);
            // 10 - Velocity Y
            map(Type.SHORT);
            // 11 - Velocity Z
            map(Type.SHORT);
            handler(getObjectTrackerHandler());
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.BYTE, 0);
                    int mappedId = newEntityId(id);
                    Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(mappedId, false);
                    Entity1_13Types.ObjectType objectType;
                    if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) {
                        objectType = Entity1_13Types.ObjectType.MINECART;
                        int data = 0;
                        switch(entityType) {
                            case CHEST_MINECART:
                                data = 1;
                                break;
                            case FURNACE_MINECART:
                                data = 2;
                                break;
                            case TNT_MINECART:
                                data = 3;
                                break;
                            case SPAWNER_MINECART:
                                data = 4;
                                break;
                            case HOPPER_MINECART:
                                data = 5;
                                break;
                            case COMMAND_BLOCK_MINECART:
                                data = 6;
                                break;
                        }
                        if (data != 0)
                            wrapper.set(Type.INT, 0, data);
                    } else {
                        objectType = Entity1_13Types.ObjectType.fromEntityType(entityType).orElse(null);
                    }
                    if (objectType == null)
                        return;
                    wrapper.set(Type.BYTE, 0, (byte) objectType.getId());
                    int data = wrapper.get(Type.INT, 0);
                    if (objectType == Entity1_13Types.ObjectType.FALLING_BLOCK) {
                        int blockState = wrapper.get(Type.INT, 0);
                        int combined = protocol.getMappingData().getNewBlockStateId(blockState);
                        wrapper.set(Type.INT, 0, combined);
                    } else if (entityType.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW)) {
                        wrapper.set(Type.INT, 0, data + 1);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.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_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.get(Type.VAR_INT, 1);
                    EntityType entityType = Entity1_14Types.getTypeFromId(type);
                    addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
                    int oldId = newEntityId(type);
                    if (oldId == -1) {
                        EntityData entityData = entityDataForType(entityType);
                        if (entityData == null) {
                            ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType);
                            wrapper.cancel();
                        } else {
                            wrapper.set(Type.VAR_INT, 1, entityData.replacementId());
                        }
                    } else {
                        wrapper.set(Type.VAR_INT, 1, oldId);
                    }
                }
            });
            // Handle entity type & metadata
            handler(getMobSpawnRewriter(Types1_13_2.METADATA_LIST));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            // Needs to be mapped for the position cache
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EXPERIENCE_ORB));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity id
            map(Type.VAR_INT);
            map(Type.BYTE);
            // Needs to be mapped for the position cache
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.LIGHTNING_BOLT));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PAINTING, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.UUID);
            map(Type.VAR_INT);
            map(Type.POSITION1_14, Type.POSITION);
            map(Type.BYTE);
            // Track entity
            handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.PAINTING));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Player UUID
            map(Type.UUID);
            // 2 - X
            map(Type.DOUBLE);
            // 3 - Y
            map(Type.DOUBLE);
            // 4 - Z
            map(Type.DOUBLE);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - Pitch
            map(Type.BYTE);
            // 7 - Metadata
            map(Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
            handler(getTrackerAndMetaHandler(Types1_13_2.METADATA_LIST, Entity1_14Types.PLAYER));
            handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, true, false));
        }
    });
    registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_14.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(getTrackerHandler(Entity1_14Types.PLAYER, Type.INT));
            handler(getDimensionHandler(1));
            handler(wrapper -> {
                short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
                wrapper.write(Type.UNSIGNED_BYTE, difficulty);
                // Max Players
                wrapper.passthrough(Type.UNSIGNED_BYTE);
                // Level Type
                wrapper.passthrough(Type.STRING);
                // Read View Distance
                wrapper.read(Type.VAR_INT);
            // TODO Track client position
            // Manually add position storage
            /*int entitiyId = wrapper.get(Type.INT, 0);
                    StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
                    storedEntity.put(new EntityPositionStorage1_14());*/
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_14.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Dimension ID
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.INT, 0);
                clientWorld.setEnvironment(dimensionId);
                short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
                wrapper.write(Type.UNSIGNED_BYTE, difficulty);
                wrapper.user().get(ChunkLightStorage.class).clear();
            });
        }
    });
}
Also used : EntityPositionHandler(com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Entity1_13Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types) EntityPositionStorage1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14) Item(com.viaversion.viaversion.api.minecraft.item.Item) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ChunkLightStorage(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14) EntityData(com.viaversion.viabackwards.api.entities.storage.EntityData) Particle(com.viaversion.viaversion.api.type.types.Particle) LegacyEntityRewriter(com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter) Position(com.viaversion.viaversion.api.minecraft.Position) Types1_13_2(com.viaversion.viaversion.api.type.types.version.Types1_13_2) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) VillagerData(com.viaversion.viaversion.api.minecraft.VillagerData) EntityPositionHandler(com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler) ClientboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13) DifficultyStorage(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage) MetaHandler(com.viaversion.viaversion.rewriter.meta.MetaHandler) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) Entity1_14Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types) EntityPositionStorage1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) EntityData(com.viaversion.viabackwards.api.entities.storage.EntityData) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Entity1_13Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14)

Example 10 with ClientboundPackets1_14

use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 in project ViaBackwards by ViaVersion.

the class Protocol1_14_3To1_14_4 method registerPackets.

@Override
protected void registerPackets() {
    // Acknowledge Player Digging - added in pre4
    registerClientbound(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING, ClientboundPackets1_14.BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            map(Type.VAR_INT);
            handler(wrapper -> {
                int status = wrapper.read(Type.VAR_INT);
                boolean allGood = wrapper.read(Type.BOOLEAN);
                if (allGood && status == 0) {
                    wrapper.cancel();
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    wrapper.passthrough(Type.VAR_INT);
                    int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                    for (int i = 0; i < size; i++) {
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        if (wrapper.passthrough(Type.BOOLEAN)) {
                            wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        }
                        wrapper.passthrough(Type.BOOLEAN);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.FLOAT);
                        // demand value added in pre-5
                        wrapper.read(Type.INT);
                    }
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)13 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)12 Type (com.viaversion.viaversion.api.type.Type)11 ClientboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14)11 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)8 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)5 Protocol1_13_2To1_14 (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14)4 Entity1_15Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types)4 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)4 Protocol1_14To1_13_2 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2)4 ServerboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14)4 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)3 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)3 Via (com.viaversion.viaversion.api.Via)3 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)3 Position (com.viaversion.viaversion.api.minecraft.Position)3 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)3 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)3 Entity1_14Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types)3 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)3