facing) | ($this->hasMap ? BlockLegacyMetadata::ITEM_FRAME_FLAG_HAS_MAP : 0); } public function readStateFromData(int $id, int $stateMeta) : void{ $this->facing = BlockDataSerializer::read5MinusHorizontalFacing($stateMeta); $this->hasMap = ($stateMeta & BlockLegacyMetadata::ITEM_FRAME_FLAG_HAS_MAP) !== 0; } public function readStateFromWorld() : void{ parent::readStateFromWorld(); $tile = $this->pos->getWorld()->getTile($this->pos); 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->pos->getWorld()->getTile($this->pos); if($tile instanceof TileItemFrame){ $tile->setItem($this->framedItem); $tile->setItemRotation($this->itemRotation); $tile->setItemDropChance($this->itemDropChance); } } public function getStateBitmask() : int{ return 0b111; } public function getFacing() : int{ return $this->facing; } public function setFacing(int $facing) : void{ $this->facing = $facing; } public function getFramedItem() : ?Item{ return $this->framedItem !== null ? clone $this->framedItem : null; } public function setFramedItem(?Item $item) : void{ if($item === null or $item->isNull()){ $this->framedItem = null; $this->itemRotation = 0; }else{ $this->framedItem = clone $item; } } public function getItemRotation() : int{ return $this->itemRotation; } public function setItemRotation(int $itemRotation) : void{ $this->itemRotation = $itemRotation; } public function getItemDropChance() : float{ return $this->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->pos->getWorld()->setBlock($this->pos, $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->pos->getWorld()->dropItem($this->pos->add(0.5, 0.5, 0.5), $this->getFramedItem()); } $this->setFramedItem(null); $this->pos->getWorld()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ $this->pos->getWorld()->useBreakOn($this->pos); } } public function place(BlockTransaction $tx, 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($tx, $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(bool $addUserData = false) : Item{ return $this->framedItem !== null ? clone $this->framedItem : parent::getPickedItem($addUserData); } public function isAffectedBySilkTouch() : bool{ return false; } }