PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
Rail.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
27use pocketmine\block\utils\RailShape;
30
31class Rail extends BaseRail{
32
33 private RailShape $railShape = RailShape::FLAT_AXIS_Z;
34
35 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
36 $w->enum($this->railShape);
37 }
38
39 protected function setShapeFromConnections(array $connections) : void{
40 $railShape = self::searchState($connections, RailConnectionInfo::CONNECTIONS) ?? self::searchState($connections, RailConnectionInfo::CURVE_CONNECTIONS);
41 if($railShape === null){
42 throw new \InvalidArgumentException("No rail shape matches these connections");
43 }
44 $this->railShape = RailShape::from($railShape);
45 }
46
47 protected function getCurrentShapeConnections() : array{
48 return RailConnectionInfo::CURVE_CONNECTIONS[$this->railShape->value] ?? RailConnectionInfo::CONNECTIONS[$this->railShape->value];
49 }
50
51 protected function getPossibleConnectionDirectionsOneConstraint(int $constraint) : array{
52 $possible = parent::getPossibleConnectionDirectionsOneConstraint($constraint);
53
54 if(($constraint & RailConnectionInfo::FLAG_ASCEND) === 0){
55 foreach([
56 Facing::NORTH,
57 Facing::SOUTH,
58 Facing::WEST,
59 Facing::EAST
60 ] as $d){
61 if($constraint !== $d->value){
62 $possible[$d->value] = true;
63 }
64 }
65 }
66
67 return $possible;
68 }
69
70 public function getShape() : RailShape{ return $this->railShape; }
71
73 public function setShape(RailShape $shape) : self{
74 $this->railShape = $shape;
75 return $this;
76 }
77}
setShape(RailShape $shape)
Definition Rail.php:73
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Rail.php:35
setShapeFromConnections(array $connections)
Definition Rail.php:39
getPossibleConnectionDirectionsOneConstraint(int $constraint)
Definition Rail.php:51