pocketmine\item\Item::getCustomBlockData PHP Method

getCustomBlockData() public method

public getCustomBlockData ( )
    public function getCustomBlockData()
    {
        if (!$this->hasCompoundTag()) {
            return null;
        }
        $tag = $this->getNamedTag();
        if (isset($tag->BlockEntityTag) and $tag->BlockEntityTag instanceof CompoundTag) {
            return $tag->BlockEntityTag;
        }
        return null;
    }

Usage Example

Example #1
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $pitch = $player->getPitch();
         if (abs($pitch) >= 45) {
             if ($pitch < 0) {
                 $f = 0;
             } else {
                 $f = 1;
             }
         } else {
             $f = $player->getDirection() + 2;
         }
     } else {
         $f = 0;
     }
     $faces = [0 => 0, 1 => 1, 2 => 4, 3 => 2, 4 => 5, 5 => 3];
     $this->meta = $faces[$f];
     $this->getLevel()->setBlock($block, $this, true, true);
     $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::DROPPER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
     $nbt->Items->setTagType(NBT::TAG_Compound);
     if ($item->hasCustomName()) {
         $nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
     }
     if ($item->hasCustomBlockData()) {
         foreach ($item->getCustomBlockData() as $key => $v) {
             $nbt->{$key} = $v;
         }
     }
     Tile::createTile(Tile::DROPPER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     return true;
 }
All Usage Examples Of pocketmine\item\Item::getCustomBlockData