Search in sources :

Example 1 with IntTag

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);
}
Also used : 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)

Example 2 with IntTag

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;
}
Also used : IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)

Example 3 with IntTag

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;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) IntTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)

Example 4 with IntTag

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;
}
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 5 with IntTag

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;
}
Also used : StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) ByteTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag) MappedItem(com.viaversion.viabackwards.api.data.MappedItem) Tag(com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag) StringTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag) 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) ByteTag(com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag) 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) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

IntTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag)16 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)13 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)12 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)10 ByteTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag)9 ListTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag)9 NumberTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag)8 ShortTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag)7 ArrayList (java.util.ArrayList)3 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)2 MappedItem (com.viaversion.viabackwards.api.data.MappedItem)1 MappedLegacyBlockItem (com.viaversion.viabackwards.api.data.MappedLegacyBlockItem)1 ItemRewriter (com.viaversion.viabackwards.api.rewriters.ItemRewriter)1 Protocol1_17_1To1_18 (com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18)1 BlockEntityIds (com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.data.BlockEntityIds)1 Block (com.viaversion.viabackwards.utils.Block)1 ParticleMappings (com.viaversion.viaversion.api.data.ParticleMappings)1 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)1 Position (com.viaversion.viaversion.api.minecraft.Position)1 BlockEntity (com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity)1