Search in sources :

Example 1 with Types1_17

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

the class EntityPackets1_17 method registerPackets.

@Override
protected void registerPackets() {
    registerTrackerWithData(ClientboundPackets1_17.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
    registerSpawnTracker(ClientboundPackets1_17.SPAWN_MOB);
    registerTracker(ClientboundPackets1_17.SPAWN_EXPERIENCE_ORB, Entity1_17Types.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_17Types.PAINTING);
    registerTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_17Types.PLAYER);
    registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_16.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_16_2.DESTROY_ENTITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int entityId = wrapper.read(Type.VAR_INT);
                tracker(wrapper.user()).removeEntity(entityId);
                // Write into single value array
                int[] array = { entityId };
                wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, array);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Hardcore
            map(Type.BOOLEAN);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            // Previous Gamemode
            map(Type.BYTE);
            // Worlds
            map(Type.STRING_ARRAY);
            // Dimension registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            handler(wrapper -> {
                byte previousGamemode = wrapper.get(Type.BYTE, 0);
                if (previousGamemode == -1) {
                    // "Unset" gamemode removed
                    wrapper.set(Type.BYTE, 0, (byte) 0);
                }
            });
            handler(getTrackerHandler(Entity1_17Types.PLAYER, Type.INT));
            handler(worldDataTrackerHandler(1));
            handler(wrapper -> {
                CompoundTag registry = wrapper.get(Type.NBT, 0);
                CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
                ListTag biomes = biomeRegistry.get("value");
                for (Tag biome : biomes) {
                    CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
                    StringTag category = biomeCompound.get("category");
                    if (category.getValue().equalsIgnoreCase("underground")) {
                        category.setValue("none");
                    }
                }
                CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type");
                ListTag dimensions = dimensionRegistry.get("value");
                for (Tag dimension : dimensions) {
                    CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
                    reduceExtendedHeight(dimensionCompound, false);
                }
                reduceExtendedHeight(wrapper.get(Type.NBT, 1), true);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            handler(worldDataTrackerHandler(0));
            handler(wrapper -> reduceExtendedHeight(wrapper.get(Type.NBT, 0), true));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17.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.read(Type.BOOLEAN);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(wrapper -> {
                // Collection length
                wrapper.write(Type.INT, wrapper.read(Type.VAR_INT));
            });
        }
    });
    // TODO translatables
    protocol.mergePacket(ClientboundPackets1_17.COMBAT_ENTER, ClientboundPackets1_16_2.COMBAT_EVENT, 0);
    protocol.mergePacket(ClientboundPackets1_17.COMBAT_END, ClientboundPackets1_16_2.COMBAT_EVENT, 1);
    protocol.mergePacket(ClientboundPackets1_17.COMBAT_KILL, ClientboundPackets1_16_2.COMBAT_EVENT, 2);
}
Also used : ClientboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17) Particle(com.viaversion.viaversion.api.type.types.Particle) Protocol1_16_4To1_17(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) 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) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 2 with Types1_17

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

the class EntityPackets1_18 method registerPackets.

@Override
protected void registerPackets() {
    registerMetadataRewriter(ClientboundPackets1_18.ENTITY_METADATA, Types1_18.METADATA_LIST, Types1_17.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_18.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Hardcore
            map(Type.BOOLEAN);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            // Previous Gamemode
            map(Type.BYTE);
            // Worlds
            map(Type.STRING_ARRAY);
            // Dimension registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.VAR_INT);
            // Chunk radius
            map(Type.VAR_INT);
            // Read simulation distance
            read(Type.VAR_INT);
            handler(worldDataTrackerHandler(1));
            handler(wrapper -> {
                final CompoundTag registry = wrapper.get(Type.NBT, 0);
                final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
                final ListTag biomes = biomeRegistry.get("value");
                for (final Tag biome : biomes.getValue()) {
                    final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
                    final StringTag category = biomeCompound.get("category");
                    if (category.getValue().equals("mountain")) {
                        category.setValue("extreme_hills");
                    }
                    // The client just needs something
                    biomeCompound.put("depth", new FloatTag(0.125F));
                    biomeCompound.put("scale", new FloatTag(0.05F));
                }
                // Track amount of biomes sent
                tracker(wrapper.user()).setBiomesSent(biomes.size());
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            handler(worldDataTrackerHandler(0));
        }
    });
}
Also used : Particle(com.viaversion.viaversion.api.type.types.Particle) ClientboundPackets1_18(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) Types1_17(com.viaversion.viaversion.api.type.types.version.Types1_17) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Types1_18(com.viaversion.viaversion.api.type.types.version.Types1_18) Entity1_17Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types) Protocol1_17_1To1_18(com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) EntityRewriter(com.viaversion.viabackwards.api.rewriters.EntityRewriter) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) FloatTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 3 with Types1_17

use of com.viaversion.viaversion.api.type.types.version.Types1_17 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)

Example 4 with Types1_17

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

the class EntityPackets method registerPackets.

@Override
public void registerPackets() {
    registerMetadataRewriter(ClientboundPackets1_17_1.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_18.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_17_1.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Hardcore
            map(Type.BOOLEAN);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            // Previous Gamemode
            map(Type.BYTE);
            // World List
            map(Type.STRING_ARRAY);
            // Registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            // World
            map(Type.STRING);
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.VAR_INT);
            handler(wrapper -> {
                int chunkRadius = wrapper.passthrough(Type.VAR_INT);
                // Simulation distance
                wrapper.write(Type.VAR_INT, chunkRadius);
            });
            handler(worldDataTrackerHandler(1));
            handler(biomeSizeTracker());
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.RESPAWN, new PacketRemapper() {

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

Aggregations

Entity1_17Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types)4 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)4 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 Type (com.viaversion.viaversion.api.type.Type)4 Types1_17 (com.viaversion.viaversion.api.type.types.version.Types1_17)4 Particle (com.viaversion.viaversion.api.type.types.Particle)3 EntityRewriter (com.viaversion.viabackwards.api.rewriters.EntityRewriter)2 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)2 Entity1_16_2Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types)2 MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)2 Types1_16 (com.viaversion.viaversion.api.type.types.version.Types1_16)2 Types1_18 (com.viaversion.viaversion.api.type.types.version.Types1_18)2 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)2 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)2 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)2 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)2 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)2 ClientboundPackets1_17 (com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17)2 EntityRewriter (com.viaversion.viaversion.rewriter.EntityRewriter)2 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)1