mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Refactor Rail handling to allow LSP-complaint shape handling
the reason there hasn't been any API until now is because of how inconvenient it was to expose a LSP-compliant API _and_ use the same base class for handling all the connection logic. This commit fixes that problem by abstracting shape handling away from BaseRail entirely, so that now it deals exclusively with connections. Deciding the shape of rail to use is now the job of the subclasses.
This commit is contained in:
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
class DetectorRail extends BaseRail{
|
||||
class DetectorRail extends StraightOnlyRail{
|
||||
protected bool $activated = false;
|
||||
|
||||
public function isActivated() : bool{ return $this->activated; }
|
||||
@ -34,22 +34,17 @@ class DetectorRail extends BaseRail{
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function readRailShapeFromMeta(int $stateMeta) : ?int{
|
||||
$stateMeta &= ~BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED;
|
||||
return isset(self::CONNECTIONS[$stateMeta]) ? $stateMeta : null;
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
parent::readStateFromData($id, $stateMeta & ~BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED);
|
||||
$this->activated = ($stateMeta & BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED) !== 0;
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return parent::writeStateToMeta() | ($this->activated ? BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED : 0);
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
parent::readStateFromData($id, $stateMeta);
|
||||
$this->activated = ($stateMeta & BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED) !== 0;
|
||||
}
|
||||
|
||||
protected function getCurrentShapeConnections() : array{
|
||||
return self::CONNECTIONS[$this->railShape];
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
Reference in New Issue
Block a user