Fire: fixed logic of extinguishing

This commit is contained in:
Dylan K. Taylor 2018-03-15 12:29:11 +00:00
parent f22ad14c67
commit 670a53ba3b

View File

@ -79,14 +79,9 @@ class Fire extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
for($s = 0; $s <= 5; ++$s){ if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$side = $this->getSide($s); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
if($side->getId() !== self::AIR and !($side instanceof Liquid)){
return;
}
} }
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
} }
public function ticksRandomly() : bool{ public function ticksRandomly() : bool{
@ -94,17 +89,49 @@ class Fire extends Flowable{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->burnsForever()){ $down = $this->getSide(Vector3::SIDE_DOWN);
if(mt_rand(0, 2) === 0){
if($this->meta === 0x0F){ $result = null;
$this->level->setBlock($this, BlockFactory::get(Block::AIR)); if($this->meta < 15){
}else{ $this->meta++;
$this->meta++; $result = $this;
$this->level->setBlock($this, $this); }
if(!$down->burnsForever()){
if($this->meta === 15){
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
$result = BlockFactory::get(Block::AIR);
}
}elseif(!$this->hasAdjacentFlammableBlocks()){
if(!$down->isSolid() or $this->meta > 3){ //fire older than 3, or without a solid block below
$result = BlockFactory::get(Block::AIR);
} }
} }
} }
if($result !== null){
$this->level->setBlock($this, $result);
if($result->getId() !== $this->id){
return;
}
}
$this->level->scheduleDelayedBlockUpdate($this, 30 + mt_rand(0, 10));
//TODO: fire spread //TODO: fire spread
} }
public function onScheduledUpdate() : void{
$this->onRandomTick();
}
private function hasAdjacentFlammableBlocks() : bool{
for($i = 0; $i <= 5; ++$i){
if($this->getSide($i)->isFlammable()){
return true;
}
}
return false;
}
} }