Rail: store shape instead of connections

shape is what we'll eventually expose on the API.
This commit is contained in:
Dylan K. Taylor
2021-07-22 16:45:42 +01:00
parent 77138c5c06
commit 2476f40cc6
4 changed files with 35 additions and 23 deletions

View File

@ -34,6 +34,11 @@ 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;
}
protected function writeStateToMeta() : int{
return parent::writeStateToMeta() | ($this->activated ? BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED : 0);
}
@ -43,8 +48,8 @@ class DetectorRail extends BaseRail{
$this->activated = ($stateMeta & BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED) !== 0;
}
protected function getConnectionsFromMeta(int $meta) : ?array{
return self::CONNECTIONS[$meta & ~BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED] ?? null;
protected function getCurrentShapeConnections() : array{
return self::CONNECTIONS[$this->railShape];
}
//TODO