Added BlockBurnEvent

This commit is contained in:
Dylan K. Taylor 2018-03-20 09:44:49 +00:00
parent 7db8845375
commit af9b0b019d
2 changed files with 57 additions and 5 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Arrow;
use pocketmine\event\block\BlockBurnEvent;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
@ -152,12 +153,15 @@ class Fire extends Flowable{
private function burnBlock(Block $block, int $chanceBound) : void{
if(mt_rand(0, $chanceBound) < $block->getFlammability()){
$block->onIncinerate();
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockBurnEvent($block, $this));
if(!$ev->isCancelled()){
$block->onIncinerate();
if(mt_rand(0, $this->meta + 9) < 5){ //TODO: check rain
$this->level->setBlock($block, BlockFactory::get(Block::FIRE, min(15, $this->meta + (mt_rand(0, 4) >> 2))));
}else{
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
if(mt_rand(0, $this->meta + 9) < 5){ //TODO: check rain
$this->level->setBlock($block, BlockFactory::get(Block::FIRE, min(15, $this->meta + (mt_rand(0, 4) >> 2))));
}else{
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
}
}
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\block;
use pocketmine\block\Block;
use pocketmine\event\Cancellable;
/**
* Called when a block is burned away by fire.
*/
class BlockBurnEvent extends BlockEvent implements Cancellable{
/** @var Block */
private $causingBlock;
public function __construct(Block $block, Block $causingBlock){
parent::__construct($block);
$this->causingBlock = $causingBlock;
}
/**
* Returns the block (usually Fire) which caused the target block to be burned away.
* @return Block
*/
public function getCausingBlock() : Block{
return $this->causingBlock;
}
}