22declare(strict_types=1);
 
   28use pocketmine\block\utils\AnyFacingTrait;
 
   29use pocketmine\block\utils\SupportType;
 
   40use 
function is_infinite;
 
   46    public const ROTATIONS = 8;
 
   48    protected bool $hasMap = 
false; 
 
   50    protected ?
Item $framedItem = 
null;
 
   51    protected int $itemRotation = 0;
 
   52    protected float $itemDropChance = 1.0;
 
   55        $w->facing($this->facing);
 
   56        $w->bool($this->hasMap);
 
 
   60        parent::readStateFromWorld();
 
   61        $tile = $this->position->getWorld()->getTile($this->position);
 
   62        if($tile instanceof TileItemFrame){
 
   63            $this->framedItem = $tile->getItem();
 
   64            if($this->framedItem->isNull()){
 
   65                $this->framedItem = 
null;
 
   67            $this->itemRotation = $tile->getItemRotation() % self::ROTATIONS;
 
   68            $this->itemDropChance = $tile->getItemDropChance();
 
 
   75        parent::writeStateToWorld();
 
   76        $tile = $this->position->getWorld()->getTile($this->position);
 
   77        if($tile instanceof TileItemFrame){
 
   78            $tile->setItem($this->framedItem);
 
   79            $tile->setItemRotation($this->itemRotation);
 
   80            $tile->setItemDropChance($this->itemDropChance);
 
 
   84    public function getFramedItem() : ?Item{
 
   85        return $this->framedItem !== null ? clone $this->framedItem : null;
 
   90        if($item === null || $item->isNull()){
 
   91            $this->framedItem = 
null;
 
   92            $this->itemRotation = 0;
 
   94            $this->framedItem = clone $item;
 
 
   99    public function getItemRotation() : int{
 
  100        return $this->itemRotation;
 
  105        $this->itemRotation = $itemRotation;
 
 
  109    public function getItemDropChance() : float{
 
  110        return $this->itemDropChance;
 
  115        if($itemDropChance < 0.0 || $itemDropChance > 1.0 || is_nan($itemDropChance) || is_infinite($itemDropChance)){
 
  116            throw new \InvalidArgumentException(
"Drop chance must be in range 0-1");
 
  118        $this->itemDropChance = $itemDropChance;
 
 
  122    public function hasMap() : bool{ return $this->hasMap; }
 
  131        $this->hasMap = $hasMap;
 
 
  136        if($this->framedItem !== null){
 
  137            $this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS;
 
  140        }elseif(!$item->isNull()){
 
  141            $this->framedItem = $item->pop();
 
  148        $this->position->getWorld()->setBlock($this->position, $this);
 
 
  154        if($this->framedItem === null){
 
  157        $world = $this->position->getWorld();
 
  158        if(Utils::getRandomFloat() <= $this->itemDropChance){
 
  159            $world->dropItem($this->position->add(0.5, 0.5, 0.5), clone $this->framedItem);
 
  162        $this->setFramedItem(
null);
 
  163        $world->setBlock($this->position, $this);
 
 
  167    private function canBeSupportedAt(Block $block, 
int $face) : bool{
 
  168        return $block->getAdjacentSupportType($face) !== SupportType::NONE;
 
  172        if(!$this->canBeSupportedAt($this, 
Facing::opposite($this->facing))){
 
  173            $this->position->getWorld()->useBreakOn($this->position);
 
 
  178        if(!$this->canBeSupportedAt($blockReplace, 
Facing::opposite($face))){
 
  182        $this->facing = $face;
 
  184        return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
 
 
  188        $drops = parent::getDropsForCompatibleTool($item);
 
  189        if($this->framedItem !== 
null && Utils::getRandomFloat() <= $this->itemDropChance){
 
  190            $drops[] = clone $this->framedItem;
 
 
  197        return $this->framedItem !== null ? clone $this->framedItem : parent::getPickedItem($addUserData);
 
 
 
onAttack(Item $item, int $face, ?Player $player=null)
 
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
 
describeBlockOnlyState(RuntimeDataDescriber $w)
 
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
 
setFramedItem(?Item $item)
 
getPickedItem(bool $addUserData=false)
 
setItemDropChance(float $itemDropChance)
 
setItemRotation(int $itemRotation)
 
getDropsForCompatibleTool(Item $item)