Search in sources :

Example 6 with Types1_16

use of com.viaversion.viaversion.api.type.types.version.Types1_16 in project ViaVersion by ViaVersion.

the class EntityPackets method registerPackets.

@Override
public void registerPackets() {
    registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
    registerTracker(ClientboundPackets1_16_2.SPAWN_MOB);
    registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_17Types.PLAYER);
    registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_16.METADATA_LIST, Types1_17.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_16_2.DESTROY_ENTITIES, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
                wrapper.cancel();
                EntityTracker entityTracker = wrapper.user().getEntityTracker(Protocol1_17To1_16_4.class);
                for (int entityId : entityIds) {
                    entityTracker.removeEntity(entityId);
                    // Send individual remove packets
                    PacketWrapper newPacket = wrapper.create(ClientboundPackets1_17.REMOVE_ENTITY);
                    newPacket.write(Type.VAR_INT, entityId);
                    newPacket.send(Protocol1_17To1_16_4.class);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(wrapper -> {
                // Collection length is now a var int
                wrapper.write(Type.VAR_INT, wrapper.read(Type.INT));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.PLAYER_POSITION, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            map(Type.DOUBLE);
            map(Type.FLOAT);
            map(Type.FLOAT);
            map(Type.BYTE);
            map(Type.VAR_INT);
            handler(wrapper -> {
                // Dismount vehicle
                wrapper.write(Type.BOOLEAN, false);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_16_2.COMBAT_EVENT, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Combat packet actions have been split into individual packets (the content hasn't changed)
                int type = wrapper.read(Type.VAR_INT);
                ClientboundPacketType packetType;
                switch(type) {
                    case 0:
                        packetType = ClientboundPackets1_17.COMBAT_ENTER;
                        break;
                    case 1:
                        packetType = ClientboundPackets1_17.COMBAT_END;
                        break;
                    case 2:
                        packetType = ClientboundPackets1_17.COMBAT_KILL;
                        break;
                    default:
                        throw new IllegalArgumentException("Invalid combat type received: " + type);
                }
                wrapper.setId(packetType.getId());
            });
        }
    });
    // The parent class of the other entity move packets that is never actually used has finally been removed from the id list
    protocol.cancelClientbound(ClientboundPackets1_16_2.ENTITY_MOVEMENT);
}
Also used : ClientboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17) EntityRewriter(com.viaversion.viaversion.rewriter.EntityRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) 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) Entity1_16_2Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types) Types1_16(com.viaversion.viaversion.api.type.types.version.Types1_16) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) ClientboundPacketType(com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Protocol1_17To1_16_4(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4) Type(com.viaversion.viaversion.api.type.Type) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) Protocol1_17To1_16_4(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPacketType(com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)6 Type (com.viaversion.viaversion.api.type.Type)6 Types1_16 (com.viaversion.viaversion.api.type.types.version.Types1_16)6 Entity1_16_2Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types)4 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)4 EntityRewriter (com.viaversion.viabackwards.api.rewriters.EntityRewriter)3 Via (com.viaversion.viaversion.api.Via)3 Entity1_16Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types)3 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)3 ClientboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 Entity1_17Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types)2 MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)2 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)2 Particle (com.viaversion.viaversion.api.type.types.Particle)2 Types1_14 (com.viaversion.viaversion.api.type.types.version.Types1_14)2 Types1_17 (com.viaversion.viaversion.api.type.types.version.Types1_17)2 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)2 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)2 ClientboundPackets1_15 (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15)2