Crafting: nuke

This commit brings in a much-needed rewrite of crafting transaction handling.

The following classes have been removed:
- CraftingTransferMaterialAction
- CraftingTakeResultAction

The following classes have significant changes:
- CraftingTransaction
	- All API methods have been removed and are now handled in CraftItemEvent
- CraftItemEvent
	- added the following:
		- getInputs()
		- getOutputs()
		- getRepetitions() (tells how many times a recipe was crafted in this event)
- Recipe interface:
	- Removed getResult() (individual recipes may handle this differently)
- CraftingRecipe interface
	- removed the following:
		- matchItems()
		- getExtraResults()
		- getAllResults()
	- added the following
		- getResults()
		- getIngredientList() : Item[], which must return a 1D array of items that should be consumed (wildcards accepted).
		- matchesCraftingGrid(CraftingGrid)
- ShapedRecipe
	- constructor now accepts string[], Item[], Item[]
- ShapelessRecipe
	- constructor now accepts Item[], Item[]
This commit is contained in:
Dylan K. Taylor
2018-03-26 13:23:28 +01:00
parent bc836aaec1
commit 8572e9e560
14 changed files with 437 additions and 521 deletions

View File

@ -25,35 +25,83 @@ namespace pocketmine\event\inventory;
use pocketmine\event\Cancellable;
use pocketmine\event\Event;
use pocketmine\inventory\CraftingRecipe;
use pocketmine\inventory\Recipe;
use pocketmine\inventory\transaction\CraftingTransaction;
use pocketmine\item\Item;
use pocketmine\Player;
class CraftItemEvent extends Event implements Cancellable{
/** @var CraftingTransaction */
private $transaction;
/** @var CraftingRecipe */
private $recipe;
/** @var int */
private $repetitions;
/** @var Item[] */
private $inputs;
/** @var Item[] */
private $outputs;
/**
* @param CraftingTransaction $transaction
* @param CraftingRecipe $recipe
* @param int $repetitions
* @param Item[] $inputs
* @param Item[] $outputs
*/
public function __construct(CraftingTransaction $transaction){
public function __construct(CraftingTransaction $transaction, CraftingRecipe $recipe, int $repetitions, array $inputs, array $outputs){
$this->transaction = $transaction;
$this->recipe = $recipe;
$this->repetitions = $repetitions;
$this->inputs = $inputs;
$this->outputs = $outputs;
}
/**
* Returns the inventory transaction involved in this crafting event.
*
* @return CraftingTransaction
*/
public function getTransaction() : CraftingTransaction{
return $this->transaction;
}
/**
* @return Recipe
* Returns the recipe crafted.
*
* @return CraftingRecipe
*/
public function getRecipe() : Recipe{
$recipe = $this->transaction->getRecipe();
if($recipe === null){
throw new \RuntimeException("This shouldn't be called if the transaction can't be executed");
}
public function getRecipe() : CraftingRecipe{
return $this->recipe;
}
return $recipe;
/**
* Returns the number of times the recipe was crafted. This is usually 1, but might be more in the case of recipe
* book shift-clicks (which craft lots of items in a batch).
*
* @return int
*/
public function getRepetitions() : int{
return $this->repetitions;
}
/**
* Returns a list of items destroyed as ingredients of the recipe.
*
* @return Item[]
*/
public function getInputs() : array{
return $this->inputs;
}
/**
* Returns a list of items created by crafting the recipe.
*
* @return Item[]
*/
public function getOutputs() : array{
return $this->outputs;
}
/**