diff --git a/src/pocketmine/inventory/transaction/action/CreateItemAction.php b/src/pocketmine/inventory/transaction/action/CreateItemAction.php new file mode 100644 index 000000000..62450dbbe --- /dev/null +++ b/src/pocketmine/inventory/transaction/action/CreateItemAction.php @@ -0,0 +1,48 @@ +hasFiniteResources() and CreativeInventory::contains($this->sourceItem); + } + + public function execute(Player $source) : void{ + //NOOP + } +} diff --git a/src/pocketmine/inventory/transaction/action/CreativeInventoryAction.php b/src/pocketmine/inventory/transaction/action/CreativeInventoryAction.php deleted file mode 100644 index 139dda193..000000000 --- a/src/pocketmine/inventory/transaction/action/CreativeInventoryAction.php +++ /dev/null @@ -1,75 +0,0 @@ -actionType = $actionType; - } - - /** - * Checks that the player is in creative, and (if creating an item) that the item exists in the creative inventory. - * - * @param Player $source - * - * @return bool - */ - public function isValid(Player $source) : bool{ - return !$source->hasFiniteResources() and - ($this->actionType === self::TYPE_DELETE_ITEM or CreativeInventory::getItemIndex($this->sourceItem) !== -1); - } - - /** - * Returns the type of the action. - */ - public function getActionType() : int{ - return $this->actionType; - } - - /** - * No need to do anything extra here: this type just provides a place for items to disappear or appear from. - * - * @param Player $source - */ - public function execute(Player $source) : void{ - - } -} diff --git a/src/pocketmine/inventory/transaction/action/DestroyItemAction.php b/src/pocketmine/inventory/transaction/action/DestroyItemAction.php new file mode 100644 index 000000000..b97454e56 --- /dev/null +++ b/src/pocketmine/inventory/transaction/action/DestroyItemAction.php @@ -0,0 +1,47 @@ +hasFiniteResources(); + } + + public function execute(Player $source) : void{ + //NOOP + } +} diff --git a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php index 78aae89d1..49fa75622 100644 --- a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php +++ b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php @@ -23,7 +23,8 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types; -use pocketmine\inventory\transaction\action\CreativeInventoryAction; +use pocketmine\inventory\transaction\action\CreateItemAction; +use pocketmine\inventory\transaction\action\DestroyItemAction; use pocketmine\inventory\transaction\action\DropItemAction; use pocketmine\inventory\transaction\action\InventoryAction; use pocketmine\inventory\transaction\action\SlotChangeAction; @@ -183,17 +184,13 @@ class NetworkInventoryAction{ case self::SOURCE_CREATIVE: switch($this->inventorySlot){ case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM: - $type = CreativeInventoryAction::TYPE_DELETE_ITEM; - break; + return new DestroyItemAction($this->newItem); case self::ACTION_MAGIC_SLOT_CREATIVE_CREATE_ITEM: - $type = CreativeInventoryAction::TYPE_CREATE_ITEM; - break; + return new CreateItemAction($this->oldItem); default: throw new \UnexpectedValueException("Unexpected creative action type $this->inventorySlot"); } - - return new CreativeInventoryAction($this->oldItem, $this->newItem, $type); case self::SOURCE_CRAFTING_GRID: case self::SOURCE_TODO: //These types need special handling.