how would I set nbt

Discussion in 'Plugin Development' started by Cat 700, Mar 13, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Cat 700

    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"}]}}}
     
  2. Offline

    Machine Maker

  3. Offline

    Cat 700

    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
     
  4. Offline

    Machine Maker

  5. Offline

    Cat 700

    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.
     
    Last edited: Mar 13, 2020
  6. Offline

    Machine Maker

    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
     
  7. Offline

    Cat 700

    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;
     
  8. Offline

    Machine Maker

    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.
     
  9. Offline

    Cat 700

    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.
     
    Last edited by a moderator: Mar 13, 2020
  10. Offline

    Machine Maker

    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.
     
  11. Offline

    Cat 700

    @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
     
    Last edited: Mar 14, 2020
Thread Status:
Not open for further replies.

Share This Page