mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +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;
|
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()
|
* Returns the Block on the side $side, works like Vector3::getSide()
|
||||||
*
|
*
|
||||||
|
@ -81,6 +81,8 @@ class Fire extends Flowable{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
|
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
$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++;
|
$this->meta++;
|
||||||
$result = $this;
|
$result = $this;
|
||||||
}
|
}
|
||||||
|
$canSpread = true;
|
||||||
|
|
||||||
if(!$down->burnsForever()){
|
if(!$down->burnsForever()){
|
||||||
|
//TODO: check rain
|
||||||
if($this->meta === 15){
|
if($this->meta === 15){
|
||||||
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
|
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
|
||||||
|
$canSpread = false;
|
||||||
$result = BlockFactory::get(Block::AIR);
|
$result = BlockFactory::get(Block::AIR);
|
||||||
}
|
}
|
||||||
}elseif(!$this->hasAdjacentFlammableBlocks()){
|
}elseif(!$this->hasAdjacentFlammableBlocks()){
|
||||||
|
$canSpread = false;
|
||||||
if(!$down->isSolid() or $this->meta > 3){ //fire older than 3, or without a solid block below
|
if(!$down->isSolid() or $this->meta > 3){ //fire older than 3, or without a solid block below
|
||||||
$result = BlockFactory::get(Block::AIR);
|
$result = BlockFactory::get(Block::AIR);
|
||||||
}
|
}
|
||||||
@ -111,14 +117,23 @@ class Fire extends Flowable{
|
|||||||
|
|
||||||
if($result !== null){
|
if($result !== null){
|
||||||
$this->level->setBlock($this, $result);
|
$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{
|
public function onScheduledUpdate() : void{
|
||||||
@ -134,4 +149,16 @@ class Fire extends Flowable{
|
|||||||
|
|
||||||
return false;
|
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{
|
public function getFlammability() : int{
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onIncinerate() : void{
|
||||||
|
$this->ignite();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user