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:
Dylan K. Taylor 2021-02-03 17:05:01 +00:00
parent d4290837f3
commit 079e794339
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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();