mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
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:
@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user