40 private array $networkIdCache = [];
44 private int $fallbackStateId;
46 public function __construct(
50 $this->fallbackStateData = BlockStateData::current(BlockTypeNames::INFO_UPDATE, []);
51 $this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData($this->fallbackStateData) ??
55 public function internalIdToNetworkId(
int $internalStateId) :
int{
56 if(isset($this->networkIdCache[$internalStateId])){
57 return $this->networkIdCache[$internalStateId];
61 $blockStateData = $this->blockStateSerializer->serialize($internalStateId);
63 $networkId = $this->blockStateDictionary->lookupStateIdFromData($blockStateData);
64 if($networkId ===
null){
65 throw new AssumptionFailedError(
"Unmapped blockstate returned by blockstate serializer: " . $blockStateData->toNbt());
70 $networkId = $this->fallbackStateId;
73 return $this->networkIdCache[$internalStateId] = $networkId;
83 $networkRuntimeId = $this->internalIdToNetworkId($internalStateId);
85 return $this->blockStateDictionary->generateDataFromStateId($networkRuntimeId) ??
throw new AssumptionFailedError(
"We just looked up this state ID, so it must exist");
88 public function getBlockStateDictionary() :
BlockStateDictionary{ return $this->blockStateDictionary; }
90 public function getFallbackStateData() : BlockStateData{ return $this->fallbackStateData; }