Development Assistance Comparing Custom ItemStacks

Discussion in 'Plugin Help/Development/Requests' started by Comt, Mar 2, 2016.

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

    Comt

    I've added several itemstacks to a class, and given them recipes, lore, and new names. (For example: ItemStack A = new ItemStack(Material.DIAMOND_HELMET, 1); then I've simply reconfigured the lore) However, I'm not sure how to compare the custom item to a vanilla one, because I'm not sure if they are really that different.

    Would itemStack A be equivalent to an actual Diamond Helmet? If so, how could I differentiate without simply checking for the custom Display Name?
     
  2. Offline

    mine-care

    That is quite broad really,

    Well lets narrow it down a bit, and supose you want to compare the itemstack a player right clicked with to a custom ItemStack called 'customItem'.
    You can use either the .equals(Object param) method, or the .matches(ItemStack param) method (The difference can be found here) to check if the ItemStack the player was holding is the custom one.
     
  3. Offline

    drew6017

    Whenever you are facing a situation like this, ask yourself "What defines them as different?". Other than the obvious fact that they are two different instances in two different locations of ram. You should have lore, name, material, etc. come to mind. If you want to check just if it is a Diamond Helmet, get the material and compare just that. I would not use the equals method in this scenario.
     
Thread Status:
Not open for further replies.

Share This Page