RuntimeBlockMapping: avoid keeping two copies of the same blockstate data in memory

This commit is contained in:
Dylan K. Taylor 2022-07-10 17:41:01 +01:00
parent 14933a731b
commit 2ba51567d8
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -66,8 +66,11 @@ final class RuntimeBlockMapping{
private BlockStateDictionary $blockStateDictionary,
private BlockStateSerializer $blockStateSerializer
){
$this->fallbackStateData = new BlockStateData(BlockTypeNames::INFO_UPDATE, [], BlockStateData::CURRENT_VERSION);
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData($this->fallbackStateData) ?? throw new AssumptionFailedError(BlockTypeNames::INFO_UPDATE . " should always exist");
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData(
new BlockStateData(BlockTypeNames::INFO_UPDATE, [], BlockStateData::CURRENT_VERSION)
) ?? 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
$this->fallbackStateData = $this->blockStateDictionary->getDataFromStateId($this->fallbackStateId) ?? throw new AssumptionFailedError("We just looked up this state data, so it must exist");
}
public function toRuntimeId(int $internalStateId) : int{