mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Added BlockBreakEvent::getDrops() and BlockBreakEvent::setDrops(Item[] $drops)
This commit is contained in:
parent
7c806c7920
commit
9768bf4f8a
@ -37,12 +37,17 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{
|
|||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $instaBreak = false;
|
protected $instaBreak = false;
|
||||||
|
protected $blockDrops = [];
|
||||||
|
|
||||||
public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){
|
public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){
|
||||||
$this->block = $block;
|
$this->block = $block;
|
||||||
$this->item = $item;
|
$this->item = $item;
|
||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
$this->instaBreak = (bool) $instaBreak;
|
$this->instaBreak = (bool) $instaBreak;
|
||||||
|
$drops = $player->isSurvival() ? $block->getDrops($item) : [];
|
||||||
|
foreach($drops as $i){
|
||||||
|
$this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlayer(){
|
public function getPlayer(){
|
||||||
@ -57,6 +62,20 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{
|
|||||||
return $this->instaBreak;
|
return $this->instaBreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Item[]
|
||||||
|
*/
|
||||||
|
public function getDrops(){
|
||||||
|
return $this->blockDrops;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Item[] $drops
|
||||||
|
*/
|
||||||
|
public function setDrops(array $drops){
|
||||||
|
$this->blockDrops = $drops;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param boolean $instaBreak
|
* @param boolean $instaBreak
|
||||||
*/
|
*/
|
||||||
|
@ -1413,7 +1413,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false);
|
$ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
|
||||||
|
|
||||||
if($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)){
|
if($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)){
|
||||||
$ev->setCancelled();
|
$ev->setCancelled();
|
||||||
@ -1439,21 +1439,24 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$player->lastBreak = PHP_INT_MAX;
|
$player->lastBreak = PHP_INT_MAX;
|
||||||
|
|
||||||
|
$drops = $ev->getDrops();
|
||||||
|
|
||||||
}elseif($item !== null and !$target->isBreakable($item)){
|
}elseif($item !== null and !$target->isBreakable($item)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}else{
|
||||||
|
$drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops
|
||||||
$level = $target->getLevel();
|
foreach($drops as $k => $i){
|
||||||
|
$drops[$k] = Item::get($i[0], $i[1], $i[2]);
|
||||||
if($level !== null){
|
}
|
||||||
$above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
|
}
|
||||||
if($above !== null){
|
|
||||||
if($above->getId() === Item::FIRE){
|
$above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
|
||||||
$level->setBlock($above, new Air(), true);
|
if($above !== null){
|
||||||
}
|
if($above->getId() === Item::FIRE){
|
||||||
|
$this->setBlock($above, new Air(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops
|
|
||||||
|
|
||||||
$players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
|
$players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
@ -1494,8 +1497,8 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
if($player === null or $player->isSurvival()){
|
if($player === null or $player->isSurvival()){
|
||||||
foreach($drops as $drop){
|
foreach($drops as $drop){
|
||||||
if($drop[2] > 0){
|
if($drop->getCount() > 0){
|
||||||
$this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop));
|
$this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user