Solved make an item comestible

Discussion in 'Plugin Development' started by danichef, Sep 25, 2016.

Thread Status:
Not open for further replies.
  1. How do i code to make an specific item comestible. I will also be interested if you could tell me if it could be with and specific skull.
    Thanks
     
  2. Offline

    Zombie_Striker

    @danichef
    There is no way to eat non-consumable items. If you want a player to eat an item, it has to already be a food item. You can, however, use resourcepacks to change the texture of the food items.

    For skulls, look into SkullMeta (for items) and Skull (for blocks)
     
  3. Offline

    Evonoucono

    @danichef
    You could use playerInteractEvent and check if the skull is right clicked. If it is you could add a food eating sound effect, remove one skull from the player's inventory and set the player's food bar a little higher.
     
  4. Atleast have the efect or look like there are plugins that has thingslike that
     
  5. @danichef

    To make the player "eat":
    You can check on interact and remove the item. You can also play particles and I'm pretty sure a sound but don't quote me on that. Particles would not be like MC though and wouldn't be able to represent the skull texture.

    To make the skull textured:
    You can do this yourself or use one of the existing heads found here. Look at my resource here to learn how to implement these into your plugin.
     
  6. Please if someone could give me an example i would be really grats
     
  7. Offline

    Zombie_Striker

    @danichef
    We are here to help you, not make your plugin for you. If that is what you want, post in the Plugin Requests forum.

    So far, we have told you everything you need to "eat" and to create skulls. If your problem has been solved, mark this thread as solved. If you have further questions on this topic, post below.
     
  8. Offline

    Evonoucono

    @danichef
    From what I was saying earlier, do something like this:

    Code:
                            if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                                ItemStack hand = p.getItemInHand();
                                if (hand.getType() == Material.SKULL){
                                    if (p.getFoodLevel() < 20){
                                        p.getWorld().playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1, 1);
    
                                        int restore = p.getFoodLevel() + 4;
                                        if (restore>20){
                                            restore = 20;
                                        }
                                        p.setFoodLevel(restore);
    
                                        if (hand.getAmount() > 1){
                                            hand.setAmount(hand.getAmount()-1);
                                        }else{
                                            p.setItemInHand(null);
                                        }
                                    }
                                }
                            }
    If you wanted to do something really fancy you could require the player to hold down their right mouse button for a second and constantly play that eating noise as it happens. Just increment an integer in a hashmap tied with each player when they right click, and when that integer hits 15 use the above code and reset that integer to 0. (not 100% if that would work though)
     
  9. Offline

    Zombie_Striker

    @Evonoucono
    Thanks captain spoonfeeder! BTW: If you don't know if your code will work, don't post it. (you know what, ignore the first part) Posting code that does not work will not help the OP.

    Also, remember that the item in the player's hand can be null, so you have to null check before getting the type.
     
  10. Offline

    Evonoucono

    @Zombie_Striker
    See that?
    But anyways, the code does work, just "SKULL" might need to be "SKULL_ITEM", depending on what he really wants. Anyways I find that spoon feeding better satisfies a majority of users on this forum, and he asked for an example, so I said, "well hey, I can do that!" so I did, and that was exactly what my code was; an example of how he should go about doing what I was talking about earlier.
     
  11. @Evonoucono
    The problem with that is, that if you just give fully working code, the OP will just copy and paste it into his IDE, and change some things, without knowing how the code actually worked, resulting in him not being able to do it the next time, and coming back here asking the exact same question again.
     
    Zombie_Striker and Lordloss like this.
  12. Thanks every one
    @AlvinB Im not creating a plugin im learning and i have friends that dont know about minecraft coding but they know general java coding.
     
  13. Offline

    Zombie_Striker

    @danichef
    If your problem has been solved, mark this thread as solved.

    BTW: if you're not creating a plugin, why are you asking these questions?
     
    timtower likes this.
  14. @Zombie_Striker Cause im trying to learn and then ill start making them
     
  15. Offline

    HeartandSoul

    Well, considering that you joined a few days ago, you wouldn't know, but that's not what this forum is for buddy:)
     
  16. Last edited by a moderator: Sep 28, 2016
Thread Status:
Not open for further replies.

Share This Page