Replace disallowed operators in src/crafting/

This commit is contained in:
Dylan K. Taylor
2022-01-20 19:18:26 +00:00
parent aa6bd4438a
commit 3f8f5cd200
3 changed files with 8 additions and 8 deletions

View File

@ -62,14 +62,14 @@ class ShapedRecipe implements CraftingRecipe{
*/
public function __construct(array $shape, array $ingredients, array $results){
$this->height = count($shape);
if($this->height > 3 or $this->height <= 0){
if($this->height > 3 || $this->height <= 0){
throw new \InvalidArgumentException("Shaped recipes may only have 1, 2 or 3 rows, not $this->height");
}
$shape = array_values($shape);
$this->width = strlen($shape[0]);
if($this->width > 3 or $this->width <= 0){
if($this->width > 3 || $this->width <= 0){
throw new \InvalidArgumentException("Shaped recipes may only have 1, 2 or 3 columns, not $this->width");
}
@ -79,7 +79,7 @@ class ShapedRecipe implements CraftingRecipe{
}
for($x = 0; $x < $this->width; ++$x){
if($row[$x] !== ' ' and !isset($ingredients[$row[$x]])){
if($row[$x] !== ' ' && !isset($ingredients[$row[$x]])){
throw new \InvalidArgumentException("No item specified for symbol '" . $row[$x] . "'");
}
}
@ -172,7 +172,7 @@ class ShapedRecipe implements CraftingRecipe{
$given = $grid->getIngredient($reverse ? $this->width - $x - 1 : $x, $y);
$required = $this->getIngredient($x, $y);
if(!$required->equals($given, !$required->hasAnyDamageValue(), $required->hasNamedTag()) or $required->getCount() > $given->getCount()){
if(!$required->equals($given, !$required->hasAnyDamageValue(), $required->hasNamedTag()) || $required->getCount() > $given->getCount()){
return false;
}
}
@ -182,10 +182,10 @@ class ShapedRecipe implements CraftingRecipe{
}
public function matchesCraftingGrid(CraftingGrid $grid) : bool{
if($this->width !== $grid->getRecipeWidth() or $this->height !== $grid->getRecipeHeight()){
if($this->width !== $grid->getRecipeWidth() || $this->height !== $grid->getRecipeHeight()){
return false;
}
return $this->matchInputMap($grid, false) or $this->matchInputMap($grid, true);
return $this->matchInputMap($grid, false) || $this->matchInputMap($grid, true);
}
}