Hello, so i was creating a plugin where if there are ingots in a chest it transformes them into blocks and this is my code: PHP: public function matchItem(Item $neededItem, ChestInventory $inv) { $items = $inv->getContents(); foreach($items as $key => $item) { if($item->equals($neededItem)) { return $key; } return false; } }foreach ($contents as $item){ // on playerinteractevent $uses = $nbt->getInt("usesCondense"); // dont mind this if ($item->getId() === Item::IRON_INGOT){ if($item->getCount() >= 9){ $ev->setCancelled(); $condensable = true; // dont mind this $transform = floor($item->getCount() / 9); $remove = $transform * 9; $slot = $this->matchItem($item, $inv); for($i = 0; $i < $transform; $i++){ $p->getInventory()->addItem(Item::get(Item::IRON_BLOCK)); $inv->setItem($slot, Item::get($item->getId(), 0, $item->getCount() - $remove)); // here's the problem } } } } however it works and gives me the right count of iron blocks too but it doesn't substract the count of all the ingots from the $remove variable but it subtracts only 1 slot (and i want it to be in all the slots which have iron ingots) i hope u understand to help me.
That might help: https://forums.pmmp.io/threads/removing-items-from-players-invent-problem.8686/#post-67327
I would suggest counting all the items and removing them before calculating and adding the blocks PHP: $count = 0;foreach ($contents as $slot => $item){ if ($item->getId() === Item::IRON_INGOT){ $count += $item->getCount(); $inventory->clear($slot); }}$blocks = floor($count/9);$inventory->addItem(Item::get(Item::IRON_BLOCK,0,$blocks));$remain = $count % 9;if($remain > 0)$inventory->addItem(Item::get(Item::IRON_INGOT,0,$remain));