facing) | ($this->hasMap ? 0x04 : 0); } public function readStateFromData(int $id, int $stateMeta) : void{ $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($stateMeta & 0x03)); $this->hasMap = ($stateMeta & 0x04) !== 0; } public function readStateFromWorld() : void{ parent::readStateFromWorld(); $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ $this->framedItem = $tile->getItem(); if($this->framedItem->isNull()){ $this->framedItem = null; } $this->itemRotation = $tile->getItemRotation() % self::ROTATIONS; $this->itemDropChance = $tile->getItemDropChance(); } } public function writeStateToWorld() : void{ parent::writeStateToWorld(); $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ $tile->setItem($this->framedItem); $tile->setItemRotation($this->itemRotation); $tile->setItemDropChance($this->itemDropChance); } } public function getStateBitmask() : int{ return 0b111; } /** * @return int */ public function getFacing() : int{ return $this->facing; } /** * @param int $facing */ public function setFacing(int $facing) : void{ $this->facing = $facing; } /** * @return Item|null */ public function getFramedItem() : ?Item{ return $this->framedItem !== null ? clone $this->framedItem : null; } /** * @param Item|null $item */ public function setFramedItem(?Item $item) : void{ if($item === null or $item->isNull()){ $this->framedItem = null; $this->itemRotation = 0; }else{ $this->framedItem = clone $item; } } /** * @return int */ public function getItemRotation() : int{ return $this->itemRotation; } /** * @param int $itemRotation */ public function setItemRotation(int $itemRotation) : void{ $this->itemRotation = $itemRotation; } /** * @return float */ public function getItemDropChance() : float{ return $this->itemDropChance; } /** * @param float $itemDropChance */ public function setItemDropChance(float $itemDropChance) : void{ $this->itemDropChance = $itemDropChance; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->framedItem !== null){ $this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS; }elseif(!$item->isNull()){ $this->framedItem = $item->pop(); }else{ return true; } $this->level->setBlock($this, $this); return true; } public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ if($this->framedItem === null){ return false; } if(lcg_value() <= $this->itemDropChance){ $this->level->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem()); } $this->setFramedItem(null); $this->level->setBlock($this, $this); return true; } public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ $this->level->useBreakOn($this); } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::DOWN or $face === Facing::UP or !$blockClicked->isSolid()){ return false; } $this->facing = $face; return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getDropsForCompatibleTool(Item $item) : array{ $drops = parent::getDropsForCompatibleTool($item); if($this->framedItem !== null and lcg_value() <= $this->itemDropChance){ $drops[] = clone $this->framedItem; } return $drops; } public function getPickedItem() : Item{ return $this->framedItem !== null ? clone $this->framedItem : parent::getPickedItem(); } public function isAffectedBySilkTouch() : bool{ return false; } public function getHardness() : float{ return 0.25; } }