Search in sources :

Example 61 with NBTTagList

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

the class ItemAttributes method replaceAttributes.

public static ItemStack replaceAttributes(ItemStack original, Single... attributes) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
    NBTTagList modifiers = new NBTTagList();
    for (Single attribute : attributes) setAttribute(modifiers, attribute.attribute, attribute.value, attribute.slot, attribute.operation);
    if (attributes.length == 0) {
        setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
    }
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);
    return CraftItemStack.asBukkitCopy(nmsStack);
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 62 with NBTTagList

use of net.minecraft.server.v1_16_R3.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 63 with NBTTagList

use of net.minecraft.server.v1_16_R3.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 64 with NBTTagList

use of net.minecraft.server.v1_16_R3.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)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)24 ArrayList (java.util.ArrayList)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 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 Map (java.util.Map)20 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)17 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)17 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)8 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)6 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