22declare(strict_types=1);
27use pocketmine\block\utils\MobHeadType;
39 public const MIN_ROTATION = 0;
40 public const MAX_ROTATION = 15;
42 protected MobHeadType $mobHeadType = MobHeadType::SKELETON;
44 protected int $facing = Facing::NORTH;
45 protected int $rotation = self::MIN_ROTATION;
48 $w->enum($this->mobHeadType);
52 $w->facingExcept($this->facing,
Facing::DOWN);
56 parent::readStateFromWorld();
57 $tile = $this->position->getWorld()->getTile($this->position);
58 if($tile instanceof TileMobHead){
59 $this->mobHeadType = $tile->getMobHeadType();
60 $this->rotation = $tile->getRotation();
67 parent::writeStateToWorld();
69 $tile = $this->position->getWorld()->getTile($this->position);
70 assert($tile instanceof TileMobHead);
71 $tile->setRotation($this->rotation);
72 $tile->setMobHeadType($this->mobHeadType);
75 public function getMobHeadType() : MobHeadType{
76 return $this->mobHeadType;
81 $this->mobHeadType = $mobHeadType;
85 public function getFacing() : int{ return $this->facing; }
89 if($facing ===
Facing::DOWN){
90 throw new \InvalidArgumentException(
"Skull may not face DOWN");
92 $this->facing = $facing;
96 public function getRotation() : int{ return $this->rotation; }
100 if($rotation < self::MIN_ROTATION || $rotation > self::MAX_ROTATION){
101 throw new \InvalidArgumentException(
"Rotation must be in range " . self::MIN_ROTATION .
" ... " . self::MAX_ROTATION);
103 $this->rotation = $rotation;
112 ->contract(0.25, 0, 0.25)
114 if($this->facing !== Facing::UP){
115 $collisionBox = $collisionBox
117 ->offsetTowards(Facing::UP, 0.25);
119 return [$collisionBox];
123 if($face ===
Facing::DOWN){
127 $this->facing = $face;
128 if($player !==
null && $face === Facing::UP){
129 $this->rotation = ((int) floor(($player->getLocation()->getYaw() * 16 / 360) + 0.5)) & 0xf;
131 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
setRotation(int $rotation)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
recalculateCollisionBoxes()
describeBlockItemState(RuntimeDataDescriber $w)
setMobHeadType(MobHeadType $mobHeadType)
describeBlockOnlyState(RuntimeDataDescriber $w)
offsetTowards(int $face, float $distance)