use of com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag in project ViaBackwards by ViaVersion.
the class LegacyBlockItemRewriter method handleItemToClient.
@Override
@Nullable
public Item handleItemToClient(@Nullable Item item) {
if (item == null)
return null;
MappedLegacyBlockItem data = replacementData.get(item.identifier());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
}
short originalData = item.data();
item.setIdentifier(data.getId());
// Keep original data if mapped data is set to -1
if (data.getData() != -1) {
item.setData(data.getData());
}
// Set display name
if (data.getName() != null) {
if (item.tag() == null) {
item.setTag(new CompoundTag());
}
CompoundTag display = item.tag().get("display");
if (display == null) {
item.tag().put("display", display = new CompoundTag());
}
StringTag nameTag = display.get("Name");
if (nameTag == null) {
display.put("Name", nameTag = new StringTag(data.getName()));
display.put(nbtTagName + "|customName", new ByteTag());
}
// Handle colors
String value = nameTag.getValue();
if (value.contains("%vb_color%")) {
display.put("Name", new StringTag(value.replace("%vb_color%", BlockColors.get(originalData))));
}
}
return item;
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag in project ViaBackwards by ViaVersion.
the class LegacyEnchantmentRewriter method rewriteEnchantmentsToClient.
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag enchantments = tag.get(key);
ListTag remappedEnchantments = new ListTag(CompoundTag.class);
List<Tag> lore = new ArrayList<>();
for (Tag enchantmentEntry : enchantments.clone()) {
Tag idTag = ((CompoundTag) enchantmentEntry).get("id");
if (idTag == null)
continue;
short newId = ((NumberTag) idTag).asShort();
String enchantmentName = enchantmentMappings.get(newId);
if (enchantmentName != null) {
enchantments.remove(enchantmentEntry);
short level = ((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort();
if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) {
lore.add(new StringTag(enchantmentName));
} else {
lore.add(new StringTag(enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level)));
}
remappedEnchantments.add(enchantmentEntry);
}
}
if (!lore.isEmpty()) {
if (!storedEnchant && enchantments.size() == 0) {
CompoundTag dummyEnchantment = new CompoundTag();
dummyEnchantment.put("id", new ShortTag((short) 0));
dummyEnchantment.put("lvl", new ShortTag((short) 0));
enchantments.add(dummyEnchantment);
tag.put(nbtTagName + "|dummyEnchant", new ByteTag());
IntTag hideFlags = tag.get("HideFlags");
if (hideFlags == null) {
hideFlags = new IntTag();
} else {
tag.put(nbtTagName + "|oldHideFlags", new IntTag(hideFlags.asByte()));
}
int flags = hideFlags.asByte() | 1;
hideFlags.setValue(flags);
tag.put("HideFlags", hideFlags);
}
tag.put(nbtTagName + "|" + key, remappedEnchantments);
CompoundTag display = tag.get("display");
if (display == null) {
tag.put("display", display = new CompoundTag());
}
ListTag loreTag = display.get("Lore");
if (loreTag == null) {
display.put("Lore", loreTag = new ListTag(StringTag.class));
}
lore.addAll(loreTag.getValue());
loreTag.setValue(lore);
}
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag 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.StringTag 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.StringTag 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;
}
Aggregations