mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Player: clean up cursor inventory when closing main inventory
This commit is contained in:
parent
8aa8280a63
commit
ebbbc581ca
@ -2168,7 +2168,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
$message = TextFormat::clean($message, $this->removeFormat);
|
$message = TextFormat::clean($message, $this->removeFormat);
|
||||||
foreach(explode("\n", $message) as $messagePart){
|
foreach(explode("\n", $message) as $messagePart){
|
||||||
@ -2243,7 +2243,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
if(!$this->spawned or !$this->isAlive()){
|
if(!$this->spawned or !$this->isAlive()){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
switch($packet->event){
|
switch($packet->event){
|
||||||
case EntityEventPacket::EATING_ITEM:
|
case EntityEventPacket::EATING_ITEM:
|
||||||
@ -2394,7 +2394,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
case InventoryTransactionPacket::USE_ITEM_ACTION_BREAK_BLOCK:
|
case InventoryTransactionPacket::USE_ITEM_ACTION_BREAK_BLOCK:
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
$item = $this->inventory->getItemInHand();
|
$item = $this->inventory->getItemInHand();
|
||||||
$oldItem = clone $item;
|
$oldItem = clone $item;
|
||||||
@ -2635,7 +2635,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
$target = $this->level->getEntity($packet->target);
|
$target = $this->level->getEntity($packet->target);
|
||||||
if($target === null){
|
if($target === null){
|
||||||
@ -2849,7 +2849,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
if(isset($this->windowIndex[$packet->windowId])){
|
if(isset($this->windowIndex[$packet->windowId])){
|
||||||
$this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowId], $this));
|
$this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowId], $this));
|
||||||
@ -2899,7 +2899,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
if(!$this->spawned or !$this->isAlive()){
|
if(!$this->spawned or !$this->isAlive()){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
$pos = new Vector3($packet->x, $packet->y, $packet->z);
|
$pos = new Vector3($packet->x, $packet->y, $packet->z);
|
||||||
if($pos->distanceSquared($this) > 10000 or $this->level->checkSpawnProtection($this, $pos)){
|
if($pos->distanceSquared($this) > 10000 or $this->level->checkSpawnProtection($this, $pos)){
|
||||||
@ -3617,7 +3617,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
//Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the
|
//Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the
|
||||||
//main inventory and drops the rest on the ground.
|
//main inventory and drops the rest on the ground.
|
||||||
$this->resetCraftingGridType();
|
$this->doCloseInventory();
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params)));
|
$this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params)));
|
||||||
|
|
||||||
@ -3800,15 +3800,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$this->craftingGrid = $grid;
|
$this->craftingGrid = $grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetCraftingGridType() : void{
|
public function doCloseInventory() : void{
|
||||||
$contents = $this->craftingGrid->getContents();
|
/** @var Inventory[] $inventories */
|
||||||
if(count($contents) > 0){
|
$inventories = [$this->craftingGrid, $this->cursorInventory];
|
||||||
$drops = $this->inventory->addItem(...$contents);
|
foreach($inventories as $inventory){
|
||||||
foreach($drops as $drop){
|
$contents = $inventory->getContents();
|
||||||
$this->dropItem($drop);
|
if(count($contents) > 0){
|
||||||
}
|
$drops = $this->inventory->addItem(...$contents);
|
||||||
|
foreach($drops as $drop){
|
||||||
|
$this->dropItem($drop);
|
||||||
|
}
|
||||||
|
|
||||||
$this->craftingGrid->clearAll();
|
$inventory->clearAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->craftingGrid->getGridWidth() > CraftingGrid::SIZE_SMALL){
|
if($this->craftingGrid->getGridWidth() > CraftingGrid::SIZE_SMALL){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user