mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Armor: fixed item disappearing when switching two of the same armour pieces
Player->useHeldItem() assumes that if the old item == the new item, we want to set the item back into the inventory if it's modified in-place. Therefore, we don't modify the item in-place to bypass the problem. closes #4022
This commit is contained in:
parent
d4290837f3
commit
079e794339
@ -123,11 +123,13 @@ class Armor extends Durable{
|
||||
|
||||
public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{
|
||||
$existing = $player->getArmorInventory()->getItem($this->getArmorSlot());
|
||||
$player->getArmorInventory()->setItem($this->getArmorSlot(), $this->pop());
|
||||
if($this->getCount() === 0){
|
||||
$thisCopy = clone $this;
|
||||
$new = $thisCopy->pop();
|
||||
$player->getArmorInventory()->setItem($this->getArmorSlot(), $new);
|
||||
if($thisCopy->getCount() === 0){
|
||||
$player->getInventory()->setItemInHand($existing);
|
||||
}else{ //if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins
|
||||
$player->getInventory()->setItemInHand($this);
|
||||
$player->getInventory()->setItemInHand($thisCopy);
|
||||
$player->getInventory()->addItem($existing);
|
||||
}
|
||||
return ItemUseResult::SUCCESS();
|
||||
|
Loading…
x
Reference in New Issue
Block a user