use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag in project ViaBackwards by ViaVersion.
the class BackwardsBlockEntityProvider method transform.
/**
* Transform blocks to block entities!
*
* @param user The user
* @param position The position of the block entity
* @param id The block entity id
*/
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
CompoundTag tag = new CompoundTag();
tag.put("id", new StringTag(id));
tag.put("x", new IntTag(Math.toIntExact(position.getX())));
tag.put("y", new IntTag(Math.toIntExact(position.getY())));
tag.put("z", new IntTag(Math.toIntExact(position.getZ())));
return this.transform(user, position, tag);
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag in project ViaBackwards by ViaVersion.
the class BedHandler method transform.
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
int offset = blockId - 748;
int color = offset >> 4;
tag.put("color", new IntTag(color));
return tag;
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag in project ViaBackwards by ViaVersion.
the class FlowerPotHandler method transform.
// TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :(
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
Pair<String, Byte> item = getOrDefault(blockId);
tag.put("Item", new StringTag(item.getKey()));
tag.put("Data", new IntTag(item.getValue()));
return tag;
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_13 method handleItemToServer.
@Override
public Item handleItemToServer(Item item) {
if (item == null)
return null;
CompoundTag tag = item.tag();
// Save original id
int originalId = (item.identifier() << 16 | item.data() & 0xFFFF);
int rawId = (item.identifier() << 4 | item.data() & 0xF);
// NBT Additions
if (isDamageable(item.identifier())) {
if (tag == null)
item.setTag(tag = new CompoundTag());
tag.put("Damage", new IntTag(item.data()));
}
if (item.identifier() == 358) {
// map
if (tag == null)
item.setTag(tag = new CompoundTag());
tag.put("map", new IntTag(item.data()));
}
// NBT Changes
if (tag != null) {
// Shield and banner
invertShieldAndBannerId(item, tag);
// Display Name now uses JSON
Tag display = tag.get("display");
if (display instanceof CompoundTag) {
CompoundTag displayTag = (CompoundTag) display;
StringTag name = displayTag.get("Name");
if (name != null) {
StringTag via = displayTag.remove(extraNbtTag + "|Name");
name.setValue(via != null ? via.getValue() : ChatRewriter.legacyTextToJsonString(name.getValue()));
}
}
// ench is now Enchantments and now uses identifiers
rewriteEnchantmentsToServer(tag, false);
rewriteEnchantmentsToServer(tag, true);
rewriteCanPlaceToServer(tag, "CanPlaceOn");
rewriteCanPlaceToServer(tag, "CanDestroy");
// Handle SpawnEggs
if (item.identifier() == 383) {
CompoundTag entityTag = tag.get("EntityTag");
StringTag identifier;
if (entityTag != null && (identifier = entityTag.get("id")) != null) {
rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue());
if (rawId == -1) {
// Bat fallback
rawId = 25100288;
} else {
entityTag.remove("id");
if (entityTag.isEmpty()) {
tag.remove("EntityTag");
}
}
} else {
// Fallback to bat
rawId = 25100288;
}
}
if (tag.isEmpty()) {
item.setTag(tag = null);
}
}
// Handle custom mappings
int identifier = item.identifier();
item.setIdentifier(rawId);
super.handleItemToServer(item);
// Mapped with original data, we can return here
if (item.identifier() != rawId && item.identifier() != -1)
return item;
// Set to legacy id again
item.setIdentifier(identifier);
int newId = -1;
if (!protocol.getMappingData().getItemMappings().inverse().containsKey(rawId)) {
if (!isDamageable(item.identifier()) && item.identifier() != 358) {
// Map
if (tag == null)
item.setTag(tag = new CompoundTag());
// Data will be lost, saving original id
tag.put(extraNbtTag, new IntTag(originalId));
}
if (item.identifier() == 229) {
// purple shulker box
// directly set the new id -> base/colorless shulker box
newId = 362;
} else if (item.identifier() == 31 && item.data() == 0) {
// Shrub was removed
// Dead Bush
rawId = 32 << 4;
} else if (protocol.getMappingData().getItemMappings().inverse().containsKey(rawId & ~0xF)) {
// Remove data
rawId &= ~0xF;
} else {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.identifier());
}
// Stone
rawId = 16;
}
}
if (newId == -1) {
newId = protocol.getMappingData().getItemMappings().inverse().get(rawId);
}
item.setIdentifier(newId);
item.setData((short) 0);
return item;
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag in project ViaBackwards by ViaVersion.
the class ItemRewriter method handleItemToClient.
@Override
@Nullable
public Item handleItemToClient(@Nullable Item item) {
if (item == null)
return null;
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
if (protocol.getTranslatableRewriter() != null && display != null) {
// Handle name and lore components
StringTag name = display.get("Name");
if (name != null) {
String newValue = protocol.getTranslatableRewriter().processText(name.getValue()).toString();
if (!newValue.equals(name.getValue())) {
saveStringTag(display, name, "Name");
}
name.setValue(newValue);
}
ListTag lore = display.get("Lore");
if (lore != null) {
boolean changed = false;
for (Tag loreEntryTag : lore) {
if (!(loreEntryTag instanceof StringTag))
continue;
StringTag loreEntry = (StringTag) loreEntryTag;
String newValue = protocol.getTranslatableRewriter().processText(loreEntry.getValue()).toString();
if (!changed && !newValue.equals(loreEntry.getValue())) {
// Backup original lore before doing any modifications
changed = true;
saveListTag(display, lore, "Lore");
}
loreEntry.setValue(newValue);
}
}
}
MappedItem data = protocol.getMappingData().getMappedItem(item.identifier());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
}
if (item.tag() == null) {
item.setTag(new CompoundTag());
}
// Save original id, set remapped id
item.tag().put(nbtTagName + "|id", new IntTag(item.identifier()));
item.setIdentifier(data.getId());
// Set custom name - only done if there is no original one
if (display == null) {
item.tag().put("display", display = new CompoundTag());
}
if (!display.contains("Name")) {
display.put("Name", new StringTag(data.getJsonName()));
display.put(nbtTagName + "|customName", new ByteTag());
}
return item;
}
Aggregations