Search in sources :

Example 31 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class SpawnPackets method register.

public static void register(Protocol1_9To1_8 protocol) {
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    // 1 - UUID
                    wrapper.write(Type.UUID, tracker.getEntityUUID(entityID));
                }
            });
            // 2 - Type
            map(Type.BYTE);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    int typeID = wrapper.get(Type.BYTE, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, true));
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            // 3 - X - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 4 - Y - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 5 - Z - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 6 - Pitch
            map(Type.BYTE);
            // 7 - Yaw
            map(Type.BYTE);
            // 8 - Data
            map(Type.INT);
            // Create last 3 shorts
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // Data (1st Integer)
                    int data = wrapper.get(Type.INT, 0);
                    short vX = 0, vY = 0, vZ = 0;
                    if (data > 0) {
                        vX = wrapper.read(Type.SHORT);
                        vY = wrapper.read(Type.SHORT);
                        vZ = wrapper.read(Type.SHORT);
                    }
                    wrapper.write(Type.SHORT, vX);
                    wrapper.write(Type.SHORT, vY);
                    wrapper.write(Type.SHORT, vZ);
                }
            });
            // Handle potions
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    final int entityID = wrapper.get(Type.VAR_INT, 0);
                    // Data
                    final int data = wrapper.get(Type.INT, 0);
                    int typeID = wrapper.get(Type.BYTE, 0);
                    if (Entity1_10Types.getTypeFromId(typeID, true) == Entity1_10Types.EntityType.SPLASH_POTION) {
                        // Convert this to meta data, woo!
                        PacketWrapper metaPacket = wrapper.create(ClientboundPackets1_9.ENTITY_METADATA, new PacketHandler() {

                            @Override
                            public void handle(PacketWrapper wrapper) throws Exception {
                                wrapper.write(Type.VAR_INT, entityID);
                                List<Metadata> meta = new ArrayList<>();
                                // Potion
                                Item item = new DataItem(373, (byte) 1, (short) data, null);
                                // Rewrite so that it gets the right nbt
                                ItemRewriter.toClient(item);
                                // TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
                                Metadata potion = new Metadata(5, MetaType1_9.Slot, item);
                                meta.add(potion);
                                wrapper.write(Types1_9.METADATA_LIST, meta);
                            }
                        });
                        // Fix packet order
                        wrapper.send(Protocol1_9To1_8.class);
                        metaPacket.send(Protocol1_9To1_8.class);
                        wrapper.cancel();
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_EXPERIENCE_ORB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB);
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            // 1 - X - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 2 - Y - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 3 - Z - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 4 - Amount to spawn
            map(Type.SHORT);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_GLOBAL_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Type
            map(Type.BYTE);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // Currently only lightning uses this
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.EntityType.LIGHTNING);
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            // 2 - X - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 3 - Y - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 4 - Z - Needs to be divide by 32
            map(Type.INT, toNewDouble);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_MOB, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    // 1 - UUID
                    wrapper.write(Type.UUID, tracker.getEntityUUID(entityID));
                }
            });
            // 2 - Type
            map(Type.UNSIGNED_BYTE);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    int typeID = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, false));
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            // 3 - X - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 4 - Y - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 5 - Z - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 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);
            map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (tracker.hasEntity(entityId)) {
                        protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
                    } else {
                        Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
                        metadataList.clear();
                    }
                }
            });
            // Handler for meta data
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.handleMetadata(entityID, metadataList);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_PAINTING, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.EntityType.PAINTING);
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    // 1 - UUID
                    wrapper.write(Type.UUID, tracker.getEntityUUID(entityID));
                }
            });
            // 2 - Title
            map(Type.STRING);
            // 3 - Position
            map(Type.POSITION);
            // 4 - Direction
            map(Type.BYTE);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SPAWN_PLAYER, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Player UUID
            map(Type.UUID);
            // Parse this info
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addEntity(entityID, Entity1_10Types.EntityType.PLAYER);
                    tracker.sendMetadataBuffer(entityID);
                }
            });
            // 2 - X - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 3 - Y - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 4 - Z - Needs to be divide by 32
            map(Type.INT, toNewDouble);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - Pitch
            map(Type.BYTE);
            handler(new // Handle discontinued player hand item
            PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    short item = wrapper.read(Type.SHORT);
                    if (item != 0) {
                        PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_9.ENTITY_EQUIPMENT, null, wrapper.user());
                        packet.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
                        packet.write(Type.VAR_INT, 0);
                        packet.write(Type.ITEM, new DataItem(item, (byte) 1, (short) 0, null));
                        try {
                            packet.send(Protocol1_9To1_8.class);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
            map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (tracker.hasEntity(entityId)) {
                        protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
                    } else {
                        Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
                        metadataList.clear();
                    }
                }
            });
            // Handler for meta data
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.handleMetadata(entityID, metadataList);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.DESTROY_ENTITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entities to destroy
            map(Type.VAR_INT_ARRAY_PRIMITIVE);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int[] entities = wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0);
                    EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    for (int entity : entities) {
                        // EntityTracker
                        tracker.removeEntity(entity);
                    }
                }
            });
        }
    });
}
Also used : EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) EntityTracker(com.viaversion.viaversion.api.data.entity.EntityTracker) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ArrayList(java.util.ArrayList) List(java.util.List) MetadataRewriter1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8)

Example 32 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class EntityTracker1_9 method handleMetadata.

public void handleMetadata(int entityId, List<Metadata> metadataList) {
    com.viaversion.viaversion.api.minecraft.entities.EntityType type = entityType(entityId);
    if (type == null) {
        return;
    }
    for (Metadata metadata : new ArrayList<>(metadataList)) {
        // Fix: wither (crash fix)
        if (type == EntityType.WITHER) {
            if (metadata.id() == 10) {
                metadataList.remove(metadata);
            // metadataList.add(new Metadata(10, NewType.Byte.getTypeID(), Type.BYTE, 0));
            }
        }
        // Fix: enderdragon (crash fix)
        if (type == EntityType.ENDER_DRAGON) {
            if (metadata.id() == 11) {
                metadataList.remove(metadata);
            // metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0));
            }
        }
        if (type == EntityType.SKELETON) {
            if ((getMetaByIndex(metadataList, 12)) == null) {
                metadataList.add(new Metadata(12, MetaType1_9.Boolean, true));
            }
        }
        // ECHOPET Patch
        if (type == EntityType.HORSE) {
            // Wrong metadata value from EchoPet, patch since it's discontinued. (https://github.com/DSH105/EchoPet/blob/06947a8b08ce40be9a518c2982af494b3b99d140/modules/API/src/main/java/com/dsh105/echopet/compat/api/entity/HorseArmour.java#L22)
            if (metadata.id() == 16 && (int) metadata.getValue() == Integer.MIN_VALUE)
                metadata.setValue(0);
        }
        if (type == EntityType.PLAYER) {
            if (metadata.id() == 0) {
                // Byte
                byte data = (byte) metadata.getValue();
                if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
                    if ((data & 0x10) == 0x10) {
                        if (validBlocking.contains(entityId)) {
                            Item shield = new DataItem(442, (byte) 1, (short) 0, null);
                            setSecondHand(entityId, shield);
                        } else {
                            setSecondHand(entityId, null);
                        }
                    } else {
                        setSecondHand(entityId, null);
                    }
                }
            }
            if (metadata.id() == 12 && Via.getConfig().isLeftHandedHandling()) {
                // Player model
                metadataList.add(new Metadata(// Main hand
                13, MetaType1_9.Byte, (byte) (((((byte) metadata.getValue()) & 0x80) != 0) ? 0 : 1)));
            }
        }
        if (type == EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
            if (metadata.id() == 0 && getMetaByIndex(metadataList, 10) != null) {
                // Only happens if the armorstand is small
                Metadata meta = getMetaByIndex(metadataList, 10);
                byte data = (byte) metadata.getValue();
                // Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
                Metadata displayName;
                Metadata displayNameVisible;
                if ((data & 0x20) == 0x20 && ((byte) meta.getValue() & 0x01) == 0x01 && (displayName = getMetaByIndex(metadataList, 2)) != null && !((String) displayName.getValue()).isEmpty() && (displayNameVisible = getMetaByIndex(metadataList, 3)) != null && (boolean) displayNameVisible.getValue()) {
                    if (!knownHolograms.contains(entityId)) {
                        knownHolograms.add(entityId);
                        try {
                            // Send movement
                            PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_POSITION, null, user());
                            wrapper.write(Type.VAR_INT, entityId);
                            wrapper.write(Type.SHORT, (short) 0);
                            wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
                            wrapper.write(Type.SHORT, (short) 0);
                            wrapper.write(Type.BOOLEAN, true);
                            wrapper.scheduleSend(Protocol1_9To1_8.class);
                        } catch (Exception ignored) {
                        }
                    }
                }
            }
        }
        // Boss bar
        if (Via.getConfig().isBossbarPatch()) {
            if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
                if (metadata.id() == 2) {
                    BossBar bar = bossBarMap.get(entityId);
                    String title = (String) metadata.getValue();
                    title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? DRAGON_TRANSLATABLE : WITHER_TRANSLATABLE) : title;
                    if (bar == null) {
                        bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, BossColor.PINK, BossStyle.SOLID);
                        bossBarMap.put(entityId, bar);
                        bar.addConnection(user());
                        bar.show();
                        // Send to provider
                        Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
                    } else {
                        bar.setTitle(title);
                    }
                } else if (metadata.id() == 6 && !Via.getConfig().isBossbarAntiflicker()) {
                    // If anti flicker is enabled, don't update health
                    BossBar bar = bossBarMap.get(entityId);
                    // Make health range between 0 and 1
                    float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
                    float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
                    if (bar == null) {
                        String title = type == EntityType.ENDER_DRAGON ? DRAGON_TRANSLATABLE : WITHER_TRANSLATABLE;
                        bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
                        bossBarMap.put(entityId, bar);
                        bar.addConnection(user());
                        bar.show();
                        // Send to provider
                        Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
                    } else {
                        bar.setHealth(health);
                    }
                }
            }
        }
    }
}
Also used : DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) BossBarProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper)

Example 33 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class EntityRewriter method logException.

private void logException(Exception e, @Nullable EntityType type, List<Metadata> metadataList, Metadata metadata) {
    if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
        Logger logger = Via.getPlatform().getLogger();
        logger.severe("An error occurred in metadata handler " + this.getClass().getSimpleName() + " for " + (type != null ? type.name() : "untracked") + " entity type: " + metadata);
        logger.severe(metadataList.stream().sorted(Comparator.comparingInt(Metadata::id)).map(Metadata::toString).collect(Collectors.joining("\n", "Full metadata: ", "")));
        e.printStackTrace();
    }
}
Also used : Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) Logger(java.util.logging.Logger)

Example 34 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class EntityPackets method register.

public static void register(Protocol protocol) {
    final PacketHandler metaTypeHandler = wrapper -> {
        for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
            metadata.setMetaType(Types1_13_2.META_TYPES.byId(metadata.metaType().typeId()));
        }
    };
    protocol.registerClientbound(ClientboundPackets1_13.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_13.METADATA_LIST, Types1_13_2.METADATA_LIST);
            handler(metaTypeHandler);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_13.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_13.METADATA_LIST, Types1_13_2.METADATA_LIST);
            handler(metaTypeHandler);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_13.ENTITY_METADATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Metadata list
            map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST);
            handler(metaTypeHandler);
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13) Type(com.viaversion.viaversion.api.type.Type) Types1_13_2(com.viaversion.viaversion.api.type.types.version.Types1_13_2) Protocol(com.viaversion.viaversion.api.protocol.Protocol) Types1_13(com.viaversion.viaversion.api.type.types.version.Types1_13) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata)

Example 35 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class OldMetaType method read.

@Override
public Metadata read(final ByteBuf buffer) throws Exception {
    final byte index = buffer.readByte();
    // End of metadata
    if (index == END)
        return null;
    final MetaType type = this.getType((index & 224) >> 5);
    return new Metadata(index & 31, type, type.type().read(buffer));
}
Also used : Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) MetaType(com.viaversion.viaversion.api.minecraft.metadata.MetaType)

Aggregations

Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)37 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)21 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)15 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)14 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)11 Item (com.viaversion.viaversion.api.minecraft.item.Item)10 Type (com.viaversion.viaversion.api.type.Type)8 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)6 MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)6 EntityData (com.viaversion.viabackwards.api.entities.storage.EntityData)5 LegacyEntityRewriter (com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter)5 Particle (com.viaversion.viaversion.api.type.types.Particle)5 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)5 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)4 WrappedMetadata (com.viaversion.viabackwards.api.entities.storage.WrappedMetadata)4 Entity1_13Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types)4 DataItem (com.viaversion.viaversion.api.minecraft.item.DataItem)4 ArrayList (java.util.ArrayList)4 EntityPositionHandler (com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler)3 Block (com.viaversion.viabackwards.utils.Block)3