InventoryManager: reduce code duplication

This commit is contained in:
Dylan K. Taylor 2021-10-29 15:37:52 +01:00
parent fb5543a2ad
commit 88b7389080
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -166,27 +166,21 @@ class InventoryManager{
//if the class isn't final, not to mention being inflexible. //if the class isn't final, not to mention being inflexible.
if($inv instanceof BlockInventory){ if($inv instanceof BlockInventory){
$blockPosition = BlockPosition::fromVector3($inv->getHolder()); $blockPosition = BlockPosition::fromVector3($inv->getHolder());
switch(true){ $windowType = match(true){
case $inv instanceof LoomInventory: $inv instanceof LoomInventory => WindowTypes::LOOM,
return [ContainerOpenPacket::blockInv($id, WindowTypes::LOOM, $blockPosition)]; $inv instanceof FurnaceInventory => match($inv->getFurnaceType()->id()){
case $inv instanceof FurnaceInventory: FurnaceType::FURNACE()->id() => WindowTypes::FURNACE,
return match($inv->getFurnaceType()->id()){ FurnaceType::BLAST_FURNACE()->id() => WindowTypes::BLAST_FURNACE,
FurnaceType::FURNACE()->id() => [ContainerOpenPacket::blockInv($id, WindowTypes::FURNACE, $blockPosition)], FurnaceType::SMOKER()->id() => WindowTypes::SMOKER,
FurnaceType::BLAST_FURNACE()->id() => [ContainerOpenPacket::blockInv($id, WindowTypes::BLAST_FURNACE, $blockPosition)],
FurnaceType::SMOKER()->id() => [ContainerOpenPacket::blockInv($id, WindowTypes::SMOKER, $blockPosition)],
default => throw new AssumptionFailedError("Unreachable") default => throw new AssumptionFailedError("Unreachable")
}; },
case $inv instanceof EnchantInventory: $inv instanceof EnchantInventory => WindowTypes::ENCHANTMENT,
return [ContainerOpenPacket::blockInv($id, WindowTypes::ENCHANTMENT, $blockPosition)]; $inv instanceof BrewingStandInventory => WindowTypes::BREWING_STAND,
case $inv instanceof BrewingStandInventory: $inv instanceof AnvilInventory => WindowTypes::ANVIL,
return [ContainerOpenPacket::blockInv($id, WindowTypes::BREWING_STAND, $blockPosition)]; $inv instanceof HopperInventory => WindowTypes::HOPPER,
case $inv instanceof AnvilInventory: default => WindowTypes::CONTAINER
return [ContainerOpenPacket::blockInv($id, WindowTypes::ANVIL, $blockPosition)]; };
case $inv instanceof HopperInventory: return [ContainerOpenPacket::blockInv($id, $windowType, $blockPosition)];
return [ContainerOpenPacket::blockInv($id, WindowTypes::HOPPER, $blockPosition)];
default:
return [ContainerOpenPacket::blockInv($id, WindowTypes::CONTAINER, $blockPosition)];
}
} }
return null; return null;
} }