PHP: $filled_slots = 0;for($i = 0; $i < $this->player->getInventory()->getSize(); $i++) { if($this->player->getInventory()->getItem($i)->getId() !== Item::AIR) { $filled_slots = $filled_slots + 1; }}if(!(n <= $this->player->getInventory()->getSize() - $filled_slots)){ $this->player->sendMessage("Your inventory must have at least n empty slots");} Where is the problem in this code? I don't get it, everything seems correct
Is the constant n already defined or is it just a missing $? And getSize() also returns the armor slots, so do -4.
Strange. I did as you said and it didn't work. but I did this $this->player->getInventory()->getSize() - 9 and it worked perfectly. Number 9 is a magical number, isn't it? Heh $this->player->getInventory()->getSize() returns 45 slots. There are only 36 in the inventory. 40 if we include the armor slots. Why is it 45 by default? By the way doesn't getSize() automatically take care of armor spots? public function getSize(){ return parent::getSize() - 4; }
PHP: //$i is a player inventoryif($i->firstEmpty() === -1){ //things to do if the player's inventory is full}
I know this already minebuilder. I know it. And I don't want to check if the inventory is full. I want to check if multiple slots are empty. I just want to know why $this->player->getInventory()->getSize() returns 45
The extra inventory slots have to do with indexes of hotbar slots. 36 for the entire inventory, 4 for the armor, 9 for the hotbar <-> inventory mappings. getSize() ideally never changes unless setSize() is called. You need to go through the contents of the inventory to find the empty slots.