mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Added handling for reflected ShapedRecipe crafting, close #1415
This commit is contained in:
parent
86b76bfcab
commit
c448f4a3b5
@ -202,11 +202,10 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
|
||||
/**
|
||||
* @param Item[][] $input
|
||||
* @param Item[][] $output
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchItems(array $input, array $output) : bool{
|
||||
private function matchInputMap(array $input) : bool{
|
||||
$map = $this->getIngredientMap();
|
||||
|
||||
//match the given items to the requested items
|
||||
@ -223,12 +222,8 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
}
|
||||
}
|
||||
|
||||
//we shouldn't need to check if there's anything left in the map, the last block should take care of that
|
||||
//however, we DO need to check if there are too many items in the grid outside of the recipe
|
||||
|
||||
/**
|
||||
* @var Item[] $row
|
||||
*/
|
||||
//check if there are any items left in the grid outside of the recipe
|
||||
/** @var Item[] $row */
|
||||
foreach($input as $y => $row){
|
||||
foreach($row as $x => $needItem){
|
||||
if(!$needItem->isNull()){
|
||||
@ -237,6 +232,23 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item[][] $input
|
||||
* @param Item[][] $output
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchItems(array $input, array $output) : bool{
|
||||
if(
|
||||
!$this->matchInputMap($input) and //as-is
|
||||
!$this->matchInputMap(array_map(function(array $row) : array{ return array_reverse($row, false); }, $input)) //mirrored
|
||||
){
|
||||
return false;
|
||||
}
|
||||
|
||||
//and then, finally, check that the output items are good:
|
||||
|
||||
/** @var Item[] $haveItems */
|
||||
|
Loading…
x
Reference in New Issue
Block a user