mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 19:59:11 +00:00
Item: added getStateId(), removed state data from public API
state data was only used for indexing stuff along with state ID anyway, so it makes more sense to lock it away in here instead.
This commit is contained in:
@@ -55,6 +55,7 @@ use function count;
|
||||
use function gettype;
|
||||
use function hex2bin;
|
||||
use function is_string;
|
||||
use function morton2d_encode;
|
||||
|
||||
class Item implements \JsonSerializable{
|
||||
use ItemEnchantmentHandlingTrait;
|
||||
@@ -469,7 +470,11 @@ class Item implements \JsonSerializable{
|
||||
return $this->identifier->getTypeId();
|
||||
}
|
||||
|
||||
final public function computeStateData() : int{
|
||||
final public function getStateId() : int{
|
||||
return morton2d_encode($this->identifier->getTypeId(), $this->computeStateData());
|
||||
}
|
||||
|
||||
private function computeStateData() : int{
|
||||
$writer = new RuntimeDataWriter(16); //TODO: max bits should be a constant instead of being hardcoded all over the place
|
||||
$this->describeState($writer);
|
||||
return $writer->getValue();
|
||||
@@ -630,8 +635,7 @@ class Item implements \JsonSerializable{
|
||||
* @param bool $checkCompound Whether to verify that the items' NBT match.
|
||||
*/
|
||||
final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{
|
||||
return $this->getTypeId() === $item->getTypeId() &&
|
||||
$this->computeStateData() === $item->computeStateData() &&
|
||||
return $this->getStateId() === $item->getStateId() &&
|
||||
(!$checkCompound || $this->getNamedTag()->equals($item->getNamedTag()));
|
||||
}
|
||||
|
||||
|
@@ -1540,7 +1540,7 @@ final class StringToItemParser extends StringToTParser{
|
||||
public function register(string $alias, \Closure $callback) : void{
|
||||
parent::register($alias, $callback);
|
||||
$item = $callback($alias);
|
||||
$this->reverseMap[$item->getTypeId()][$item->computeStateData()][$alias] = true;
|
||||
$this->reverseMap[$item->getStateId()][$alias] = true;
|
||||
}
|
||||
|
||||
/** @phpstan-param \Closure(string $input) : Block $callback */
|
||||
@@ -1559,7 +1559,7 @@ final class StringToItemParser extends StringToTParser{
|
||||
* @phpstan-return list<string>
|
||||
*/
|
||||
public function lookupAliases(Item $item) : array{
|
||||
$aliases = $this->reverseMap[$item->getTypeId()][$item->computeStateData()] ?? [];
|
||||
$aliases = $this->reverseMap[$item->getStateId()] ?? [];
|
||||
return array_keys($aliases);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user