96 if($this->radius < 0.1){
100 $blockFactory = RuntimeBlockStateRegistry::getInstance();
102 $mRays = $this->rays - 1;
103 $incendiary = $this->fireChance > 0;
104 for($i = 0; $i < $this->rays; ++$i){
105 for($j = 0; $j < $this->rays; ++$j){
106 for($k = 0; $k < $this->rays; ++$k){
107 if($i === 0 || $i === $mRays || $j === 0 || $j === $mRays || $k === 0 || $k === $mRays){
109 [$shiftX, $shiftY, $shiftZ] = [$i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1];
110 $len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2);
111 [$shiftX, $shiftY, $shiftZ] = [($shiftX / $len) * $this->stepLen, ($shiftY / $len) * $this->stepLen, ($shiftZ / $len) * $this->stepLen];
112 $pointerX = $this->source->x;
113 $pointerY = $this->source->y;
114 $pointerZ = $this->source->z;
116 for($blastForce = $this->radius * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
117 $x = (int) $pointerX;
118 $y = (int) $pointerY;
119 $z = (int) $pointerZ;
120 $vBlockX = $pointerX >= $x ? $x : $x - 1;
121 $vBlockY = $pointerY >= $y ? $y : $y - 1;
122 $vBlockZ = $pointerZ >= $z ? $z : $z - 1;
124 $pointerX += $shiftX;
125 $pointerY += $shiftY;
126 $pointerZ += $shiftZ;
131 $subChunk = $this->subChunkExplorer->currentSubChunk;
132 if($subChunk ===
null){
136 $state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);
138 $blastResistance = $blockFactory->blastResistance[$state] ?? 0;
139 if($blastResistance >= 0){
140 $blastForce -= ($blastResistance / 5 + 0.3) * $this->stepLen;
142 if(!isset($this->affectedBlocks[
World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){
143 $_block = $this->world->getBlockAt($vBlockX, $vBlockY, $vBlockZ,
true,
false);
144 foreach($_block->getAffectedBlocks() as $_affectedBlock){
145 $_affectedBlockPos = $_affectedBlock->getPosition();
146 $posHash =
World::blockHash($_affectedBlockPos->x, $_affectedBlockPos->y, $_affectedBlockPos->z);
147 $this->affectedBlocks[$posHash] = $_affectedBlock;
149 if($incendiary && Utils::getRandomFloat() <= $this->fireChance){
150 $this->fireIgnitions[$posHash] = $_affectedBlock;
170 $source = (new
Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
171 $yield = min(100, (1 / $this->radius) * 100);
173 if($this->what instanceof
Entity){
174 $ev =
new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield, $this->fireIgnitions);
177 if($ev->isCancelled()){
181 $yield = $ev->getYield();
182 $this->affectedBlocks = $ev->getBlockList();
183 $this->fireIgnitions = $ev->getIgnitions();
184 }elseif($this->what instanceof Block){
185 $ev =
new BlockExplodeEvent(
188 $this->affectedBlocks,
190 $this->fireIgnitions,
194 if($ev->isCancelled()){
197 $yield = $ev->getYield();
198 $this->affectedBlocks = $ev->getAffectedBlocks();
199 $this->fireIgnitions = $ev->getIgnitions();
203 $explosionSize = $this->radius * 2;
204 $minX = (int) floor($this->source->x - $explosionSize - 1);
205 $maxX = (int) ceil($this->source->x + $explosionSize + 1);
206 $minY = (int) floor($this->source->y - $explosionSize - 1);
207 $maxY = (int) ceil($this->source->y + $explosionSize + 1);
208 $minZ = (int) floor($this->source->z - $explosionSize - 1);
209 $maxZ = (int) ceil($this->source->z + $explosionSize + 1);
211 $explosionBB =
new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
214 $list = $this->world->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what :
null);
215 foreach($list as $entity){
216 $entityPos = $entity->getPosition();
217 $distance = $entityPos->distance($this->source) / $explosionSize;
220 $motion = $entityPos->subtractVector($this->source)->normalize();
222 $impact = (1 - $distance) * ($exposure = 1);
224 $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1);
226 if($this->what instanceof Entity){
227 $ev =
new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
228 }elseif($this->what instanceof Block){
229 $ev =
new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
231 $ev =
new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
234 $entity->attack($ev);
235 $entity->setMotion($entity->getMotion()->addVector($motion->multiply($impact)));
239 $air = VanillaItems::AIR();
240 $airBlock = VanillaBlocks::AIR();
241 $fireBlock = VanillaBlocks::FIRE();
243 foreach($this->affectedBlocks as $hash => $block){
244 $pos = $block->getPosition();
245 if($block instanceof TNT){
246 $block->ignite(mt_rand(10, 30));
248 if(mt_rand(0, 100) < $yield){
249 foreach($block->getDrops($air) as $drop){
250 $this->world->dropItem($pos->add(0.5, 0.5, 0.5), $drop);
253 if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !==
null){
254 $t->onBlockDestroyed();
257 isset($this->fireIgnitions[$hash]) &&
258 $block->getSide(Facing::DOWN)->getSupportType(Facing::UP) === SupportType::FULL ?
262 $this->world->setBlockAt($pos->x, $pos->y, $pos->z, $targetBlock);
266 $this->world->addParticle($source,
new HugeExplodeSeedParticle());
267 $this->world->addSound($source,
new ExplodeSound());