diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 00eeb3a9d..8f490c4aa 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -67,7 +67,7 @@ class Water extends Liquid{ public function onEntityCollide(Entity $entity) : void{ $entity->resetFallDistance(); - if($entity->fireTicks > 0){ + if($entity->isOnFire()){ $entity->extinguish(); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 0f3702c6c..3cade37c1 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -477,7 +477,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** @var int */ public $lastUpdate; /** @var int */ - public $fireTicks = 0; + protected $fireTicks = 0; /** @var CompoundTag */ public $namedtag; /** @var bool */ @@ -1093,8 +1093,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public function setOnFire(int $seconds) : void{ $ticks = $seconds * 20; - if($ticks > $this->fireTicks){ - $this->fireTicks = $ticks; + if($ticks > $this->getFireTicks()){ + $this->setFireTicks($ticks); } $this->setGenericFlag(self::DATA_FLAG_ONFIRE, true); @@ -1109,8 +1109,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** * @param int $fireTicks + * @throws \InvalidArgumentException */ public function setFireTicks(int $fireTicks) : void{ + if($fireTicks < 0 or $fireTicks > 0x7fff){ + throw new \InvalidArgumentException("Fire ticks must be in range 0 ... " . 0x7fff . ", got $fireTicks"); + } $this->fireTicks = $fireTicks; } @@ -2187,4 +2191,47 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public function __toString(){ return (new \ReflectionClass($this))->getShortName() . "(" . $this->getId() . ")"; } + + /** + * TODO: remove this BC hack in 4.0 + * + * @param string $name + * + * @return mixed + * @throws \ErrorException + */ + public function __get($name){ + if($name === "fireTicks"){ + return $this->fireTicks; + } + throw new \ErrorException("Undefined property: " . get_class($this) . "::\$" . $name); + } + + /** + * TODO: remove this BC hack in 4.0 + * + * @param string $name + * @param mixed $value + * + * @throws \ErrorException + * @throws \InvalidArgumentException + */ + public function __set($name, $value){ + if($name === "fireTicks"){ + $this->setFireTicks($value); + }else{ + throw new \ErrorException("Undefined property: " . get_class($this) . "::\$" . $name); + } + } + + /** + * TODO: remove this BC hack in 4.0 + * + * @param string $name + * + * @return bool + */ + public function __isset($name){ + return $name === "fireTicks"; + } } diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index fd561a968..c1bb3e881 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -319,7 +319,7 @@ abstract class Projectile extends Entity{ $entityHit->attack($ev); - if($this->fireTicks > 0){ + if($this->isOnFire()){ $ev = new EntityCombustByEntityEvent($this, $entityHit, 5); $ev->call(); if(!$ev->isCancelled()){