97 if($this->radius < 0.1){
101 $blockFactory = RuntimeBlockStateRegistry::getInstance();
103 $mRays = $this->rays - 1;
104 $incendiary = $this->fireChance > 0;
105 for($i = 0; $i < $this->rays; ++$i){
106 for($j = 0; $j < $this->rays; ++$j){
107 for($k = 0; $k < $this->rays; ++$k){
108 if($i === 0 || $i === $mRays || $j === 0 || $j === $mRays || $k === 0 || $k === $mRays){
110 [$shiftX, $shiftY, $shiftZ] = [$i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1];
111 $len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2);
112 [$shiftX, $shiftY, $shiftZ] = [($shiftX / $len) * $this->stepLen, ($shiftY / $len) * $this->stepLen, ($shiftZ / $len) * $this->stepLen];
113 $pointerX = $this->source->x;
114 $pointerY = $this->source->y;
115 $pointerZ = $this->source->z;
117 for($blastForce = $this->radius * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
118 $x = (int) $pointerX;
119 $y = (int) $pointerY;
120 $z = (int) $pointerZ;
121 $vBlockX = $pointerX >= $x ? $x : $x - 1;
122 $vBlockY = $pointerY >= $y ? $y : $y - 1;
123 $vBlockZ = $pointerZ >= $z ? $z : $z - 1;
125 $pointerX += $shiftX;
126 $pointerY += $shiftY;
127 $pointerZ += $shiftZ;
132 $subChunk = $this->subChunkExplorer->currentSubChunk;
133 if($subChunk ===
null){
137 $state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);
139 $blastResistance = $blockFactory->blastResistance[$state] ?? 0;
140 if($blastResistance >= 0){
141 $blastForce -= ($blastResistance / 5 + 0.3) * $this->stepLen;
143 if(!isset($this->affectedBlocks[
World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){
144 $_block = $this->world->getBlockAt($vBlockX, $vBlockY, $vBlockZ,
true,
false);
145 foreach($_block->getAffectedBlocks() as $_affectedBlock){
146 $_affectedBlockPos = $_affectedBlock->getPosition();
147 $posHash =
World::blockHash($_affectedBlockPos->x, $_affectedBlockPos->y, $_affectedBlockPos->z);
148 $this->affectedBlocks[$posHash] = $_affectedBlock;
150 if($incendiary && Utils::getRandomFloat() <= $this->fireChance){
151 $this->fireIgnitions[$posHash] = $_affectedBlock;
171 $source = (new
Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
172 $yield = min(100, (1 / $this->radius) * 100);
174 if($this->what instanceof
Entity){
175 $ev =
new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield, $this->fireIgnitions);
178 if($ev->isCancelled()){
182 $yield = $ev->getYield();
183 $this->affectedBlocks = $ev->getBlockList();
184 $this->fireIgnitions = $ev->getIgnitions();
185 }elseif($this->what instanceof Block){
186 $ev =
new BlockExplodeEvent(
189 $this->affectedBlocks,
191 $this->fireIgnitions,
195 if($ev->isCancelled()){
198 $yield = $ev->getYield();
199 $this->affectedBlocks = $ev->getAffectedBlocks();
200 $this->fireIgnitions = $ev->getIgnitions();
204 $explosionSize = $this->radius * 2;
205 $minX = (int) floor($this->source->x - $explosionSize - 1);
206 $maxX = (int) ceil($this->source->x + $explosionSize + 1);
207 $minY = (int) floor($this->source->y - $explosionSize - 1);
208 $maxY = (int) ceil($this->source->y + $explosionSize + 1);
209 $minZ = (int) floor($this->source->z - $explosionSize - 1);
210 $maxZ = (int) ceil($this->source->z + $explosionSize + 1);
212 $explosionBB =
new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
215 $list = $this->world->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what :
null);
216 foreach($list as $entity){
217 $entityPos = $entity->getPosition();
218 $distance = $entityPos->distance($this->source) / $explosionSize;
221 $motion = $entityPos->subtractVector($this->source)->normalize();
222 $exposure = $this->getExposure($this->source, $entity);
224 $impact = (1 - $distance) * $exposure;
226 $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1);
228 if($this->what instanceof Entity){
229 $ev =
new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
230 }elseif($this->what instanceof Block){
231 $ev =
new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
233 $ev =
new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
236 $entity->attack($ev);
237 $entity->setMotion($entity->getMotion()->addVector($motion->multiply($impact)));
241 $air = VanillaItems::AIR();
242 $airBlock = VanillaBlocks::AIR();
243 $fireBlock = VanillaBlocks::FIRE();
245 foreach($this->affectedBlocks as $hash => $block){
246 $pos = $block->getPosition();
247 if($block instanceof TNT){
248 $block->ignite(mt_rand(10, 30));
250 if(mt_rand(0, 100) < $yield){
251 foreach($block->getDrops($air) as $drop){
252 $this->world->dropItem($pos->add(0.5, 0.5, 0.5), $drop);
255 if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !==
null){
256 $t->onBlockDestroyed();
259 isset($this->fireIgnitions[$hash]) &&
260 $block->getSide(Facing::DOWN)->getSupportType(Facing::UP) === SupportType::FULL ?
264 $this->world->setBlockAt($pos->x, $pos->y, $pos->z, $targetBlock);
268 $this->world->addParticle($source,
new HugeExplodeSeedParticle());
269 $this->world->addSound($source,
new ExplodeSound());