Search in sources :

Example 1 with Block

use of com.viaversion.viabackwards.utils.Block in project ViaBackwards by ViaVersion.

the class EntityPackets1_10 method registerPackets.

@Override
protected void registerPackets() {
    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_10Types.EntityType.EXPERIENCE_ORB);
    registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_10Types.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.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(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    EntityType type = tracker(wrapper.user()).entityType(entityId);
                    List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
                    handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
                    EntityData entityData = entityDataForType(type);
                    if (entityData != null) {
                        WrappedMetadata storage = new WrappedMetadata(metadata);
                        wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
                        if (entityData.hasBaseMeta())
                            entityData.defaultMeta().createMeta(storage);
                    }
                }
            });
        }
    });
    registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_10Types.EntityType.PAINTING);
    registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_10Types.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));
        }
    });
    registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
    registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) WrappedMetadata(com.viaversion.viabackwards.api.entities.storage.WrappedMetadata) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) EntityData(com.viaversion.viabackwards.api.entities.storage.EntityData) 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)

Example 2 with Block

use of com.viaversion.viabackwards.utils.Block 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 3 with Block

use of com.viaversion.viabackwards.utils.Block 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 4 with Block

use of com.viaversion.viabackwards.utils.Block in project ViaBackwards by ViaVersion.

the class LegacyBlockItemRewriter method handleBlock.

@Nullable
public Block handleBlock(int blockId, int data) {
    MappedLegacyBlockItem settings = replacementData.get(blockId);
    if (settings == null || !settings.isBlock())
        return null;
    Block block = settings.getBlock();
    // For some blocks, the data can still be useful (:
    if (block.getData() == -1) {
        return block.withData(data);
    }
    return block;
}
Also used : MappedLegacyBlockItem(com.viaversion.viabackwards.api.data.MappedLegacyBlockItem) Block(com.viaversion.viabackwards.utils.Block) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 5 with Block

use of com.viaversion.viabackwards.utils.Block in project ViaBackwards by ViaVersion.

the class LegacyBlockItemRewriter method handleBlockID.

public int handleBlockID(int idx) {
    int type = idx >> 4;
    int meta = idx & 15;
    Block b = handleBlock(type, meta);
    if (b == null)
        return idx;
    return (b.getId() << 4 | (b.getData() & 15));
}
Also used : Block(com.viaversion.viabackwards.utils.Block)

Aggregations

Block (com.viaversion.viabackwards.utils.Block)6 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)3 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)3 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)3 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)3 MappedLegacyBlockItem (com.viaversion.viabackwards.api.data.MappedLegacyBlockItem)2 EntityData (com.viaversion.viabackwards.api.entities.storage.EntityData)2 WrappedMetadata (com.viaversion.viabackwards.api.entities.storage.WrappedMetadata)2 LegacyEntityRewriter (com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter)2 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)2 Entity1_12Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types)2 Type (com.viaversion.viaversion.api.type.Type)2 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)2 Optional (java.util.Optional)2 PotionSplashHandler (com.viaversion.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler)1 Protocol1_10To1_11 (com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11)1 ChestedHorseStorage (com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage)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