Fixed crash when opening crafting table and other 'UI' inventories

This commit is contained in:
Dylan K. Taylor 2023-03-20 22:00:38 +00:00
parent 758b5ee500
commit c9601ae67d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -141,10 +141,6 @@ class InventoryManager{
}
private function addDynamic(Inventory $inventory) : int{
if(isset($this->inventories[spl_object_id($inventory)])){
throw new \InvalidArgumentException("Inventory " . get_class($inventory) . " is already tracked");
}
$this->inventories[spl_object_id($inventory)] = new InventoryManagerEntry($inventory);
$id = $this->getNewWindowId();
$this->add($id, $inventory);
return $id;
@ -168,6 +164,17 @@ class InventoryManager{
}
}
/**
* @param int[]|int $slotMap
* @phpstan-param array<int, int>|int $slotMap
*/
private function addComplexDynamic(array|int $slotMap, Inventory $inventory) : int{
$this->addComplex($slotMap, $inventory);
$id = $this->getNewWindowId();
$this->associateIdWithInventory($id, $inventory);
return $id;
}
private function remove(int $id) : void{
$inventory = $this->networkIdToInventoryMap[$id];
unset($this->networkIdToInventoryMap[$id]);
@ -296,9 +303,10 @@ class InventoryManager{
$this->onCurrentWindowRemove();
$this->openWindowDeferred(function() use ($inventory) : void{
$windowId = $this->addDynamic($inventory);
if(($slotMap = $this->createComplexSlotMapping($inventory)) !== null){
$this->addComplex($slotMap, $inventory);
$windowId = $this->addComplexDynamic($slotMap, $inventory);
}else{
$windowId = $this->addDynamic($inventory);
}
foreach($this->containerOpenCallbacks as $callback){