Custom Item Bug

  • Hi @red51


    Custom items are bloody awesome addition <3 thank you! I'm sure the folk on Medieval Realms are going to love getting their gemstones in their inventory instead of instantly being converted to cash.


    One problem though, the stacks spit fine, but when you try to stack them back up they won't stack until you close the inventory down and re-open up. A wee bug I think?


  • Hehe, this looks really promising! :thumbup:
    Unfortunately I wasn't able to reproduce this issue, but I've already made some changes to the custom item handling (maybe that bug was fixed as a side effect)^^ A new hotfix will be available tomorrow, if you still experience any custom item related issues with it, please let me know ;)

  • Hot darn, look at that! Nice Succinite! Sorry to derail your thread; I'm a gemologist by trade and an avid fan of games, so when the two come together, I get a little giddy. People get minerals on your server? That's awesome!

  • A new hotfix will be available tomorrow


    Thanks for the heads up! Yep one gemstone down, 9 more to go. :thumbsup:



    People get minerals on your server?


    Yep, there have been gemstones for quite some time now but they were instantly sold. Red's new update makes it way more fun now as they go into your inventory instead. :saint:

  • Hi @red51 I'm using this code to add gems to a players inventory:



    Java
    Inventory inventory = player.getInventory();
    inventory.insertNewCustomItem(EMERALD, 1, 1, 1,
    Inventory.SlotType.Inventory);

    When a player finds a gemstone and they currently do not have one in their inventory the notification shows correct ( 1x Emerald * )



    However, the second one found shows up at ( 2x Emerald * ) even though only one is added to the inventory (meaning they now have 2).


  • However, the second one found shows up at ( 2x Emerald * ) even though only one is added to the inventory (meaning they now have 2).

    If a 2nd item (of the same type, no matter if it's a vanilla or custom item) is added to the inventory within 1-2 seconds, the "1x item" label just gets updated ;) That's actually intended. The reason for this is that there are sometimes situations in which many items are added to the inventory in a short time, and an updated label showing the total amount of items is sometimes more useful in these situations than several "1x" labels ^^

  • Just to confirm, I tried again on a clean server restart (i.e. no reloadplugins command used). I found one Emerald then stopped (I actually went away and grabbed a coffee) I came back and continued mining and found a second Emerald. Although (correctly) I had one more added to my inventory the lower right hand corner notification said I had found 2x Emerald.


    This is the code snippet I am using to add custom item to inventory:


    Java
    Inventory inventory = player.getInventory();
    inventory.insertNewCustomItem(EMERALD, 1, 1, 1,
    Inventory.SlotType.Inventory);
  • Oh, well that's not supposed to happen =O I will check out what's going on there!
    The code looks fine btw, but you should only use "1" as variation if there is more than 1 variation defined for your item (otherwise, the default variation is 0) ;)

  • Sorry @red51 yet another message!


    The method:

    Java
    //method 1
    inventory.insertNewCustomItem(EMERALD, 0, 1);


    Work well for adding new custom items to the inventory (in the first available free slot or stacks if item already exists), however, it does not generate the nice inventory addition notification/animation on the lower right hand corner of the screen.



    The following method does generate a nice notification/animation on the lower right hand corner;



    Java
    //method 2
    inventory.insertNewCustomItem(EMERALD, 0, 1, 0, Inventory.SlotType.Inventory);


    However, the above second method requires that I specify a slot (in my examples case - slot 0) the result of which is the item already occupying the slot(0) gets deleted.


    Now I have tried writing some code to analyse the inventory (so I can use method 2) so I can allocate the correct slot (or stack if needed), however using item.getName() I simply get "apiitem" which isn't going to work.


    The ideal solution would be a notification/animation on method 1.


    Or, a new method like method 1;



    Java
    //method 3
    inventory.insertNewCustomItemWithGuiFeedback(EMERALD, 0, 1);




    :D

  • however using item.getName() I simply get "apiitem"


    Hmm this is actually causing some roadblock for me. I can't work with the items I've added as I have no means to differentiate between them.


    The names, including definition name are all "apiitem" and the getTypeID are all the same at 890. =O


    Edit: I can't even hack around it using different max stack sizes as the event.getItem().getMaxStacksize() for all custom items return 1 even though that's not the set max stack size.

  • Work well for adding new custom items to the inventory (in the first available free slot or stacks if item already exists), however, it does not generate the nice inventory addition notification/animation on the lower right hand corner of the screen.

    Oh, thanks for letting me know! This seems to be a general issue with the "insertNewItem()" methods (not only affecting custom items) =O


    The names, including definition name are all "apiitem" and the getTypeID are all the same at 890

    Yes, that's intended. Internally there is a universal "apiitem" which is used by every custom item. This way the game makes sure there are no collision between item id's, and in addition to that, the game is still runnable if stop using a certain custom item plugin (while there are still custom items in your inventories or chests) ;)
    The game distinguishes individual custom items via the item attribute. Every custom item has a CustomItemAttribute (which can be received with Item.getAttribute()). You can add individual attributes to your CustomItemAttribute (this way you can store additional information per item), for example:


    You can also get the UUID from the CustomItemAttribute. This way you can get the actual CustomItem definition from the server:

    Java
    Item.CustomItemAttribute attribute = (Item.CustomItemAttribute) item.getAttribute();
    CustomItem customItemDef = getServer().getCustomItem(attribute.getUUID());
    //Probably it's always a good idea to do a null check
    if(customItemDef != null){
    String itemname = customItemDef.getName();
    int maxStackSize = customItemDef.getMaxStacksize();
    }

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!