CraftingTransaction: Don't hardcode crafting grid sizes

This commit is contained in:
Dylan K. Taylor
2017-11-28 17:13:23 +00:00
parent 98ac6fc7be
commit 878f1bffb9
3 changed files with 8 additions and 4 deletions

View File

@ -25,7 +25,7 @@ namespace pocketmine\inventory;
class BigCraftingGrid extends CraftingGrid{ class BigCraftingGrid extends CraftingGrid{
public function getDefaultSize() : int{ public function getGridWidth() : int{
return 9; return 3;
} }
} }

View File

@ -31,8 +31,12 @@ class CraftingGrid extends BaseInventory{
parent::__construct($holder); parent::__construct($holder);
} }
public function getGridWidth() : int{
return 2;
}
public function getDefaultSize() : int{ public function getDefaultSize() : int{
return 4; return $this->getGridWidth() ** 2;
} }
public function setSize(int $size){ public function setSize(int $size){

View File

@ -46,7 +46,7 @@ class CraftingTransaction extends InventoryTransaction{
protected $recipe = null; protected $recipe = null;
public function __construct(Player $source, $actions = []){ public function __construct(Player $source, $actions = []){
$this->gridSize = ($source->getCraftingGrid() instanceof BigCraftingGrid) ? 3 : 2; $this->gridSize = $source->getCraftingGrid()->getGridWidth();
$air = ItemFactory::get(Item::AIR, 0, 0); $air = ItemFactory::get(Item::AIR, 0, 0);
$this->inputs = array_fill(0, $this->gridSize, array_fill(0, $this->gridSize, $air)); $this->inputs = array_fill(0, $this->gridSize, array_fill(0, $this->gridSize, $air));