Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Food source

Comments in 'Plugin Development' started by TryoneLegendZzz, Apr 10, 2016.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    i want to make it where when u eat it heals your health not hunger bar is this possible via plugin?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  3. Heroata
    Offline

    Heroata New Member

    Joined:
    Dec 15, 2013
    Posts:
    31
    Minecraft User:
    Heroata
    PHP:
    $player->setHealth($player->getHealth() + 3);
    Just an idea. But if you use this completely; when player's health is 20, bad things gonna happens.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    if(($player->getHealth() + 3) < $player->getMaxHealth()){
       
    $player->setHealth($player->getMaxHealth());
    } else {
       
    $player->setHealth($player->getHealth() + 3);
    }
    Heroata likes this.
  5. Heroata
    Offline

    Heroata New Member

    Joined:
    Dec 15, 2013
    Posts:
    31
    Minecraft User:
    Heroata
    Better :D
  6. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    Found a way but thanks!
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Atleast share how you did it for people who might have the same question in the future.
    Vaivez66 likes this.
  8. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    At first I thought the title said "Food Sauce".
    minebuilder0110 likes this.
  9. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    Here is the code sorry!
    PHP:
    $this->items = [
                
    Item::APPLE => 4,
                
    Item::MUSHROOM_STEW => 6,
                
    Item::BEETROOT_SOUP => 5,
                
    Item::BREAD => 5,
                
    Item::RAW_PORKCHOP => 2,
                
    Item::COOKED_PORKCHOP => 8,
                
    Item::RAW_BEEF => 3,
                
    Item::STEAK => 8,
                
    Item::COOKED_CHICKEN => 6,
                
    Item::RAW_CHICKEN => 2,
                
    Item::MELON_SLICE => 2,
                
    Item::GOLDEN_APPLE => 4,
                
    Item::PUMPKIN_PIE => 8,
                
    Item::CARROT => 3,
                
    Item::POTATO => 1,
                
    Item::BAKED_POTATO => 5,
                
    Item::COOKIE => 2,
                
    Item::COOKED_FISH => [
                    
    => 5,
                    
    => 6
                
    ],
                
    Item::RAW_FISH => [
                    
    => 2,
                    
    => 2,
                    
    => 1,
                    
    => 1
                
    ],
                
    Item::POTION => 0,
                
    Item::ROTTEN_FLESH => 4
            
    ];
    public function 
    onHeal(EntityRegainHealthEvent $ev){
            if(
    $ev->getRegainReason() === EntityRegainHealthEvent::CAUSE_SATURATION){
                
    $ev->setCancelled();
            }
        }
       
        public function 
    onEat(PlayerItemConsumeEvent $ev){
            
    $e = new EntityRegainHealthEvent($ev->getPlayer(), $this->items[$ev->getItem()->getId()], EntityRegainHealthEvent::CAUSE_REGEN);
            
    $ev->getPlayer()->setHealth($ev->getPlayer()->getHealth() + $e->getAmount());
        }
    Vaivez66 likes this.

Share This Page

Advertisement