mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +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{
|
public function onClose(Player $who) : void{
|
||||||
parent::onClose($who);
|
parent::onClose($who);
|
||||||
|
|
||||||
for($i = 0; $i < 2; ++$i){
|
$this->dropContents($this->holder->getLevel(), $this->holder->add(0.5, 0.5, 0.5));
|
||||||
$this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem($i));
|
|
||||||
$this->clear($i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,6 +26,8 @@ namespace pocketmine\inventory;
|
|||||||
use pocketmine\event\inventory\InventoryOpenEvent;
|
use pocketmine\event\inventory\InventoryOpenEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
|
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
|
||||||
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
|
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
|
||||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
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{
|
protected function doSetItemEvents(int $index, Item $newItem) : ?Item{
|
||||||
return $newItem;
|
return $newItem;
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,6 @@ class EnchantInventory extends ContainerInventory{
|
|||||||
public function onClose(Player $who) : void{
|
public function onClose(Player $who) : void{
|
||||||
parent::onClose($who);
|
parent::onClose($who);
|
||||||
|
|
||||||
for($i = 0; $i < 2; ++$i){
|
$this->dropContents($this->holder->getLevel(), $this->holder->add(0.5, 0.5, 0.5));
|
||||||
$this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem($i));
|
|
||||||
$this->clear($i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -218,12 +218,7 @@ class Explosion{
|
|||||||
$t->unpair();
|
$t->unpair();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dropPos = $t->asVector3()->add(0.5, 0.5, 0.5);
|
$t->getInventory()->dropContents($this->level, $t->add(0.5, 0.5, 0.5));
|
||||||
foreach($t->getInventory()->getContents() as $drop){
|
|
||||||
if(!$drop->isNull()){
|
|
||||||
$this->level->dropItem($dropPos, $drop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$t->close();
|
$t->close();
|
||||||
|
@ -1689,9 +1689,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$tile->unpair();
|
$tile->unpair();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($tile->getInventory()->getContents() as $chestItem){
|
$tile->getInventory()->dropContents($this, $target);
|
||||||
$this->dropItem($target, $chestItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tile->close();
|
$tile->close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user