41 public const MAX_AGE = 15;
43 protected function getFireDamage() :
int{
47 private function canBeSupportedBy(
Block $block) :
bool{
52 $world = $this->position->getWorld();
53 $down = $this->
getSide(Facing::DOWN);
54 if(SoulFire::canBeSupportedBy($down)){
55 $world->setBlock($this->position, VanillaBlocks::SOUL_FIRE());
56 }elseif(!$this->canBeSupportedBy($this->
getSide(Facing::DOWN)) && !$this->hasAdjacentFlammableBlocks()){
57 $world->setBlock($this->position, VanillaBlocks::AIR());
59 $world->scheduleDelayedBlockUpdate($this->position, mt_rand(30, 40));
68 $down = $this->getSide(
Facing::DOWN);
71 if($this->age < self::MAX_AGE && mt_rand(0, 2) === 0){
77 if(!$down->burnsForever()){
79 if($this->age === self::MAX_AGE){
80 if(!$down->isFlammable() && mt_rand(0, 3) === 3){
82 $result = VanillaBlocks::AIR();
84 }elseif(!$this->hasAdjacentFlammableBlocks()){
86 if($down->isTransparent() || $this->age > 3){
87 $result = VanillaBlocks::AIR();
92 $world = $this->position->getWorld();
94 $world->setBlock($this->position, $result);
97 $world->scheduleDelayedBlockUpdate($this->position, mt_rand(30, 40));
100 $this->burnBlocksAround();
106 $this->onRandomTick();
109 private function hasAdjacentFlammableBlocks() : bool{
110 foreach(
Facing::ALL as $face){
111 if($this->getSide($face)->isFlammable()){
119 private function burnBlocksAround() : void{
122 foreach($this->getHorizontalSides() as $side){
123 $this->burnBlock($side, 300);
127 $this->burnBlock($this->getSide(Facing::UP), 350);
128 $this->burnBlock($this->getSide(Facing::DOWN), 350);
131 private function burnBlock(Block $block,
int $chanceBound) : void{
132 if(mt_rand(0, $chanceBound) < $block->getFlammability()){
134 if(BlockBurnEvent::hasHandlers()){
135 $ev =
new BlockBurnEvent($block, $this);
137 $cancelled = $ev->isCancelled();
140 $block->onIncinerate();
142 $world = $this->position->getWorld();
143 if($world->getBlock($block->position)->isSameState($block)){
144 $spreadedFire =
false;
145 if(mt_rand(0, $this->age + 9) < 5){
147 $fire->age = min(self::MAX_AGE, $fire->age + (mt_rand(0, 4) >> 2));
148 $spreadedFire = $this->spreadBlock($block, $fire);
151 $world->setBlock($block->position, VanillaBlocks::AIR());
158 private function spreadFire() : void{
159 $world = $this->position->getWorld();
160 $difficultyChanceIncrease = $world->getDifficulty() * 7;
161 $ageDivisor = $this->age + 30;
163 for($y = -1; $y <= 4; ++$y){
164 $targetY = $y + (int) $this->position->y;
165 if($targetY < World::Y_MIN || $targetY >= World::Y_MAX){
169 $randomBound = 100 + ($y > 1 ? ($y - 1) * 100 : 0);
171 for($z = -1; $z <= 1; ++$z){
172 $targetZ = $z + (int) $this->position->z;
173 for($x = -1; $x <= 1; ++$x){
174 if($x === 0 && $y === 0 && $z === 0){
177 $targetX = $x + (int) $this->position->x;
178 if(!$world->isInWorld($targetX, $targetY, $targetZ)){
182 if(!$world->isChunkLoaded($targetX >> Chunk::COORD_BIT_SIZE, $targetZ >> Chunk::COORD_BIT_SIZE)){
185 $block = $world->getBlockAt($targetX, $targetY, $targetZ);
186 if($block->getTypeId() !== BlockTypeIds::AIR){
193 foreach($block->position->sides() as $vector3){
194 if($world->isInWorld($vector3->x, $vector3->y, $vector3->z)){
195 $encouragement = max($encouragement, $world->getBlockAt($vector3->x, $vector3->y, $vector3->z)->getFlameEncouragement());
199 if($encouragement <= 0){
203 $maxChance = intdiv($encouragement + 40 + $difficultyChanceIncrease, $ageDivisor);
206 if($maxChance > 0 && mt_rand(0, $randomBound - 1) <= $maxChance){
208 $new->age = min(self::MAX_AGE, $this->age + (mt_rand(0, 4) >> 2));
209 $this->spreadBlock($block, $new);
216 private function spreadBlock(Block $block, Block $newState) : bool{
217 return BlockEventHelper::spread($block, $newState, $this);