Skip to content

Commit

Permalink
add pmmp#6258
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshy3282 committed Oct 3, 2024
1 parent 81a10b7 commit 76cb631
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Additions
> https://github.com/pmmp/PocketMine-MP/pull/6194
> https://github.com/pmmp/PocketMine-MP/pull/6204
> https://github.com/pmmp/PocketMine-MP/pull/6240
> https://github.com/pmmp/PocketMine-MP/pull/6258

## What is this?
Expand Down
64 changes: 64 additions & 0 deletions src/event/block/BlockSupportBreakEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace pocketmine\event\block;

use pocketmine\block\Block;
use pocketmine\item\Item;

/**
* Called when a block is destroyed because its support has been destroyed.
*/
class BlockSupportBreakEvent extends BlockEvent{
/** @var Item[] */
protected array $blockDrops = [];

/**
* @param Item[] $drops
*/
public function __construct(
Block $block,
array $drops = [],
protected int $xpDrops = 0
){
parent::__construct($block);
$this->setDrops($drops);
}

/**
* @return Item[]
*/
public function getDrops() : array{
return $this->blockDrops;
}

/**
* @param Item[] $drops
*/
public function setDrops(array $drops) : void{
$this->setDropsVariadic(...$drops);
}

/**
* Variadic hack for easy array member type enforcement.
*/
public function setDropsVariadic(Item ...$drops) : void{
$this->blockDrops = $drops;
}

/**
* Returns how much XP will be dropped by breaking this block.
*/
public function getXpDropAmount() : int{
return $this->xpDrops;
}

/**
* Sets how much XP will be dropped by breaking this block.
*/
public function setXpDropAmount(int $amount) : void{
if($amount < 0){
throw new \InvalidArgumentException("Amount must be at least zero");
}
$this->xpDrops = $amount;
}
}
8 changes: 8 additions & 0 deletions src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use pocketmine\entity\object\ItemEntity;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\block\BlockSupportBreakEvent;
use pocketmine\event\block\BlockUpdateEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\world\ChunkLoadEvent;
Expand Down Expand Up @@ -2098,6 +2099,13 @@ public function useBreakOn(Vector3 $vector, Item &$item = null, ?Player $player

}elseif(!$target->getBreakInfo()->isBreakable()){
return false;
}else{
$ev = new BlockSupportBreakEvent($target, $drops, $xpDrop);

$ev->call();

$drops = $ev->getDrops();
$xpDrop = $ev->getXpDropAmount();
}

foreach($affectedBlocks as $t){
Expand Down

0 comments on commit 76cb631

Please sign in to comment.