Search in sources :

Example 26 with StringTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag 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)

Example 27 with StringTag

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

the class BlockItemPackets1_16 method handleBlockEntity.

private void handleBlockEntity(CompoundTag tag) {
    StringTag idTag = tag.get("id");
    if (idTag == null)
        return;
    String id = idTag.getValue();
    if (id.equals("minecraft:conduit")) {
        Tag targetUuidTag = tag.remove("Target");
        if (!(targetUuidTag instanceof IntArrayTag))
            return;
        // Target -> target_uuid
        UUID targetUuid = UUIDIntArrayType.uuidFromIntArray((int[]) targetUuidTag.getValue());
        tag.put("target_uuid", new StringTag(targetUuid.toString()));
    } else if (id.equals("minecraft:skull")) {
        Tag skullOwnerTag = tag.remove("SkullOwner");
        if (!(skullOwnerTag instanceof CompoundTag))
            return;
        CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
        Tag ownerUuidTag = skullOwnerCompoundTag.remove("Id");
        if (ownerUuidTag instanceof IntArrayTag) {
            UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) ownerUuidTag.getValue());
            skullOwnerCompoundTag.put("Id", new StringTag(ownerUuid.toString()));
        }
        // SkullOwner -> Owner
        CompoundTag ownerTag = new CompoundTag();
        for (Map.Entry<String, Tag> entry : skullOwnerCompoundTag) {
            ownerTag.put(entry.getKey(), entry.getValue());
        }
        tag.put("Owner", ownerTag);
    }
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 28 with StringTag

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

the class BlockItemPackets1_16 method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    super.handleItemToClient(item);
    CompoundTag tag = item.tag();
    if (item.identifier() == 771 && tag != null) {
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof IntArrayTag) {
                UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
                ownerCompundTag.put("Id", new StringTag(ownerUuid.toString()));
            }
        }
    }
    InventoryPackets.newToOldAttributes(item);
    enchantmentRewriter.handleToClient(item);
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Aggregations

StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)28 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)27 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)22 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)16 IntTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)13 ByteTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag)8 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)5 Type (com.viaversion.viaversion.api.type.Type)4 IntArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag)4 ArrayList (java.util.ArrayList)4 LongArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag)3 UUID (java.util.UUID)3 MappedLegacyBlockItem (com.viaversion.viabackwards.api.data.MappedLegacyBlockItem)2 EntityRewriter (com.viaversion.viabackwards.api.rewriters.EntityRewriter)2 Protocol1_17_1To1_18 (com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18)2 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)2 Entity1_17Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types)2 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)2