Added BaseInventory->dropContents()

This commit is contained in:
Dylan K. Taylor
2017-10-16 12:18:06 +01:00
parent 18d3a97466
commit fd847f02ad
5 changed files with 21 additions and 17 deletions

View File

@ -26,6 +26,8 @@ namespace pocketmine\inventory;
use pocketmine\event\inventory\InventoryOpenEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
@ -128,6 +130,21 @@ abstract class BaseInventory implements Inventory{
}
}
/**
* Drops the contents of the inventory into the specified Level at the specified position and clears the inventory
* contents.
*
* @param Level $level
* @param Vector3 $position
*/
public function dropContents(Level $level, Vector3 $position) : void{
foreach($this->getContents() as $item){
$level->dropItem($position, $item);
}
$this->clearAll();
}
protected function doSetItemEvents(int $index, Item $newItem) : ?Item{
return $newItem;
}