mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Enable various types of interaction to return items to the player, without needing to have a bunch of boilerplate creative mode and held item checks
it became glaringly obvious that this was needed because of #4827 and #4868. this is further needed with the addition of cauldrons.
This commit is contained in:
@@ -129,16 +129,15 @@ class Armor extends Durable{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{
|
||||
public function onClickAir(Player $player, Vector3 $directionVector, array &$returnedItems) : ItemUseResult{
|
||||
$existing = $player->getArmorInventory()->getItem($this->getArmorSlot());
|
||||
$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($thisCopy);
|
||||
$player->getInventory()->addItem($existing);
|
||||
$player->getInventory()->setItemInHand($existing);
|
||||
if(!$thisCopy->isNull()){
|
||||
//if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins)
|
||||
$returnedItems[] = $thisCopy;
|
||||
}
|
||||
return ItemUseResult::SUCCESS();
|
||||
}
|
||||
|
Reference in New Issue
Block a user