pocketmine\block\Chest::place PHP Метод

place() публичный Метод

public place ( Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null )
$item pocketmine\item\Item
$block Block
$target Block
$player pocketmine\Player
    public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
    {
        $faces = [0 => 4, 1 => 2, 2 => 5, 3 => 3];
        $chest = null;
        $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
        for ($side = 2; $side <= 5; ++$side) {
            if (($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)) {
                continue;
            } elseif (($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)) {
                continue;
            }
            $c = $this->getSide($side);
            if ($c instanceof Chest and $c->getDamage() === $this->meta) {
                $tile = $this->getLevel()->getTile($c);
                if ($tile instanceof TileChest and !$tile->isPaired()) {
                    $chest = $tile;
                    break;
                }
            }
        }
        $this->getLevel()->setBlock($block, $this, true, true);
        $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), 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 = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
        if ($chest instanceof TileChest and $tile instanceof TileChest) {
            $chest->pairWith($tile);
            $tile->pairWith($chest);
        }
        return true;
    }