Search in sources :

Example 11 with CompoundTag

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

the class BlockItemPackets1_13 method itemIdToRaw.

private int itemIdToRaw(int oldId, Item item, CompoundTag tag) {
    Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);
    if (eggEntityId.isPresent()) {
        if (tag == null) {
            item.setTag(tag = new CompoundTag());
        }
        if (!tag.contains("EntityTag")) {
            CompoundTag entityTag = new CompoundTag();
            entityTag.put("id", new StringTag(eggEntityId.get()));
            tag.put("EntityTag", entityTag);
        }
        // 383 << 16;
        return 0x17f0000;
    }
    return (oldId >> 4) << 16 | oldId & 0xF;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 12 with CompoundTag

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

the class BlockItemPackets1_12 method handleNbtToServer.

private void handleNbtToServer(CompoundTag compoundTag, CompoundTag backupTag) {
    // Restore the removed long array tags
    for (Map.Entry<String, Tag> entry : backupTag) {
        if (entry.getValue() instanceof CompoundTag) {
            CompoundTag nestedTag = compoundTag.get(entry.getKey());
            handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
        } else {
            compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
        }
    }
}
Also used : IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) LongArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntArrayTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag) Map(java.util.Map) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 13 with CompoundTag

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

the class ItemPackets1_11_1 method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    super.handleItemToClient(item);
    CompoundTag tag = item.tag();
    if (tag == null)
        return item;
    if (tag.get("ench") instanceof ListTag) {
        enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
    }
    if (tag.get("StoredEnchantments") instanceof ListTag) {
        enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
    }
    return item;
}
Also used : ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 14 with CompoundTag

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

the class ItemRewriterBase method saveListTag.

protected void saveListTag(CompoundTag displayTag, ListTag original, String name) {
    // Multiple places might try to backup data
    String backupName = nbtTagName + "|o" + name;
    if (!displayTag.contains(backupName)) {
        // Clone all tag entries
        ListTag listTag = new ListTag();
        for (Tag tag : original.getValue()) {
            listTag.add(tag.clone());
        }
        displayTag.put(backupName, listTag);
    }
}
Also used : Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)

Example 15 with CompoundTag

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

the class LegacyBlockItemRewriter method getNamedTag.

protected CompoundTag getNamedTag(String text) {
    CompoundTag tag = new CompoundTag();
    tag.put("display", new CompoundTag());
    text = "§r" + text;
    ((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text));
    return tag;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) 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