mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 15:19:56 +00:00
Change air tank regeneration to match UA (#2396)
This commit is contained in:
parent
8daf3dc8b4
commit
bea634a9b7
@ -665,13 +665,8 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
$this->attack($ev);
|
$this->attack($ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->canBreathe()){
|
if($this->doAirSupplyTick($tickDiff)){
|
||||||
$this->setBreathing(false);
|
|
||||||
$this->doAirSupplyTick($tickDiff);
|
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
}elseif(!$this->isBreathing()){
|
|
||||||
$this->setBreathing(true);
|
|
||||||
$this->setAirSupplyTicks($this->getMaxAirSupplyTicks());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,22 +695,42 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ticks the entity's air supply when it cannot breathe.
|
* Ticks the entity's air supply, consuming it when underwater and regenerating it when out of water.
|
||||||
|
*
|
||||||
* @param int $tickDiff
|
* @param int $tickDiff
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function doAirSupplyTick(int $tickDiff) : void{
|
protected function doAirSupplyTick(int $tickDiff) : bool{
|
||||||
|
$ticks = $this->getAirSupplyTicks();
|
||||||
|
$oldTicks = $ticks;
|
||||||
|
if(!$this->canBreathe()){
|
||||||
|
$this->setBreathing(false);
|
||||||
|
|
||||||
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
|
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
|
||||||
lcg_value() <= (1 / ($respirationLevel + 1))
|
lcg_value() <= (1 / ($respirationLevel + 1))
|
||||||
){
|
){
|
||||||
$ticks = $this->getAirSupplyTicks() - $tickDiff;
|
$ticks -= $tickDiff;
|
||||||
|
|
||||||
if($ticks <= -20){
|
if($ticks <= -20){
|
||||||
$this->setAirSupplyTicks(0);
|
$ticks = 0;
|
||||||
$this->onAirExpired();
|
$this->onAirExpired();
|
||||||
}else{
|
}
|
||||||
|
}
|
||||||
|
}elseif(!$this->isBreathing()){
|
||||||
|
if($ticks < ($max = $this->getMaxAirSupplyTicks())){
|
||||||
|
$ticks += $tickDiff * 5;
|
||||||
|
}
|
||||||
|
if($ticks >= $max){
|
||||||
|
$ticks = $max;
|
||||||
|
$this->setBreathing(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($ticks !== $oldTicks){
|
||||||
$this->setAirSupplyTicks($ticks);
|
$this->setAirSupplyTicks($ticks);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return $ticks !== $oldTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user