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...
This commit is contained in:
Dylan K. Taylor 2023-01-24 15:49:42 +00:00
parent 92896c78da
commit cbaff1caec
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 17 additions and 10 deletions

View File

@ -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{

View File

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