mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Nuke Block->meta, split into variant and state properties, lots of cleanup
This is a major change to the way block metadata is handled within the PM core. This separates variant metadata (which really ought to be part of the ID) from state metadata, and in a couple of cases flattens separate states of blocks together. The result of this is that invalid variants can be much more easily detected, and additionally state handling is much cleaner since meta is only needed at the serialize layer instead of throughout the code.
This commit is contained in:
@ -26,7 +26,23 @@ namespace pocketmine\block;
|
||||
class RedstoneRail extends BaseRail{
|
||||
protected const FLAG_POWERED = 0x08;
|
||||
|
||||
protected function getConnectionsForState() : array{
|
||||
return self::CONNECTIONS[$this->meta & ~self::FLAG_POWERED];
|
||||
/** @var bool */
|
||||
protected $powered = false;
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return parent::writeStateToMeta() | ($this->powered ? self::FLAG_POWERED : 0);
|
||||
}
|
||||
|
||||
public function readStateFromMeta(int $meta) : void{
|
||||
parent::readStateFromMeta($meta);
|
||||
$this->powered = ($meta & self::FLAG_POWERED) !== 0;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
protected function getConnectionsFromMeta(int $meta) : array{
|
||||
return self::CONNECTIONS[$meta & ~self::FLAG_POWERED] ?? [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user