41 private array $deserializeFuncs = [];
47 private array $simpleCache = [];
50 if(count($stateData->getStates()) === 0){
52 return $this->simpleCache[$stateData->getName()] ??= $this->deserializeToStateId($stateData);
56 return $this->deserializeToStateId($stateData);
59 private function deserializeToStateId(
BlockStateData $stateData) : int{
60 $stateId = $this->deserializeBlock($stateData)->getStateId();
63 if(!RuntimeBlockStateRegistry::getInstance()->hasStateId($stateId)){
64 throw new \LogicException(
"State ID $stateId returned by deserializer for " . $stateData->getName() .
" is not registered in RuntimeBlockStateRegistry");
70 public function map(
string $id, \Closure $c) : void{
71 $this->deserializeFuncs[$id] = $c;
72 $this->simpleCache = [];
82 return $this->deserializeFuncs[$id] ?? null;
87 $id = $blockStateData->getName();
88 if(!array_key_exists($id, $this->deserializeFuncs)){
91 $reader =
new Reader($blockStateData);
92 $block = $this->deserializeFuncs[$id]($reader);
93 $reader->checkUnreadProperties();