mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-27 05:13:46 +00:00
BlockStateData: introduce and use current()
This commit is contained in:
parent
6b7a4e2c41
commit
da5302ca86
@ -117,7 +117,7 @@ final class CraftingManagerFromDataHelper{
|
|||||||
->read(ErrorToExceptionHandler::trapAndRemoveFalse(fn() => base64_decode($blockStatesRaw, true)))
|
->read(ErrorToExceptionHandler::trapAndRemoveFalse(fn() => base64_decode($blockStatesRaw, true)))
|
||||||
->mustGetCompoundTag()
|
->mustGetCompoundTag()
|
||||||
->getValue();
|
->getValue();
|
||||||
$blockStateData = new BlockStateData($blockName, $blockStatesTag, BlockStateData::CURRENT_VERSION);
|
$blockStateData = BlockStateData::current($blockName, $blockStatesTag);
|
||||||
}else{
|
}else{
|
||||||
$blockStateData = null;
|
$blockStateData = null;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,14 @@ final class BlockStateData{
|
|||||||
private int $version
|
private int $version
|
||||||
){}
|
){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Tag[] $states
|
||||||
|
* @phpstan-param array<string, Tag> $states
|
||||||
|
*/
|
||||||
|
public static function current(string $name, array $states) : self{
|
||||||
|
return new self($name, $states, self::CURRENT_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
public function getName() : string{ return $this->name; }
|
public function getName() : string{ return $this->name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -281,6 +281,6 @@ final class BlockStateWriter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockStateData() : BlockStateData{
|
public function getBlockStateData() : BlockStateData{
|
||||||
return new BlockStateData($this->id, $this->states, BlockStateData::CURRENT_VERSION);
|
return BlockStateData::current($this->id, $this->states);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ final class BlockDataUpgrader{
|
|||||||
$blockStateData = $this->upgradeStringIdMeta($id, $data);
|
$blockStateData = $this->upgradeStringIdMeta($id, $data);
|
||||||
if($blockStateData === null){
|
if($blockStateData === null){
|
||||||
//unknown block, invalid ID
|
//unknown block, invalid ID
|
||||||
$blockStateData = new BlockStateData(BlockTypeNames::INFO_UPDATE, [], BlockStateData::CURRENT_VERSION);
|
$blockStateData = BlockStateData::current(BlockTypeNames::INFO_UPDATE, []);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//Modern (post-1.13) blockstate
|
//Modern (post-1.13) blockstate
|
||||||
|
@ -63,7 +63,7 @@ final class RuntimeBlockMapping{
|
|||||||
private BlockStateSerializer $blockStateSerializer
|
private BlockStateSerializer $blockStateSerializer
|
||||||
){
|
){
|
||||||
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData(
|
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData(
|
||||||
new BlockStateData(BlockTypeNames::INFO_UPDATE, [], BlockStateData::CURRENT_VERSION)
|
BlockStateData::current(BlockTypeNames::INFO_UPDATE, [])
|
||||||
) ?? throw new AssumptionFailedError(BlockTypeNames::INFO_UPDATE . " should always exist");
|
) ?? throw new AssumptionFailedError(BlockTypeNames::INFO_UPDATE . " should always exist");
|
||||||
//lookup the state data from the dictionary to avoid keeping two copies of the same data around
|
//lookup the state data from the dictionary to avoid keeping two copies of the same data around
|
||||||
$this->fallbackStateData = $this->blockStateDictionary->getDataFromStateId($this->fallbackStateId) ?? throw new AssumptionFailedError("We just looked up this state data, so it must exist");
|
$this->fallbackStateData = $this->blockStateDictionary->getDataFromStateId($this->fallbackStateId) ?? throw new AssumptionFailedError("We just looked up this state data, so it must exist");
|
||||||
|
@ -84,6 +84,6 @@ final class GlobalBlockStateHandlers{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function getUnknownBlockStateData() : BlockStateData{
|
public static function getUnknownBlockStateData() : BlockStateData{
|
||||||
return self::$unknownBlockStateData ??= new BlockStateData(BlockTypeNames::INFO_UPDATE, [], BlockStateData::CURRENT_VERSION);
|
return self::$unknownBlockStateData ??= BlockStateData::current(BlockTypeNames::INFO_UPDATE, []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user