Search in sources :

Example 1 with ClientboundPackets1_12

use of com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12 in project ViaBackwards by ViaVersion.

the class EntityPackets1_12 method registerPackets.

@Override
protected void registerPackets() {
    protocol.registerClientbound(ClientboundPackets1_12.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_12Types.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_12.SPAWN_EXPERIENCE_ORB, Entity1_12Types.EntityType.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_12.SPAWN_GLOBAL_ENTITY, Entity1_12Types.EntityType.WEATHER);
    protocol.registerClientbound(ClientboundPackets1_12.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);
            // 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 entity
            handler(getTrackerHandler());
            // Rewrite entity type / metadata
            handler(getMobSpawnRewriter(Types1_12.METADATA_LIST));
        }
    });
    registerTracker(ClientboundPackets1_12.SPAWN_PAINTING, Entity1_12Types.EntityType.PAINTING);
    protocol.registerClientbound(ClientboundPackets1_12.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_12.METADATA_LIST);
            handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, Entity1_12Types.EntityType.PLAYER));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_12.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_12Types.EntityType.PLAYER, Type.INT));
            handler(getDimensionHandler(1));
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class);
                    tracker.setEntityId(wrapper.get(Type.INT, 0));
                }
            });
            // Send fake inventory achievement
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper packetWrapper) throws Exception {
                    PacketWrapper wrapper = PacketWrapper.create(0x07, null, packetWrapper.user());
                    wrapper.write(Type.VAR_INT, 1);
                    wrapper.write(Type.STRING, "achievement.openInventory");
                    wrapper.write(Type.VAR_INT, 1);
                    wrapper.scheduleSend(Protocol1_11_1To1_12.class);
                }
            });
        }
    });
    registerRespawn(ClientboundPackets1_12.RESPAWN);
    registerRemoveEntities(ClientboundPackets1_12.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_12.ENTITY_METADATA, Types1_12.METADATA_LIST);
    protocol.registerClientbound(ClientboundPackets1_12.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.INT);
            handler(wrapper -> {
                int size = wrapper.get(Type.INT, 0);
                int newSize = size;
                for (int i = 0; i < size; i++) {
                    String key = wrapper.read(Type.STRING);
                    // Remove new attribute
                    if (key.equals("generic.flyingSpeed")) {
                        newSize--;
                        wrapper.read(Type.DOUBLE);
                        int modSize = wrapper.read(Type.VAR_INT);
                        for (int j = 0; j < modSize; j++) {
                            wrapper.read(Type.UUID);
                            wrapper.read(Type.DOUBLE);
                            wrapper.read(Type.BYTE);
                        }
                    } else {
                        wrapper.write(Type.STRING, key);
                        wrapper.passthrough(Type.DOUBLE);
                        int modSize = wrapper.passthrough(Type.VAR_INT);
                        for (int j = 0; j < modSize; j++) {
                            wrapper.passthrough(Type.UUID);
                            wrapper.passthrough(Type.DOUBLE);
                            wrapper.passthrough(Type.BYTE);
                        }
                    }
                }
                if (newSize != size) {
                    wrapper.set(Type.INT, 0, newSize);
                }
            });
        }
    });
}
Also used : ShoulderTracker(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker) 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) ClientboundPackets1_12(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12) ParrotStorage(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) Block(com.viaversion.viabackwards.utils.Block) Types1_12(com.viaversion.viaversion.api.type.types.version.Types1_12) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) StoredEntityData(com.viaversion.viaversion.api.data.entity.StoredEntityData) MetaType1_12(com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) Optional(java.util.Optional) ShoulderTracker(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker) Protocol1_11_1To1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Block(com.viaversion.viabackwards.utils.Block)

Example 2 with ClientboundPackets1_12

use of com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12 in project ViaBackwards by ViaVersion.

the class Protocol1_11_1To1_12 method registerPackets.

@Override
protected void registerPackets() {
    blockItemPackets.register();
    entityPackets.register();
    new SoundPackets1_12(this).register();
    new ChatPackets1_12(this).register();
    registerClientbound(ClientboundPackets1_12.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action >= 0 && action <= 2) {
                    JsonElement component = wrapper.read(Type.COMPONENT);
                    wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(component.toString()));
                }
            });
        }
    });
    cancelClientbound(ClientboundPackets1_12.ADVANCEMENTS);
    cancelClientbound(ClientboundPackets1_12.UNLOCK_RECIPES);
    cancelClientbound(ClientboundPackets1_12.SELECT_ADVANCEMENTS_TAB);
}
Also used : Entity1_12Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types) ServerboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3) ServerboundPackets1_12(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) ClientboundPackets1_12(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) EntityPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.EntityPackets1_12) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) ChatPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPackets1_12) BlockItemPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.BlockItemPackets1_12) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) SoundPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) ShoulderTracker(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12) ChatPackets1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPackets1_12)

Aggregations

ShoulderTracker (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker)2 Entity1_12Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types)2 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)2 Type (com.viaversion.viaversion.api.type.Type)2 ClientboundPackets1_12 (com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12)2 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)1 BackwardsMappings (com.viaversion.viabackwards.api.data.BackwardsMappings)1 LegacyEntityRewriter (com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter)1 Protocol1_11_1To1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12)1 ParrotStorage (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage)1 BlockItemPackets1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.BlockItemPackets1_12)1 ChatPackets1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPackets1_12)1 EntityPackets1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.EntityPackets1_12)1 SoundPackets1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12)1 Block (com.viaversion.viabackwards.utils.Block)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)1 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)1 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)1 MetaType1_12 (com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12)1