mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-14 15:35:31 +00:00
TypeConverter: further simplification
This commit is contained in:
parent
c33f97ae41
commit
93a1e84ad9
@ -50,7 +50,6 @@ use pocketmine\player\GameMode;
|
|||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\AssumptionFailedError;
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use pocketmine\utils\SingletonTrait;
|
use pocketmine\utils\SingletonTrait;
|
||||||
use function array_key_exists;
|
|
||||||
|
|
||||||
class TypeConverter{
|
class TypeConverter{
|
||||||
use SingletonTrait;
|
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
|
* @throws TypeConversionException
|
||||||
*/
|
*/
|
||||||
@ -284,18 +272,20 @@ class TypeConverter{
|
|||||||
}
|
}
|
||||||
$pSlot = $action->inventorySlot;
|
$pSlot = $action->inventorySlot;
|
||||||
|
|
||||||
$craftingGrid = $player->getCraftingGrid();
|
$slot = UIInventorySlotOffset::CRAFTING2X2_INPUT[$pSlot] ?? null;
|
||||||
$slot = $this->mapUIInventory($pSlot, UIInventorySlotOffset::CRAFTING2X2_INPUT, true);
|
|
||||||
if($slot !== null){
|
if($slot !== null){
|
||||||
$window = $craftingGrid;
|
$window = $player->getCraftingGrid();
|
||||||
}elseif(($current = $player->getCurrentWindow()) !== null){
|
}elseif(($current = $player->getCurrentWindow()) !== null){
|
||||||
$slot =
|
$slotMap = match(true){
|
||||||
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ANVIL, $current instanceof AnvilInventory) ??
|
$current instanceof AnvilInventory => UIInventorySlotOffset::ANVIL,
|
||||||
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ENCHANTING_TABLE, $current instanceof EnchantInventory) ??
|
$current instanceof EnchantInventory => UIInventorySlotOffset::ENCHANTING_TABLE,
|
||||||
$this->mapUIInventory($pSlot, UIInventorySlotOffset::LOOM, $current instanceof LoomInventory) ??
|
$current instanceof LoomInventory => UIInventorySlotOffset::LOOM,
|
||||||
$this->mapUIInventory($pSlot, UIInventorySlotOffset::CRAFTING3X3_INPUT, $current instanceof CraftingTableInventory);
|
$current instanceof CraftingTableInventory => UIInventorySlotOffset::CRAFTING3X3_INPUT,
|
||||||
if($slot !== null){
|
default => null
|
||||||
|
};
|
||||||
|
if($slotMap !== null){
|
||||||
$window = $current;
|
$window = $current;
|
||||||
|
$slot = $slotMap[$pSlot] ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($slot === null){
|
if($slot === null){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user