Search in sources :

Example 16 with Tag

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

the class PistonHandler method getDataFromTag.

// The type hasn't actually been updated in the blockstorage, so we need to construct it
private String getDataFromTag(CompoundTag tag) {
    StringTag name = tag.get("Name");
    if (name == null)
        return null;
    CompoundTag properties = tag.get("Properties");
    if (properties == null)
        return name.getValue();
    StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]");
    for (Map.Entry<String, Tag> entry : properties) {
        if (!(entry.getValue() instanceof StringTag))
            continue;
        joiner.add(entry.getKey() + "=" + ((StringTag) entry.getValue()).getValue());
    }
    return joiner.toString();
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) 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) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) HashMap(java.util.HashMap) Map(java.util.Map) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) StringJoiner(java.util.StringJoiner)

Example 17 with Tag

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

the class SpawnerHandler method transform.

@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
    Tag dataTag = tag.get("SpawnData");
    if (dataTag instanceof CompoundTag) {
        CompoundTag data = (CompoundTag) dataTag;
        Tag idTag = data.get("id");
        if (idTag instanceof StringTag) {
            StringTag s = (StringTag) idTag;
            s.setValue(EntityNameRewrites.rewrite(s.getValue()));
        }
    }
    return tag;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) 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) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)

Example 18 with Tag

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

the class BlockItemPackets1_13 method handleItemToClient.

@Override
public Item handleItemToClient(Item item) {
    if (item == null)
        return null;
    // Custom mappings/super call moved down
    int originalId = item.identifier();
    Integer rawId = null;
    boolean gotRawIdFromTag = false;
    CompoundTag tag = item.tag();
    // Use tag to get original ID and data
    Tag originalIdTag;
    if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) {
        rawId = ((NumberTag) originalIdTag).asInt();
        gotRawIdFromTag = true;
    }
    if (rawId == null) {
        // Look for custom mappings
        super.handleItemToClient(item);
        // Handle one-way special case
        if (item.identifier() == -1) {
            if (originalId == 362) {
                // base/colorless shulker box
                // purple shulker box
                rawId = 0xe50000;
            } else {
                if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
                    ViaBackwards.getPlatform().getLogger().warning("Failed to get 1.12 item for " + originalId);
                }
                rawId = 0x10000;
            }
        } else {
            // Take the newly added tag
            if (tag == null) {
                tag = item.tag();
            }
            rawId = itemIdToRaw(item.identifier(), item, tag);
        }
    }
    item.setIdentifier(rawId >> 16);
    item.setData((short) (rawId & 0xFFFF));
    // NBT changes
    if (tag != null) {
        if (isDamageable(item.identifier())) {
            Tag damageTag = tag.remove("Damage");
            if (!gotRawIdFromTag && damageTag instanceof IntTag) {
                item.setData((short) (int) damageTag.getValue());
            }
        }
        if (item.identifier() == 358) {
            // map
            Tag mapTag = tag.remove("map");
            if (!gotRawIdFromTag && mapTag instanceof IntTag) {
                item.setData((short) (int) mapTag.getValue());
            }
        }
        // Shield and banner
        invertShieldAndBannerId(item, tag);
        // Display Name now uses JSON
        CompoundTag display = tag.get("display");
        if (display != null) {
            StringTag name = display.get("Name");
            if (name != null) {
                display.put(extraNbtTag + "|Name", new StringTag(name.getValue()));
                name.setValue(ChatRewriter.jsonToLegacyText(name.getValue()));
            }
        }
        // ench is now Enchantments and now uses identifiers
        rewriteEnchantmentsToClient(tag, false);
        rewriteEnchantmentsToClient(tag, true);
        rewriteCanPlaceToClient(tag, "CanPlaceOn");
        rewriteCanPlaceToClient(tag, "CanDestroy");
    }
    return item;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) ShortTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) ByteTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) NumberTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)

Example 19 with Tag

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

the class BlockItemPackets1_13 method rewriteCanPlaceToClient.

private void rewriteCanPlaceToClient(CompoundTag tag, String tagName) {
    // The tag was manually created incorrectly so ignore rewriting it
    if (!(tag.get(tagName) instanceof ListTag))
        return;
    ListTag blockTag = tag.get(tagName);
    if (blockTag == null)
        return;
    ListTag newCanPlaceOn = new ListTag(StringTag.class);
    tag.put(extraNbtTag + "|" + tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag)));
    for (Tag oldTag : blockTag) {
        Object value = oldTag.getValue();
        String[] newValues = value instanceof String ? BlockIdData.fallbackReverseMapping.get(((String) value).replace("minecraft:", "")) : null;
        if (newValues != null) {
            for (String newValue : newValues) {
                newCanPlaceOn.add(new StringTag(newValue));
            }
        } else {
            newCanPlaceOn.add(oldTag);
        }
    }
    tag.put(tagName, newCanPlaceOn);
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) ShortTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) ByteTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) NumberTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag) CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)

Example 20 with Tag

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

the class BlockItemPackets1_13 method invertShieldAndBannerId.

private void invertShieldAndBannerId(Item item, CompoundTag tag) {
    if (item.identifier() != 442 && item.identifier() != 425)
        return;
    Tag blockEntityTag = tag.get("BlockEntityTag");
    if (!(blockEntityTag instanceof CompoundTag))
        return;
    CompoundTag blockEntityCompoundTag = (CompoundTag) blockEntityTag;
    Tag base = blockEntityCompoundTag.get("Base");
    if (base instanceof IntTag) {
        IntTag baseTag = (IntTag) base;
        // invert color id
        baseTag.setValue(15 - baseTag.asInt());
    }
    Tag patterns = blockEntityCompoundTag.get("Patterns");
    if (patterns instanceof ListTag) {
        ListTag patternsTag = (ListTag) patterns;
        for (Tag pattern : patternsTag) {
            if (!(pattern instanceof CompoundTag))
                continue;
            IntTag colorTag = ((CompoundTag) pattern).get("Color");
            // Invert color id
            colorTag.setValue(15 - colorTag.asInt());
        }
    }
}
Also used : ListTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag) ShortTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag) ByteTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) NumberTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag) 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) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)

Aggregations

CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)33 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)33 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)29 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)22 IntTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)15 NumberTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag)12 ByteTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag)11 ShortTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag)10 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)8 Type (com.viaversion.viaversion.api.type.Type)7 IntArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag)7 LongArrayTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)4 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)4 Item (com.viaversion.viaversion.api.minecraft.item.Item)4 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)4 UUID (java.util.UUID)4 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)3