TypeConverter: further simplification

This commit is contained in:
Dylan K. Taylor 2021-11-08 20:27:53 +00:00
parent c33f97ae41
commit 93a1e84ad9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -50,7 +50,6 @@ use pocketmine\player\GameMode;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\SingletonTrait;
use function array_key_exists;
class TypeConverter{
use SingletonTrait;
@ -246,17 +245,6 @@ class TypeConverter{
}
}
/**
* @param int[] $test
* @phpstan-param array<int, int> $test
*/
protected function mapUIInventory(int $slot, array $test, bool $valid) : ?int{
if(array_key_exists($slot, $test) && $valid){
return $test[$slot];
}
return null;
}
/**
* @throws TypeConversionException
*/
@ -284,18 +272,20 @@ class TypeConverter{
}
$pSlot = $action->inventorySlot;
$craftingGrid = $player->getCraftingGrid();
$slot = $this->mapUIInventory($pSlot, UIInventorySlotOffset::CRAFTING2X2_INPUT, true);
$slot = UIInventorySlotOffset::CRAFTING2X2_INPUT[$pSlot] ?? null;
if($slot !== null){
$window = $craftingGrid;
$window = $player->getCraftingGrid();
}elseif(($current = $player->getCurrentWindow()) !== null){
$slot =
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ANVIL, $current instanceof AnvilInventory) ??
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ENCHANTING_TABLE, $current instanceof EnchantInventory) ??
$this->mapUIInventory($pSlot, UIInventorySlotOffset::LOOM, $current instanceof LoomInventory) ??
$this->mapUIInventory($pSlot, UIInventorySlotOffset::CRAFTING3X3_INPUT, $current instanceof CraftingTableInventory);
if($slot !== null){
$slotMap = match(true){
$current instanceof AnvilInventory => UIInventorySlotOffset::ANVIL,
$current instanceof EnchantInventory => UIInventorySlotOffset::ENCHANTING_TABLE,
$current instanceof LoomInventory => UIInventorySlotOffset::LOOM,
$current instanceof CraftingTableInventory => UIInventorySlotOffset::CRAFTING3X3_INPUT,
default => null
};
if($slotMap !== null){
$window = $current;
$slot = $slotMap[$pSlot] ?? null;
}
}
if($slot === null){