I am somewhat confused on how to set nbt on a itemstack. I want to set this nbt SkullOwner:{Id:"198765c1-c236-4c7d-8555-d0dbacfcb123",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc2MmExNWIwNDY5MmEyZTRiM2ZiMzY2M2JkNGI3ODQzNGRjZTE3MzJiOGViMWM3YTlmN2MwZmJmNmYifX19"}]}}}
ok thanks I was actually reading forums cause I realized this could be counted as a repost but I just don't understand itemmeta stuff and couldn't understand how to do it
There are no pure bukkit api ways to do it. There are however custom libraries you can use to abstract alot of the NMS code if you don't want to write it. https://www.spigotmc.org/resources/nbt-api.7939/
I use spigot and I have safenbt but the problem is I ran into something it can't do. so I came here and I can't use the nbttagstring but now I am just using setstring so hopefully that works out asbukkitcopy doesn't work how would I change applecompound back into a itemstack @Machine Maker EDIT by Moderator: merged posts, please use the edit button instead of double posting.
If you are referring directly to that tutorial I linked, apple compound is an NBTCompound object, so you can't turn that into an item.You would do CraftItemStack.asBukkitCopy(nmsApple) to get back to a bukkit ItemStack
it is not working here is my code Code: ItemStack bottle = new ItemStack(Material.PLAYER_HEAD); ItemMeta itemmeta = bottle.getItemMeta(); itemmeta.addEnchant(Enchantment.MENDING, 1, true); itemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); net.minecraft.server.v1_15_R1.ItemStack nmsbottle = CraftItemStack.asNMSCopy(bottle); NBTTagCompound bottlecompound = (nmsbottle.hasTag()) ? nmsbottle.getTag() : new NBTTagCompound(); bottlecompound.setString("test1", "test2"); ShapedRecipe expBottle = new ShapedRecipe(CraftItemStack.asBukkitCopy(nmsbottle)); Material ink_sac = Material.INK_SAC; expBottle.shape("*%*","%B%","*!*"); expBottle.setIngredient('*', ink_sac); expBottle.setIngredient('%', Material.SUGAR); expBottle.setIngredient('B', Material.GLASS_BOTTLE); expBottle.setIngredient('!', Material.ACACIA_DOOR); getServer().addRecipe(expBottle); then my immports Code: import org.bukkit.Material; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import net.minecraft.server.v1_15_R1.NBTTagCompound;
Well the recipe output would not have the custom item meta you put on it (the exchange and the hide enchants flag) because you don't set the ItemMeta on the item to the new item meta. (bottle.setItemMeta(ItemMeta)) As for the NBT tag being on the output, it should work. I don't know if you were determining if it wasn't working simply by the enchant not being on the item. EDIT: oh WAIT, you need to add the NBTCompound back to the NMSItemStack nmsbottle.setTag(bottlecompound) This is all in that tutorial I linked.
thank you very much it works now the enchants don't work but that is because the player head can't have enchanted look on it sadly but that doesn't matter ok now I have the problem of setstring being annoying to where you have to have to strings and how would I tell it to write the nbt of SkullOwner:{Id:"198765c1-c236-4c7d-8555-d0dbacfcb123",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc2MmExNWIwNDY5MmEyZTRiM2ZiMzY2M2JkNGI3ODQzNGRjZTE3MzJiOGViMWM3YTlmN2MwZmJmNmYifX19"}]}}} because what setstring does is it takes the first string and puts a colon between them and then puts them together as the nbt EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You should still be able to put an enchantment on it... Make sure after you get the ItemMeta, add the enchantments, you then call setItemMeta() on the item to actually change the item meta.
@Machine Maker I can put a enchant on it but it won't work to show the enchant because head doesn't allow that which is fine I don't need enchant on it Edit: I still haven't found out how to use setstring to set nbt to SkullOwner:{Id:"198765c1-c236-4c7d-8555-d0dbacfcb123",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc2MmExNWIwNDY5MmEyZTRiM2ZiMzY2M2JkNGI3ODQzNGRjZTE3MzJiOGViMWM3YTlmN2MwZmJmNmYifX19"}]}}} edit2: I still can not find out how to because setInt does apostrophes and IDK what needs a string without being inside a curly bracket. the only thing I see that could work is set instead of setstring but IDK how to make a NBTTagString because it says not visible edit3: set doesn't work because it is basically the same thing as setString so and setInt so it isn't working edit4: if anyone knows how to set the texture of a head I would like to know