pocketmine\block\Rail::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)
    {
        $downBlock = $this->getSide(Vector3::SIDE_DOWN);
        if ($downBlock instanceof Rail or !$this->isBlock($downBlock)) {
            //判断是否可以放置
            return false;
        }
        $arrayXZ = [[1, 0], [0, 1], [-1, 0], [0, -1]];
        $arrayY = [0, 1, -1];
        /** @var Vector3 [] $connected */
        $connected = [];
        foreach ($arrayXZ as $xz) {
            $x = $xz[0];
            $z = $xz[1];
            foreach ($arrayY as $y) {
                $v3 = (new Vector3($x, $y, $z))->add($this);
                $block = $this->level->getBlock($v3);
                if ($block instanceof Rail) {
                    if ($block->connect($this)) {
                        $connected[] = $v3;
                        break;
                    }
                }
            }
            if (count($connected) == 2) {
                break;
            }
        }
        switch (count($connected)) {
            case 1:
                $v3 = $connected[0]->subtract($this);
                $this->meta = $v3->y != 1 ? $v3->x == 0 ? 0 : 1 : ($v3->z == 0 ? $v3->x / -2 + 2.5 : $v3->z / 2 + 4.5);
                break;
            case 2:
                $subtract = [];
                foreach ($connected as $key => $value) {
                    $subtract[$key] = $value->subtract($this);
                }
                if (abs($subtract[0]->x) == abs($subtract[1]->z) and abs($subtract[1]->x) == abs($subtract[0]->z)) {
                    $v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this));
                    $this->meta = $v3->x == 1 ? $v3->z == 1 ? 6 : 9 : ($v3->z == 1 ? 7 : 8);
                } elseif ($subtract[0]->y == 1 or $subtract[1]->y == 1) {
                    $v3 = $subtract[0]->y == 1 ? $subtract[0] : $subtract[1];
                    $this->meta = $v3->x == 0 ? $v3->z == -1 ? 4 : 5 : ($v3->x == 1 ? 2 : 3);
                } else {
                    $this->meta = $subtract[0]->x == 0 ? 0 : 1;
                }
                break;
            default:
                break;
        }
        $this->level->setBlock($this, Block::get($this->id, $this->meta), true, true);
        return true;
    }