Search in sources :

Example 26 with CompoundTag

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

the class PistonHandler method transform.

@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
    CompoundTag blockState = tag.get("blockState");
    if (blockState == null)
        return tag;
    String dataFromTag = getDataFromTag(blockState);
    if (dataFromTag == null)
        return tag;
    Integer id = pistonIds.get(dataFromTag);
    if (id == null) {
        // TODO see why this could be null and if this is bad
        return tag;
    }
    tag.put("blockId", new IntTag(id >> 4));
    tag.put("blockData", new IntTag(id & 15));
    return tag;
}
Also used : CompoundTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)

Example 27 with CompoundTag

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

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

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

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

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