DropItemAction: don't require a source item in constructor

This commit is contained in:
Dylan K. Taylor 2018-03-29 12:18:19 +01:00
parent ec332e3e60
commit f41a731493
2 changed files with 8 additions and 9 deletions

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\inventory\transaction\action; namespace pocketmine\inventory\transaction\action;
use pocketmine\event\player\PlayerDropItemEvent; use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\Player; use pocketmine\Player;
/** /**
@ -31,15 +33,12 @@ use pocketmine\Player;
*/ */
class DropItemAction extends InventoryAction{ class DropItemAction extends InventoryAction{
/** public function __construct(Item $targetItem){
* Verifies that the source item of a drop-item action must be air. This is not strictly necessary, just a sanity parent::__construct(ItemFactory::get(Item::AIR, 0, 0), $targetItem);
* check. }
*
* @param Player $source
* @return bool
*/
public function isValid(Player $source) : bool{ public function isValid(Player $source) : bool{
return $this->sourceItem->isNull(); return true;
} }
public function onPreExecute(Player $source) : bool{ public function onPreExecute(Player $source) : bool{

View File

@ -170,7 +170,7 @@ class NetworkInventoryAction{
throw new \UnexpectedValueException("Only expecting drop-item world actions from the client!"); throw new \UnexpectedValueException("Only expecting drop-item world actions from the client!");
} }
return new DropItemAction($this->oldItem, $this->newItem); return new DropItemAction($this->newItem);
case self::SOURCE_CREATIVE: case self::SOURCE_CREATIVE:
switch($this->inventorySlot){ switch($this->inventorySlot){
case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM: case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM: