mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 06:25:32 +00:00
Living: extract an applyConsumptionResults() method from consumeObject()
inspired by #3592, which has gone stale
This commit is contained in:
parent
15401d740f
commit
aefaf73685
@ -300,17 +300,20 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){
|
if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if($consumable instanceof FoodSource && $consumable->requiresHunger() and !$this->isHungry()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::consumeObject($consumable);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function applyConsumptionResults(Consumable $consumable) : void{
|
||||||
if($consumable instanceof FoodSource){
|
if($consumable instanceof FoodSource){
|
||||||
if($consumable->requiresHunger() and !$this->isHungry()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addFood($consumable->getFoodRestore());
|
$this->addFood($consumable->getFoodRestore());
|
||||||
$this->addSaturation($consumable->getSaturationRestore());
|
$this->addSaturation($consumable->getSaturationRestore());
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::consumeObject($consumable);
|
parent::applyConsumptionResults($consumable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,13 +363,20 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->applyConsumptionResults($consumable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies effects from consuming the object. This shouldn't do any can-consume checks (those are expected to be
|
||||||
|
* handled by the caller).
|
||||||
|
*/
|
||||||
|
protected function applyConsumptionResults(Consumable $consumable) : void{
|
||||||
foreach($consumable->getAdditionalEffects() as $effect){
|
foreach($consumable->getAdditionalEffects() as $effect){
|
||||||
$this->addEffect($effect);
|
$this->addEffect($effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
$consumable->onConsume($this);
|
$consumable->onConsume($this);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user