mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
CraftingTransaction: Start from pre-computed iteration count for input matching
This will be faster to bail out on failures.
This commit is contained in:
parent
ef2dd1de92
commit
033b44df5a
@ -44,11 +44,11 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
* @param Item[] $txItems
|
* @param Item[] $txItems
|
||||||
* @param Item[] $recipeItems
|
* @param Item[] $recipeItems
|
||||||
* @param bool $wildcards
|
* @param bool $wildcards
|
||||||
|
* @param int $iterations
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
* @throws TransactionValidationException
|
|
||||||
*/
|
*/
|
||||||
protected function matchRecipeItems(array $txItems, array $recipeItems, bool $wildcards) : int{
|
protected function matchRecipeItems(array $txItems, array $recipeItems, bool $wildcards, int $iterations = 0) : int{
|
||||||
if(empty($recipeItems)){
|
if(empty($recipeItems)){
|
||||||
throw new TransactionValidationException("No recipe items given");
|
throw new TransactionValidationException("No recipe items given");
|
||||||
}
|
}
|
||||||
@ -56,7 +56,6 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
throw new TransactionValidationException("No transaction items given");
|
throw new TransactionValidationException("No transaction items given");
|
||||||
}
|
}
|
||||||
|
|
||||||
$iterations = 0;
|
|
||||||
while(!empty($recipeItems)){
|
while(!empty($recipeItems)){
|
||||||
/** @var Item $recipeItem */
|
/** @var Item $recipeItem */
|
||||||
$recipeItem = array_pop($recipeItems);
|
$recipeItem = array_pop($recipeItems);
|
||||||
@ -120,7 +119,7 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
try{
|
try{
|
||||||
$this->repetitions = $this->matchRecipeItems($this->outputs, $this->recipe->getResultsFor($this->source->getCraftingGrid()), false);
|
$this->repetitions = $this->matchRecipeItems($this->outputs, $this->recipe->getResultsFor($this->source->getCraftingGrid()), false);
|
||||||
|
|
||||||
if(($inputIterations = $this->matchRecipeItems($this->inputs, $this->recipe->getIngredientList(), true)) !== $this->repetitions){
|
if(($inputIterations = $this->matchRecipeItems($this->inputs, $this->recipe->getIngredientList(), true, $this->repetitions)) !== $this->repetitions){
|
||||||
throw new TransactionValidationException("Tried to craft recipe $this->repetitions times in batch, but have enough inputs for $inputIterations");
|
throw new TransactionValidationException("Tried to craft recipe $this->repetitions times in batch, but have enough inputs for $inputIterations");
|
||||||
}
|
}
|
||||||
}catch(\InvalidStateException $e){
|
}catch(\InvalidStateException $e){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user