Search in sources :

Example 81 with NBTTagCompound

use of net.minecraft.server.v1_16_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_11_R1 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.c());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_11_R1.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound)

Example 82 with NBTTagCompound

use of net.minecraft.server.v1_16_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_12_R1 method setAttribute.

@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
    net.minecraft.server.v1_12_R1.ItemStack nmsItem = getNMSStack(bukkitItem);
    if (nmsItem.getTag() == null) {
        nmsItem.setTag(new NBTTagCompound());
    }
    NBTTagCompound compound = nmsItem.getTag();
    if (compound.hasKey("AttributeModifiers")) {
        NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
        // NBT lists don't have an indexOf method, so we need to loop
        // through each attribute, and determine if it is one we want to
        // modify. We want to modify an attribute if the attribute was
        // set using MechanicsCore, and it's attribute type matches the
        // parameter attribute type.
        boolean isModifiedAttribute = false;
        for (int i = 0; i < list.size(); i++) {
            // 10 is the id for nbt lists
            if (list.get(i).getTypeId() != 10) {
                continue;
            }
            NBTTagCompound nbt = list.get(i);
            String name = nbt.getString("Name");
            String attributeName = nbt.getString("AttributeName");
            // There is no offhand, or slot argument in 1_8_8.
            if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
                continue;
            }
            // Since this attribute already exists, we only need to modify
            // the existing value. No need to set the name/uuid
            nbt.setDouble("Amount", value);
            isModifiedAttribute = true;
            break;
        }
        if (!isModifiedAttribute) {
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("AttributeName", attribute.getMinecraftName());
            nbt.setString("Name", "MechanicsCoreAttribute");
            nbt.setDouble("Amount", value);
            // 0 == add
            nbt.setInt("Operation", 0);
            nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
            nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
            if (slot != null) {
                nbt.setString("Slot", slot.getSlotName());
            }
        }
    }
    bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) Nonnull(javax.annotation.Nonnull)

Example 83 with NBTTagCompound

use of net.minecraft.server.v1_16_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_12_R1 method getBukkitCompound.

private NBTTagCompound getBukkitCompound(ItemStack bukkitStack, String plugin) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitStack);
    if (nmsStack.getTag() == null) {
        nmsStack.setTag(new NBTTagCompound());
    }
    NBTTagCompound nbt = nmsStack.getTag().getCompound("PublicBukkitValues");
    // internal map.
    if (nbt.isEmpty()) {
        nmsStack.getTag().set("PublicBukkitValues", nbt);
    }
    if (plugin == null) {
        return nbt;
    } else {
        NBTTagCompound pluginCompound = nbt.getCompound(plugin);
        if (pluginCompound.isEmpty()) {
            nbt.set(plugin, pluginCompound);
        }
        return pluginCompound;
    }
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 84 with NBTTagCompound

use of net.minecraft.server.v1_16_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_12_R1 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.c());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_12_R1.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 85 with NBTTagCompound

use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method getItemStackNBTString.

@Override
public String getItemStackNBTString(ItemStack itemStack, String key) {
    net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
    return tagCompound.getString(key);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)70 ItemStack (org.bukkit.inventory.ItemStack)61 Map (java.util.Map)42 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)39 ArrayList (java.util.ArrayList)38 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)38 ItemMeta (org.bukkit.inventory.meta.ItemMeta)35 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)34 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)24 Nullable (javax.annotation.Nullable)21 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)21 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)20 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)20 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)20 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)19 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)18