block: added constants for various integer property bounds

This commit is contained in:
Dylan K. Taylor
2022-01-28 21:27:30 +00:00
parent 466b018319
commit 0642364a44
20 changed files with 107 additions and 79 deletions

View File

@ -36,6 +36,7 @@ use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Cactus extends Transparent{
public const MAX_AGE = 15;
protected int $age = 0;
@ -44,7 +45,7 @@ class Cactus extends Transparent{
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 15);
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, self::MAX_AGE);
}
public function getStateBitmask() : int{
@ -55,8 +56,8 @@ class Cactus extends Transparent{
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 15){
throw new \InvalidArgumentException("Age must be in range 0-15");
if($age < 0 || $age > self::MAX_AGE){
throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE);
}
$this->age = $age;
return $this;
@ -101,7 +102,7 @@ class Cactus extends Transparent{
public function onRandomTick() : void{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
if($this->age === 15){
if($this->age === self::MAX_AGE){
for($y = 1; $y < 3; ++$y){
if(!$this->position->getWorld()->isInWorld($this->position->x, $this->position->y + $y, $this->position->z)){
break;