Search in sources :

Example 16 with ListTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag in project ViaBackwards by ViaVersion.

the class Protocol1_18To1_18_2 method registerPackets.

@Override
protected void registerPackets() {
    new CommandRewriter1_18_2(this).registerDeclareCommands(ClientboundPackets1_18.DECLARE_COMMANDS);
    final PacketHandler entityEffectIdHandler = wrapper -> {
        final int id = wrapper.read(Type.VAR_INT);
        if ((byte) id != id) {
            if (!Via.getConfig().isSuppressConversionWarnings()) {
                ViaBackwards.getPlatform().getLogger().warning("Cannot send entity effect id " + id + " to old client");
            }
            wrapper.cancel();
            return;
        }
        wrapper.write(Type.BYTE, (byte) id);
    };
    registerClientbound(ClientboundPackets1_18.ENTITY_EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(entityEffectIdHandler);
        }
    });
    registerClientbound(ClientboundPackets1_18.REMOVE_ENTITY_EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity id
            map(Type.VAR_INT);
            handler(entityEffectIdHandler);
        }
    });
    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);
            // World List
            map(Type.STRING_ARRAY);
            // Registry
            map(Type.NBT);
            // Current dimension data
            map(Type.NBT);
            handler(wrapper -> {
                final CompoundTag registry = wrapper.get(Type.NBT, 0);
                final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
                final ListTag dimensions = dimensionsHolder.get("value");
                for (final Tag dimension : dimensions) {
                    removeTagPrefix(((CompoundTag) dimension).get("element"));
                }
                removeTagPrefix(wrapper.get(Type.NBT, 1));
            });
        }
    });
    registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> removeTagPrefix(wrapper.passthrough(Type.NBT)));
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ClientboundPackets1_18(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CommandRewriter1_18_2(com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2) Via(com.viaversion.viaversion.api.Via) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) CommandRewriter1_18_2(com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.data.CommandRewriter1_18_2) 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) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 17 with ListTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_16_2 method handleBlockEntity.

private void handleBlockEntity(CompoundTag tag) {
    StringTag idTag = tag.get("id");
    if (idTag == null)
        return;
    if (idTag.getValue().equals("minecraft:skull")) {
        // Workaround an old client bug: MC-68487
        Tag skullOwnerTag = tag.get("SkullOwner");
        if (!(skullOwnerTag instanceof CompoundTag))
            return;
        CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
        if (!skullOwnerCompoundTag.contains("Id"))
            return;
        CompoundTag properties = skullOwnerCompoundTag.get("Properties");
        if (properties == null)
            return;
        ListTag textures = properties.get("textures");
        if (textures == null)
            return;
        CompoundTag first = textures.size() > 0 ? textures.get(0) : null;
        if (first == null)
            return;
        // Make the client cache the skinprofile over this uuid
        int hashCode = first.get("Value").getValue().hashCode();
        // TODO split texture in 4 for a lower collision chance
        int[] uuidIntArray = { hashCode, 0, 0, 0 };
        skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray));
    }
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) 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) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 18 with ListTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_14 method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    super.handleItemToClient(item);
    // Lore now uses JSON
    CompoundTag tag = item.tag();
    CompoundTag display;
    if (tag != null && (display = tag.get("display")) != null) {
        ListTag lore = display.get("Lore");
        if (lore != null) {
            saveListTag(display, lore, "Lore");
            for (Tag loreEntry : lore) {
                if (!(loreEntry instanceof StringTag))
                    continue;
                StringTag loreEntryTag = (StringTag) loreEntry;
                String value = loreEntryTag.getValue();
                if (value != null && !value.isEmpty()) {
                    loreEntryTag.setValue(ChatRewriter.jsonToLegacyText(value));
                }
            }
        }
    }
    enchantmentRewriter.handleToClient(item);
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 19 with ListTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag in project ViaBackwards by ViaVersion.

the class BlockItemPackets1_14 method handleItemToServer.

@Override
public Item handleItemToServer(Item item) {
    if (item == null)
        return null;
    // Lore now uses JSON
    CompoundTag tag = item.tag();
    CompoundTag display;
    if (tag != null && (display = tag.get("display")) != null) {
        // Transform to json if no backup tag is found (else process that in the super method)
        ListTag lore = display.get("Lore");
        if (lore != null && !hasBackupTag(display, "Lore")) {
            for (Tag loreEntry : lore) {
                if (loreEntry instanceof StringTag) {
                    StringTag loreEntryTag = (StringTag) loreEntry;
                    loreEntryTag.setValue(ChatRewriter.legacyTextToJsonString(loreEntryTag.getValue()));
                }
            }
        }
    }
    enchantmentRewriter.handleToServer(item);
    // Call this last to check for the backup lore above
    super.handleItemToServer(item);
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Aggregations

CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)19 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)19 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)17 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)16 IntTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)9 ByteTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag)7 NumberTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag)7 ShortTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag)7 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 Type (com.viaversion.viaversion.api.type.Type)4 ArrayList (java.util.ArrayList)3 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)2 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)2 EntityRewriter (com.viaversion.viabackwards.api.rewriters.EntityRewriter)2 Entity1_17Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types)2 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)2 MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)2 Particle (com.viaversion.viaversion.api.type.types.Particle)2 Types1_17 (com.viaversion.viaversion.api.type.types.version.Types1_17)2 ClientboundPackets1_17 (com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17)2