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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block
;
25
26
use
pocketmine\block\utils\RailConnectionInfo
;
27
use pocketmine\block\utils\RailShape;
28
use
pocketmine\data\runtime\RuntimeDataDescriber
;
29
use
pocketmine\math\Facing
;
30
31
class
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
}
pocketmine\block\BaseRail
Definition
BaseRail.php:38
pocketmine\block\Rail
Definition
Rail.php:31
pocketmine\block\Rail\setShape
setShape(RailShape $shape)
Definition
Rail.php:73
pocketmine\block\Rail\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Rail.php:35
pocketmine\block\Rail\getCurrentShapeConnections
getCurrentShapeConnections()
Definition
Rail.php:47
pocketmine\block\Rail\setShapeFromConnections
setShapeFromConnections(array $connections)
Definition
Rail.php:39
pocketmine\block\Rail\getPossibleConnectionDirectionsOneConstraint
getPossibleConnectionDirectionsOneConstraint(int $constraint)
Definition
Rail.php:51
pocketmine\block\utils\RailConnectionInfo
Definition
RailConnectionInfo.php:29
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
Rail.php
Generated by
1.12.0