mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added BaseInventory->dropContents()
This commit is contained in:
parent
18d3a97466
commit
fd847f02ad
@ -59,9 +59,6 @@ class AnvilInventory extends ContainerInventory{
|
||||
public function onClose(Player $who) : void{
|
||||
parent::onClose($who);
|
||||
|
||||
for($i = 0; $i < 2; ++$i){
|
||||
$this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem($i));
|
||||
$this->clear($i);
|
||||
}
|
||||
$this->dropContents($this->holder->getLevel(), $this->holder->add(0.5, 0.5, 0.5));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -59,9 +59,6 @@ class EnchantInventory extends ContainerInventory{
|
||||
public function onClose(Player $who) : void{
|
||||
parent::onClose($who);
|
||||
|
||||
for($i = 0; $i < 2; ++$i){
|
||||
$this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem($i));
|
||||
$this->clear($i);
|
||||
}
|
||||
$this->dropContents($this->holder->getLevel(), $this->holder->add(0.5, 0.5, 0.5));
|
||||
}
|
||||
}
|
@ -218,12 +218,7 @@ class Explosion{
|
||||
$t->unpair();
|
||||
}
|
||||
|
||||
$dropPos = $t->asVector3()->add(0.5, 0.5, 0.5);
|
||||
foreach($t->getInventory()->getContents() as $drop){
|
||||
if(!$drop->isNull()){
|
||||
$this->level->dropItem($dropPos, $drop);
|
||||
}
|
||||
}
|
||||
$t->getInventory()->dropContents($this->level, $t->add(0.5, 0.5, 0.5));
|
||||
}
|
||||
|
||||
$t->close();
|
||||
|
@ -1689,9 +1689,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$tile->unpair();
|
||||
}
|
||||
|
||||
foreach($tile->getInventory()->getContents() as $chestItem){
|
||||
$this->dropItem($target, $chestItem);
|
||||
}
|
||||
$tile->getInventory()->dropContents($this, $target);
|
||||
}
|
||||
|
||||
$tile->close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user