How I set the value of hunger recovery on new food?

Discussion in 'Plugin Development' started by xMinecraft, May 4, 2013.

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

    xMinecraft

    I create a new food "toast" and I want to pick up 3 of starvation.
    How I set the value of hunger recovery?

    Code:java
    1. public final class main extends JavaPlugin implements Listener {
    2. public ItemStack toast;
    3. public final Logger logger = Logger.getLogger("Minecraft");
    4. private FurnaceRecipe toast2;
    5.  
    6. @Override
    7. public void onEnable() {
    8. ItemStack is2;
    9. ItemMeta meta2;
    10. Server server = this.getServer();
    11. server.getPluginManager().registerEvents(this, this);
    12.  
    13. is2 = new ItemStack(Material.BREAD, 1);
    14. meta2 = is2.getItemMeta();
    15. meta2.setDisplayName(ChatColor.GOLD + "Pan Tostao");
    16. is2.setItemMeta(meta2);
    17. toast = is2;
    18.  
    19. toast2 = new FurnaceRecipe(toast, Material.BREAD).setInput(Material.BREAD);
    20.  
    21. server.addRecipe(toast2);
    22.  
    23. }
    24. }


    Regards.
     
  2. Offline

    MCForger

    xMinecraft
    You could listen to the consume event and say if the bread is toast set the hunger level +3
     
  3. Offline

    xMinecraft

    MCForger how? sorry but i don't speak english very good and i don't understand xd

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    xMinecraft

    Digi do you know?
     
  5. xMinecraft
    Use PlayerItemConsumeEvent and check if consumed item's name is Toast and then cancel it, remove one item from the held amount (or set to null if he only has 1) and add to the player's hunger.
     
  6. Offline

    xMinecraft

    Digi thanks man :)
    I'll see PlayerItemConsumeEvent
     
Thread Status:
Not open for further replies.

Share This Page