PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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\data\bedrock\block\BlockLegacyMetadata
;
28
use
pocketmine\data\runtime\RuntimeDataDescriber
;
29
use
pocketmine\math\Facing
;
30
use
function
array_keys;
31
use
function
implode;
32
33
class
Rail
extends
BaseRail
{
34
35
private
int
$railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
36
37
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
38
$w->railShape($this->railShape);
39
}
40
41
protected
function
setShapeFromConnections
(array $connections) : void{
42
$railShape = self::searchState($connections,
RailConnectionInfo
::CONNECTIONS) ?? self::searchState($connections,
RailConnectionInfo
::CURVE_CONNECTIONS);
43
if
($railShape ===
null
){
44
throw
new \InvalidArgumentException(
"No rail shape matches these connections"
);
45
}
46
$this->railShape = $railShape;
47
}
48
49
protected
function
getCurrentShapeConnections
() : array{
50
return
RailConnectionInfo
::CURVE_CONNECTIONS[$this->railShape] ??
RailConnectionInfo
::CONNECTIONS[$this->railShape];
51
}
52
53
protected
function
getPossibleConnectionDirectionsOneConstraint
(
int
$constraint) : array{
54
$possible = parent::getPossibleConnectionDirectionsOneConstraint($constraint);
55
56
if
(($constraint & RailConnectionInfo::FLAG_ASCEND) === 0){
57
foreach
([
58
Facing::NORTH,
59
Facing::SOUTH,
60
Facing::WEST,
61
Facing::EAST
62
] as $d){
63
if
($constraint !== $d){
64
$possible[$d] =
true
;
65
}
66
}
67
}
68
69
return
$possible;
70
}
71
72
public
function
getShape() : int{ return $this->railShape; }
73
75
public
function
setShape
(
int
$shape) : self{
76
if(!isset(
RailConnectionInfo
::CONNECTIONS[$shape]) && !isset(
RailConnectionInfo
::CURVE_CONNECTIONS[$shape])){
77
throw
new \InvalidArgumentException(
"Invalid shape, must be one of "
. implode(
", "
, [...array_keys(RailConnectionInfo::CONNECTIONS), ...array_keys(RailConnectionInfo::CURVE_CONNECTIONS)]));
78
}
79
$this->railShape = $shape;
80
return
$this;
81
}
82
}
pocketmine\block\BaseRail
Definition
BaseRail.php:38
pocketmine\block\Rail
Definition
Rail.php:33
pocketmine\block\Rail\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Rail.php:37
pocketmine\block\Rail\getCurrentShapeConnections
getCurrentShapeConnections()
Definition
Rail.php:49
pocketmine\block\Rail\setShapeFromConnections
setShapeFromConnections(array $connections)
Definition
Rail.php:41
pocketmine\block\Rail\getPossibleConnectionDirectionsOneConstraint
getPossibleConnectionDirectionsOneConstraint(int $constraint)
Definition
Rail.php:53
pocketmine\block\Rail\setShape
setShape(int $shape)
Definition
Rail.php:75
pocketmine\block\utils\RailConnectionInfo
Definition
RailConnectionInfo.php:29
pocketmine\data\bedrock\block\BlockLegacyMetadata
Definition
BlockLegacyMetadata.php:29
pocketmine\math\Facing
Definition
Facing.php:28
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
src
block
Rail.php
Generated by
1.12.0