Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class Block{

/**
* @internal
* Hardcoded int is `Binary::readLong(hash('xxh3', Binary::writeLLong(BlockTypeIds::AIR), binary: true))`
* Hardcoded int is `Binary::readLong(hash('xxh3', Binary::writeLLong(BlockTypeIds::AIR_TYPE_NUMBER), binary: true))`
* TODO: it would be much easier if we could just make this 0 or some other easy value
*/
public const EMPTY_STATE_ID = (BlockTypeIds::AIR << self::INTERNAL_STATE_DATA_BITS) | (-7482769108513497636 & self::INTERNAL_STATE_DATA_MASK);
public const EMPTY_STATE_ID = (BlockTypeIds::AIR_TYPE_NUMBER << self::INTERNAL_STATE_DATA_BITS) | (-7482769108513497636 & self::INTERNAL_STATE_DATA_MASK);

protected BlockIdentifier $idInfo;
protected string $fallbackName;
Expand Down Expand Up @@ -97,7 +97,7 @@ class Block{
* The type ID is included in the XOR mask. This is not necessary to improve distribution, but it reduces the number
* of operations required to compute the state ID (micro optimization).
*/
private static function computeStateIdXorMask(int $typeId) : int{
public static function computeStateIdXorMask(int $typeId) : int{
return
$typeId << self::INTERNAL_STATE_DATA_BITS |
(Binary::readLong(hash('xxh3', Binary::writeLLong($typeId), binary: true)) & self::INTERNAL_STATE_DATA_MASK);
Expand All @@ -120,7 +120,7 @@ public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo
$this->describeBlockOnlyState($calculator);
$this->requiredBlockOnlyStateDataBits = $calculator->getBitsUsed();

$this->stateIdXorMask = self::computeStateIdXorMask($idInfo->getBlockTypeId());
$this->stateIdXorMask = self::computeStateIdXorMask($idInfo->getBlockTypeNumber());

//this must be done last, otherwise the defaultState could have uninitialized fields
$defaultState = clone $this;
Expand Down Expand Up @@ -156,7 +156,7 @@ public function getName() : string{
*
* @see BlockTypeIds
*/
public function getTypeId() : int{
public function getTypeId() : string{
return $this->idInfo->getBlockTypeId();
}

Expand Down
15 changes: 10 additions & 5 deletions src/block/BlockIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@
use pocketmine\utils\Utils;

class BlockIdentifier{
private int $typeNumber;

/**
* @phpstan-param class-string<Tile>|null $tileClass
*/
public function __construct(
private int $blockTypeId,
private string $blockTypeId,
private ?string $tileClass = null
){
if($blockTypeId < 0){
throw new \InvalidArgumentException("Block type ID may not be negative");
}
$this->typeNumber = BlockTypeIds::lookupTypeNumberFromTypeId($this->blockTypeId);
if($tileClass !== null){
Utils::testValidInstance($tileClass, Tile::class);
}
}

public function getBlockTypeId() : int{ return $this->blockTypeId; }
public function getBlockTypeId() : string{ return $this->blockTypeId; }

/**
* @internal
*/
public function getBlockTypeNumber() : int{ return $this->typeNumber; }

/**
* @phpstan-return class-string<Tile>|null
Expand Down
Loading