mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
CraftingTransaction: make CraftingManager injectable
this becomes a bit easier to unit-test.
This commit is contained in:
parent
96541763f1
commit
29612cded3
@ -23,9 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory\transaction;
|
||||
|
||||
use pocketmine\crafting\CraftingManager;
|
||||
use pocketmine\crafting\CraftingRecipe;
|
||||
use pocketmine\event\inventory\CraftItemEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use function array_pop;
|
||||
use function count;
|
||||
use function intdiv;
|
||||
@ -55,6 +57,13 @@ class CraftingTransaction extends InventoryTransaction{
|
||||
protected $inputs = [];
|
||||
/** @var Item[] */
|
||||
protected $outputs = [];
|
||||
/** @var CraftingManager */
|
||||
private $craftingManager;
|
||||
|
||||
public function __construct(Player $source, CraftingManager $craftingManager, array $actions = []){
|
||||
parent::__construct($source, $actions);
|
||||
$this->craftingManager = $craftingManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item[] $txItems
|
||||
@ -126,7 +135,7 @@ class CraftingTransaction extends InventoryTransaction{
|
||||
$this->matchItems($this->outputs, $this->inputs);
|
||||
|
||||
$failed = 0;
|
||||
foreach($this->source->getServer()->getCraftingManager()->matchRecipeByOutputs($this->outputs) as $recipe){
|
||||
foreach($this->craftingManager->matchRecipeByOutputs($this->outputs) as $recipe){
|
||||
try{
|
||||
//compute number of times recipe was crafted
|
||||
$this->repetitions = $this->matchRecipeItems($this->outputs, $recipe->getResultsFor($this->source->getCraftingGrid()), false);
|
||||
|
@ -236,7 +236,7 @@ class InGamePacketHandler extends PacketHandler{
|
||||
//trying to execute it
|
||||
|
||||
if($this->craftingTransaction === null){
|
||||
$this->craftingTransaction = new CraftingTransaction($this->player, $actions);
|
||||
$this->craftingTransaction = new CraftingTransaction($this->player, $this->player->getServer()->getCraftingManager(), $actions);
|
||||
}else{
|
||||
foreach($actions as $action){
|
||||
$this->craftingTransaction->addAction($action);
|
||||
|
Loading…
x
Reference in New Issue
Block a user