mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Flammable blocks adjacent to fire now burn away
There are some strange bugs with blockupdating causing invisible client-side-only fires that need to be investigated.
This commit is contained in:
parent
670a53ba3b
commit
9a1d3aec6b
@ -534,6 +534,13 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return $this->getFlammability() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this block is burned away by being on fire.
|
||||
*/
|
||||
public function onIncinerate() : void{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Block on the side $side, works like Vector3::getSide()
|
||||
*
|
||||
|
@ -81,6 +81,8 @@ class Fire extends Flowable{
|
||||
public function onNearbyBlockChange() : void{
|
||||
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
||||
}else{
|
||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,13 +98,17 @@ class Fire extends Flowable{
|
||||
$this->meta++;
|
||||
$result = $this;
|
||||
}
|
||||
$canSpread = true;
|
||||
|
||||
if(!$down->burnsForever()){
|
||||
//TODO: check rain
|
||||
if($this->meta === 15){
|
||||
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
|
||||
$canSpread = false;
|
||||
$result = BlockFactory::get(Block::AIR);
|
||||
}
|
||||
}elseif(!$this->hasAdjacentFlammableBlocks()){
|
||||
$canSpread = false;
|
||||
if(!$down->isSolid() or $this->meta > 3){ //fire older than 3, or without a solid block below
|
||||
$result = BlockFactory::get(Block::AIR);
|
||||
}
|
||||
@ -111,14 +117,23 @@ class Fire extends Flowable{
|
||||
|
||||
if($result !== null){
|
||||
$this->level->setBlock($this, $result);
|
||||
if($result->getId() !== $this->id){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->level->scheduleDelayedBlockUpdate($this, 30 + mt_rand(0, 10));
|
||||
if($canSpread){
|
||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
||||
|
||||
//TODO: fire spread
|
||||
//TODO: raise upper bound for chance in humid biomes
|
||||
|
||||
foreach($this->getHorizontalSides() as $side){
|
||||
$this->burnBlock($side, 300);
|
||||
}
|
||||
|
||||
//vanilla uses a 250 upper bound here, but I don't think they intended to increase the chance of incineration
|
||||
$this->burnBlock($this->getSide(Vector3::SIDE_UP), 350);
|
||||
$this->burnBlock($this->getSide(Vector3::SIDE_DOWN), 350);
|
||||
|
||||
//TODO: fire spread
|
||||
}
|
||||
}
|
||||
|
||||
public function onScheduledUpdate() : void{
|
||||
@ -134,4 +149,16 @@ class Fire extends Flowable{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function burnBlock(Block $block, int $chanceBound) : void{
|
||||
if(mt_rand(0, $chanceBound) < $block->getFlammability()){
|
||||
$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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,8 @@ class TNT extends Solid{
|
||||
public function getFlammability() : int{
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function onIncinerate() : void{
|
||||
$this->ignite();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user