mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +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[][] $input
|
||||||
* @param Item[][] $output
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function matchItems(array $input, array $output) : bool{
|
private function matchInputMap(array $input) : bool{
|
||||||
$map = $this->getIngredientMap();
|
$map = $this->getIngredientMap();
|
||||||
|
|
||||||
//match the given items to the requested items
|
//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
|
//check if there are any items left in the grid outside of the recipe
|
||||||
//however, we DO need to check if there are too many items in the grid outside of the recipe
|
/** @var Item[] $row */
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Item[] $row
|
|
||||||
*/
|
|
||||||
foreach($input as $y => $row){
|
foreach($input as $y => $row){
|
||||||
foreach($row as $x => $needItem){
|
foreach($row as $x => $needItem){
|
||||||
if(!$needItem->isNull()){
|
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:
|
//and then, finally, check that the output items are good:
|
||||||
|
|
||||||
/** @var Item[] $haveItems */
|
/** @var Item[] $haveItems */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user