mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 01:39:52 +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;
|
namespace pocketmine\inventory\transaction;
|
||||||
|
|
||||||
|
use pocketmine\crafting\CraftingManager;
|
||||||
use pocketmine\crafting\CraftingRecipe;
|
use pocketmine\crafting\CraftingRecipe;
|
||||||
use pocketmine\event\inventory\CraftItemEvent;
|
use pocketmine\event\inventory\CraftItemEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\player\Player;
|
||||||
use function array_pop;
|
use function array_pop;
|
||||||
use function count;
|
use function count;
|
||||||
use function intdiv;
|
use function intdiv;
|
||||||
@ -55,6 +57,13 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
protected $inputs = [];
|
protected $inputs = [];
|
||||||
/** @var Item[] */
|
/** @var Item[] */
|
||||||
protected $outputs = [];
|
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
|
* @param Item[] $txItems
|
||||||
@ -126,7 +135,7 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
$this->matchItems($this->outputs, $this->inputs);
|
$this->matchItems($this->outputs, $this->inputs);
|
||||||
|
|
||||||
$failed = 0;
|
$failed = 0;
|
||||||
foreach($this->source->getServer()->getCraftingManager()->matchRecipeByOutputs($this->outputs) as $recipe){
|
foreach($this->craftingManager->matchRecipeByOutputs($this->outputs) as $recipe){
|
||||||
try{
|
try{
|
||||||
//compute number of times recipe was crafted
|
//compute number of times recipe was crafted
|
||||||
$this->repetitions = $this->matchRecipeItems($this->outputs, $recipe->getResultsFor($this->source->getCraftingGrid()), false);
|
$this->repetitions = $this->matchRecipeItems($this->outputs, $recipe->getResultsFor($this->source->getCraftingGrid()), false);
|
||||||
|
@ -236,7 +236,7 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
//trying to execute it
|
//trying to execute it
|
||||||
|
|
||||||
if($this->craftingTransaction === null){
|
if($this->craftingTransaction === null){
|
||||||
$this->craftingTransaction = new CraftingTransaction($this->player, $actions);
|
$this->craftingTransaction = new CraftingTransaction($this->player, $this->player->getServer()->getCraftingManager(), $actions);
|
||||||
}else{
|
}else{
|
||||||
foreach($actions as $action){
|
foreach($actions as $action){
|
||||||
$this->craftingTransaction->addAction($action);
|
$this->craftingTransaction->addAction($action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user