mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +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{
|
public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{
|
||||||
$existing = $player->getArmorInventory()->getItem($this->getArmorSlot());
|
$existing = $player->getArmorInventory()->getItem($this->getArmorSlot());
|
||||||
$player->getArmorInventory()->setItem($this->getArmorSlot(), $this->pop());
|
$thisCopy = clone $this;
|
||||||
if($this->getCount() === 0){
|
$new = $thisCopy->pop();
|
||||||
|
$player->getArmorInventory()->setItem($this->getArmorSlot(), $new);
|
||||||
|
if($thisCopy->getCount() === 0){
|
||||||
$player->getInventory()->setItemInHand($existing);
|
$player->getInventory()->setItemInHand($existing);
|
||||||
}else{ //if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins
|
}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);
|
$player->getInventory()->addItem($existing);
|
||||||
}
|
}
|
||||||
return ItemUseResult::SUCCESS();
|
return ItemUseResult::SUCCESS();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user