Creating Custom ItemMeta

Discussion in 'Plugin Development' started by ChrisixStudios, Dec 31, 2012.

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


    Is there an easier way to create an custom ItemMeta without using the

    public class CustomMeta implements ItemMeta

    and another question is general ItemMeta used that all Materials can go into so then I belive you can use

    public class CustomMeta extends GeneralItemMeta

    Any information on this topic?
  2. Offline


    i dont get what your asking...

    you can create ItemMeta inside any method of your code...
  3. Offline


    But how can you create a custom ItemMeta that can hold special objects or is that what lore is for?
  4. Offline


    Creating custom ItemMeta won't do anything. ItemMeta is just a bridge for NBTTags and I'm pretty sure that the servers only saves the NBTTag variables that the specific thing that is being saved uses so if you were to put in a custom integer tag in an ItemStack when the server is reloaded/shut-down/restarted you would loose that tag. And if you just wanted that then it would be easier to use Metadata.

    What were you wanting to do with it I could probably help you find an alternative that would work properly.
  5. Offline


    Well I am creating a gun mod for my dad and I might be putting it public, I need it to store the number of rounds in that gun (which is the ItemStack). I want it so even if you have the same type of gun it will have different rounds. I also want it so that if you give another player that ItemStack it still has all it's properties.

    I believe this is what the lore is used for but if not, what is lore used for anyway?
  6. Offline


    lore is just what is displayed under the name and enchantments. For a potion it shows the potion type and time and for leather armor it tells you if it is dyed or not.

    lore should work for what you want to do though. If you need help with how to set it up just ask. otherwise I'll just leave you with that.
  7. Offline


    Is there a way to do it so it doesn't show?
  8. Offline


    If you want each separate gun to have it's own ammo count that could get very difficult. You could try keeping track of each ItemStack but on a server restart you would have to find them again and there is the possibility that it would cause memory leaks if you store the ItemStacks directly but you could use Metadata but that is lost on a server restart also

    EDIT: actually you could use Metadata on the ItemStack then when a player logs out you loop through their inventory and the add up all of the bullets that they have in any slot that they have a gun in and also do that for any remaining players in your onDisable() method and then save all of that in a config file.
  9. Offline


    I guess it would be fine if it is showing. All I need in to lore is the first lore to be Gun and the second to be rounds because the way I have it now creates and GunEntity and saves that to file and reloads it which is a pain. So i'' just have it showing. Thanks!
  10. Offline


    I did this pre-1.4.6 while working on a custom item system. The custom NBT data seemed to get saved between restarts, unless it didn't and I completely failed to notice it (even if it doesnt save in between restarts, this would be quite useful). Anyways, I haven't had a chance to look into it for 1.4.6 yet, all I know is that it broke the whole system I used to store and edit the tags, so will need to figure out another way to do it... I will post back here when I figure it out

    Okay, this "should" work. I haven't tested it out though.

    To set it:
    net.minecraft.server.v1_4_6.ItemStack nmsstack = CraftItemStack.asNMSCopy(new ItemStack(Material.DIAMOND_SWORD));
    nmsstack.tag.setInt("testint", 10);
    org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nmsstack);
    Then to get it:

    net.minecraft.server.v1_4_6.ItemStack nmsstack = CraftItemStack.asNMSCopy(is);
    int testint = nmsstack.tag.getInt("testint");

    P.S. Sorry for the double post, its 3:30 am and i'm lazy.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 30, 2016
  11. Offline


    With this code, I really wanna keep it just bukkit.jar and not use the craftbukkit which is where you get the CraftItemStack. It is a good idea but I already got my system done.
  12. Offline


    Okay, no problem. I don't think it is possible to add custom data to items without CraftBukkit though, anyways, I am going to be using this for fixing a few plugins so I am happy either way. Good luck with your plugin!
  13. Offline


    Thanks you too! And i am just using the Lore and parsing it to the object I need.
Thread Status:
Not open for further replies.

Share This Page