From cbaff1caecefea7abc186836de95f2db3c816e9f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 24 Jan 2023 15:49:42 +0000 Subject: [PATCH] BlockPlaceEvent: use BlockTransaction, closes #1760 BlockPlaceEvent no longer extends BlockEvent, since it's now a multi-block event getBlockReplaced() is removed getTransaction() is added to be honest, BlockPlaceEvent should be something like PlayerBlockPlaceEvent... --- src/event/block/BlockPlaceEvent.php | 25 ++++++++++++++++--------- src/world/World.php | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/event/block/BlockPlaceEvent.php b/src/event/block/BlockPlaceEvent.php index eeb6a7dbc..b92569fc1 100644 --- a/src/event/block/BlockPlaceEvent.php +++ b/src/event/block/BlockPlaceEvent.php @@ -26,24 +26,24 @@ namespace pocketmine\event\block; use pocketmine\block\Block; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; +use pocketmine\event\Event; use pocketmine\item\Item; use pocketmine\player\Player; +use pocketmine\world\BlockTransaction; /** - * Called when a player places a block + * Called when a player initiates a block placement action. + * More than one block may be changed by a single placement action, for example when placing a door. */ -class BlockPlaceEvent extends BlockEvent implements Cancellable{ +class BlockPlaceEvent extends Event implements Cancellable{ use CancellableTrait; public function __construct( protected Player $player, - Block $blockPlace, - protected Block $blockReplace, + protected BlockTransaction $transaction, protected Block $blockAgainst, protected Item $item - ){ - parent::__construct($blockPlace); - } + ){} /** * Returns the player who is placing the block. @@ -59,8 +59,15 @@ class BlockPlaceEvent extends BlockEvent implements Cancellable{ return clone $this->item; } - public function getBlockReplaced() : Block{ - return $this->blockReplace; + /** + * Returns a BlockTransaction object containing all the block positions that will be changed by this event, and the + * states they will be changed to. + * + * This will usually contain only one block, but may contain more if the block being placed is a multi-block + * structure such as a door or bed. + */ + public function getTransaction() : BlockTransaction{ + return $this->transaction; } public function getBlockAgainst() : Block{ diff --git a/src/world/World.php b/src/world/World.php index 2d7f18d4e..e6f240614 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2051,7 +2051,7 @@ class World implements ChunkManager{ } if($player !== null){ - $ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item); + $ev = new BlockPlaceEvent($player, $tx, $blockClicked, $item); if($player->isSpectator()){ $ev->cancel(); }