mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Replace disallowed operators in src/crafting/
This commit is contained in:
parent
aa6bd4438a
commit
3f8f5cd200
@ -96,7 +96,7 @@ abstract class CraftingGrid extends SimpleInventory{
|
|||||||
* Returns the item at offset x,y, offset by where the starts of the recipe rectangle are.
|
* Returns the item at offset x,y, offset by where the starts of the recipe rectangle are.
|
||||||
*/
|
*/
|
||||||
public function getIngredient(int $x, int $y) : Item{
|
public function getIngredient(int $x, int $y) : Item{
|
||||||
if($this->startX !== null and $this->startY !== null){
|
if($this->startX !== null && $this->startY !== null){
|
||||||
return $this->getItem(($y + $this->startY) * $this->gridWidth + ($x + $this->startX));
|
return $this->getItem(($y + $this->startY) * $this->gridWidth + ($x + $this->startX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ class ShapedRecipe implements CraftingRecipe{
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $shape, array $ingredients, array $results){
|
public function __construct(array $shape, array $ingredients, array $results){
|
||||||
$this->height = count($shape);
|
$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");
|
throw new \InvalidArgumentException("Shaped recipes may only have 1, 2 or 3 rows, not $this->height");
|
||||||
}
|
}
|
||||||
|
|
||||||
$shape = array_values($shape);
|
$shape = array_values($shape);
|
||||||
|
|
||||||
$this->width = strlen($shape[0]);
|
$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");
|
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){
|
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] . "'");
|
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);
|
$given = $grid->getIngredient($reverse ? $this->width - $x - 1 : $x, $y);
|
||||||
$required = $this->getIngredient($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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,10 +182,10 @@ class ShapedRecipe implements CraftingRecipe{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function matchesCraftingGrid(CraftingGrid $grid) : bool{
|
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->matchInputMap($grid, false) or $this->matchInputMap($grid, true);
|
return $this->matchInputMap($grid, false) || $this->matchInputMap($grid, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ class ShapelessRecipe implements CraftingRecipe{
|
|||||||
|
|
||||||
foreach($this->ingredients as $needItem){
|
foreach($this->ingredients as $needItem){
|
||||||
foreach($input as $j => $haveItem){
|
foreach($input as $j => $haveItem){
|
||||||
if($haveItem->equals($needItem, !$needItem->hasAnyDamageValue(), $needItem->hasNamedTag()) and $haveItem->getCount() >= $needItem->getCount()){
|
if($haveItem->equals($needItem, !$needItem->hasAnyDamageValue(), $needItem->hasNamedTag()) && $haveItem->getCount() >= $needItem->getCount()){
|
||||||
unset($input[$j]);
|
unset($input[$j]);
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user