Age blocks logic moved into dedicated trait (#5962)

This commit is contained in:
ShockedPlot7560
2023-09-08 13:25:26 +02:00
committed by GitHub
parent d3ab516ba4
commit d60fca0a1c
12 changed files with 92 additions and 196 deletions

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\AgeableTrait;
use pocketmine\block\utils\BlockEventHelper;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\block\utils\SupportType;
@ -41,27 +42,15 @@ use function mt_rand;
class CocoaBlock extends Transparent{
use HorizontalFacingTrait;
use AgeableTrait;
public const MAX_AGE = 2;
protected int $age = 0;
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > self::MAX_AGE){
throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE);
}
$this->age = $age;
return $this;
}
/**
* @return AxisAlignedBB[]
*/