Revert "Block: Get rid of state bitmasks"

This reverts commit b7b05e729e.

Apparently this was premature, because we still need these things to deal with default state remapping.
This commit is contained in:
Dylan K. Taylor
2019-02-24 18:30:18 +00:00
parent 6cb263fcca
commit 0f7f5362b8
53 changed files with 251 additions and 14 deletions

View File

@ -43,6 +43,8 @@ use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\tile\TileFactory;
use function array_merge;
use function assert;
use function dechex;
use function get_class;
use const PHP_INT_MAX;
@ -80,6 +82,9 @@ class Block extends Position implements BlockIds, Metadatable{
* @param string $name English name of the block type (TODO: implement translations)
*/
public function __construct(BlockIdentifier $idInfo, string $name){
if(($idInfo->getVariant() & $this->getStateBitmask()) !== 0){
throw new \InvalidArgumentException("Variant 0x" . dechex($idInfo->getVariant()) . " collides with state bitmask 0x" . dechex($this->getStateBitmask()));
}
$this->idInfo = $idInfo;
$this->fallbackName = $name;
}
@ -118,7 +123,9 @@ class Block extends Position implements BlockIds, Metadatable{
* @return int
*/
public function getDamage() : int{
return $this->idInfo->getVariant() | $this->writeStateToMeta();
$stateMeta = $this->writeStateToMeta();
assert(($stateMeta & ~$this->getStateBitmask()) === 0);
return $this->idInfo->getVariant() | $stateMeta;
}
protected function writeStateToMeta() : int{
@ -161,6 +168,15 @@ class Block extends Position implements BlockIds, Metadatable{
}
}
/**
* Returns a bitmask used to extract state bits from block metadata.
*
* @return int
*/
public function getStateBitmask() : int{
return 0;
}
/**
* Returns whether the given block has an equivalent type to this one. This compares base legacy ID and variant.
*