Search in sources :

Example 46 with CompoundTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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 47 with CompoundTag

use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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 48 with CompoundTag

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

CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)48 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)36 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)34 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)25 IntTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)18 ByteTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag)12 NumberTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag)12 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)11 Type (com.viaversion.viaversion.api.type.Type)10 ShortTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag)10 IntArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag)8 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)7 LongArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag)7 ArrayList (java.util.ArrayList)7 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)6 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)6 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)4 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)4 Item (com.viaversion.viaversion.api.minecraft.item.Item)4 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)4