Clean up hierarchy of rails

detector rail has fundamentally different functionality than activator and powered rails, so it's misleading to present the same APIs for both.
detector rail's 'powered' state is better referred to as 'activated', since it means the detector rail is actually _producing_ power, and not _receiving_ power.
This commit is contained in:
Dylan K. Taylor
2021-02-05 21:25:34 +00:00
parent 6ccfe21d57
commit 4fc3bc53f7
5 changed files with 71 additions and 7 deletions

View File

@ -23,7 +23,29 @@ declare(strict_types=1);
namespace pocketmine\block;
class DetectorRail extends RedstoneRail{
class DetectorRail extends BaseRail{
protected bool $activated = false;
public function isActivated() : bool{ return $this->activated; }
/** @return $this */
public function setActivated(bool $activated) : self{
$this->activated = $activated;
return $this;
}
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 getConnectionsFromMeta(int $meta) : ?array{
return self::CONNECTIONS[$meta & ~BlockLegacyMetadata::REDSTONE_RAIL_FLAG_POWERED] ?? null;
}
//TODO
}