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();
}
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;
}
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;
}
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);
}
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());
}
}
}
Aggregations