Search in sources :

Example 66 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method resetAttributes.

public static ItemStack resetAttributes(ItemStack original) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    if (nmsStack.hasTag()) {
        NBTTagCompound compound = nmsStack.getTag();
        NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
        if (modifiers != null) {
            compound.remove("AttributeModifiers");
            nmsStack.setTag(compound);
            return CraftItemStack.asBukkitCopy(nmsStack);
        } else
            return original;
    } else
        return original;
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 67 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    net.minecraft.server.v1_10_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").setString("EntityId", entity);
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
        tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
        tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
    }
    final NBTTagList tagList = new NBTTagList();
    final NBTTagCompound spawnPotentials = new NBTTagCompound();
    spawnPotentials.set("Entity", new NBTTagCompound());
    spawnPotentials.getCompound("Entity").setString("id", entity);
    spawnPotentials.setInt("Weight", 1);
    tagList.add(spawnPotentials);
    tag.getCompound("BlockEntityTag").set("SpawnPotentials", tagList);
    // SpawnEgg data
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", entity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound)

Example 68 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    net.minecraft.server.v1_9_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").setString("EntityId", entity);
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
        tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
        tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
    }
    final NBTTagList tagList = new NBTTagList();
    final NBTTagCompound spawnPotentials = new NBTTagCompound();
    spawnPotentials.set("Entity", new NBTTagCompound());
    spawnPotentials.getCompound("Entity").setString("id", entity);
    spawnPotentials.setInt("Weight", 1);
    tagList.add(spawnPotentials);
    tag.getCompound("BlockEntityTag").set("SpawnPotentials", tagList);
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", entity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Example 69 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project PaperDev by Kamillaova.

the class CraftMetaItem method buildEnchantments.

static EnchantmentMap buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
    // Paper
    if (!tag.hasKey(key.NBT)) {
        return null;
    }
    NBTTagList ench = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
    // Paper
    EnchantmentMap enchantments = new EnchantmentMap();
    for (int i = 0; i < ench.size(); i++) {
        int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
        int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);
        Enchantment enchant = Enchantment.getById(id);
        if (enchant != null) {
            enchantments.put(enchant, level);
        }
    }
    return enchantments;
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) Enchantment(org.bukkit.enchantments.Enchantment)

Example 70 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project PaperDev by Kamillaova.

the class CraftMetaKnowledgeBook method applyToItem.

void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData);
    if (hasRecipes()) {
        NBTTagList list = new NBTTagList();
        for (NamespacedKey recipe : this.recipes) {
            list.add(new NBTTagString(recipe.toString()));
        }
        itemData.set(BOOK_RECIPES.NBT, list);
    }
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NamespacedKey(org.bukkit.NamespacedKey) CraftNamespacedKey(org.bukkit.craftbukkit.v1_12_R1.util.CraftNamespacedKey) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString)

Aggregations

NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)27 ItemStack (org.bukkit.inventory.ItemStack)23 ArrayList (java.util.ArrayList)22 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 Map (java.util.Map)21 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)8 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)6 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_16_R3.NBTTagList)5 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_9_R2.NBTTagList)5