Getting/Setting item food values

Discussion in 'Plugin Development' started by Mats391, Jul 10, 2014.

Thread Status:
Not open for further replies.
  1. Hi,
    i currently am working on a plugin that changes the food values of some items and adds some new custom ones (just changing display name). My problem is to read or even set the values for individual item stacks. Bukkit doesnt help at all there :(
    I already tried using NBT apis like PowerNBT or by using craftbukkit methods directy, but no success. The closest i got was using this bit of code:

    1. ItemStack item;
    3. if(CraftItemStack.asNMSCopy(item).getItem() instanceof ItemFood)
    4. {
    5. ItemFood food = (ItemFood) CraftItemStack.asNMSCopy(item).getItem();
    6. food.getNutrition(null);
    7. food.getSaturationModifier(null);
    8. }

    But this does not work for fish... I also dont know what the parameter on the get-methods is about. It wants a minecraft itemstack, but it works with "null".
    If noone has any ideas, i do have a somewhat ugly workaround planned. For that i would just always cancel the consume event and apply my food values from config. Would be annoying, but might be the only way :(

  2. Offline


    How about changing your code and making it change the effects on PlayerEatFoodEvent (or whatever it's called :p)
  3. Yea thats what i meant with my workaround: Canceleing the default one and writing my own code to handle the event. But if possible i would like to not do that as it would require a map with all foods and their nutrition values which is quite annoying to make :p
  4. Offline


    Make a CustomFood object.
    Make it have the fields:
    Then on playereatevent, somehow get the info that way?...
Thread Status:
Not open for further replies.

Share This Page