public function __construct(Item $result, ...$shape)
{
if (count($shape) === 0) {
throw new \InvalidArgumentException("Must provide a shape");
}
if (count($shape) > 3) {
throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
}
foreach ($shape as $y => $row) {
if (strlen($row) === 0 or strlen($row) > 3) {
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row));
}
$this->ingredients[] = array_fill(0, strlen($row), null);
$len = strlen($row);
for ($i = 0; $i < $len; ++$i) {
$this->shape[$row[$i]] = null;
if (!isset($this->shapeItems[$row[$i]])) {
$this->shapeItems[$row[$i]] = [new Vector2($i, $y)];
} else {
$this->shapeItems[$row[$i]][] = new Vector2($i, $y);
}
}
}
$this->output = clone $result;
}