Skip to content

Commit

Permalink
Revert "invenory problem"
Browse files Browse the repository at this point in the history
This reverts commit 805c5ae.
  • Loading branch information
dexdurable committed Sep 22, 2020
1 parent 7004c03 commit 1e744eb
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions src/pocketmine/inventory/SimpleTransactionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,69 +148,7 @@ protected function matchItems(array &$needItems, array &$haveItems) {
return true;
}

public function squashDuplicateSlotChanges() {
$slotChanges = [];
$inventories = [];

$slots = [];

foreach($this->transactions as $key => $tr) {
if (empty($this->getSource()->getCurrentWindow())) {
continue;
}
$slotChanges[$h = (spl_object_hash($tr->getInventory()) . "@" . $tr->getSlot())][] = $tr;
$inventories[$h] = $tr->getInventory();
$slots[$h] = $tr->getSlot();
}

foreach($slotChanges as $hash => $list) {
if(count($list) === 1) {
continue;
}
$inventory = $inventories[$hash];
$slot = $slots[$hash];

$sourceItem = $inventory->getItem($slot);

$targetItem = $this->findResultItem($sourceItem, $list);
if($targetItem === null){
return false;
}

foreach($list as $transaction){
unset($this->transactions[spl_object_hash($transaction)]);
}

if(!$targetItem->equalsExact($sourceItem)){
$this->addTransaction(new BaseTransaction($inventory, $slot, $sourceItem, $targetItem));
}
}
return true;
}

protected function findResultItem($needOrigin, array $possibleActions) : ?Item{
foreach($possibleActions as $i => $action){
if($action->getSourceItem()->equalsExact($needOrigin)){
$newList = $possibleActions;
unset($newList[$i]);
if(count($newList) === 0){
return $action->getTargetItem();
}
$result = $this->findResultItem($action->getTargetItem(), $newList);
if($result !== null){
return $result;
}
}
}

return null;
}

public function canExecute() {
// if (!$this->squashDuplicateSlotChanges()) {
// return false;
// }

$haveItems = [];
$needItems = [];

Expand Down

0 comments on commit 1e744eb

Please sign in to comment.