81 if($this->radius < 0.1){
85 $blockFactory = RuntimeBlockStateRegistry::getInstance();
87 $mRays = $this->rays - 1;
88 for($i = 0; $i < $this->rays; ++$i){
89 for($j = 0; $j < $this->rays; ++$j){
90 for($k = 0; $k < $this->rays; ++$k){
91 if($i === 0 || $i === $mRays || $j === 0 || $j === $mRays || $k === 0 || $k === $mRays){
93 [$shiftX, $shiftY, $shiftZ] = [$i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1];
94 $len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2);
95 [$shiftX, $shiftY, $shiftZ] = [($shiftX / $len) * $this->stepLen, ($shiftY / $len) * $this->stepLen, ($shiftZ / $len) * $this->stepLen];
96 $pointerX = $this->source->x;
97 $pointerY = $this->source->y;
98 $pointerZ = $this->source->z;
100 for($blastForce = $this->radius * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
101 $x = (int) $pointerX;
102 $y = (int) $pointerY;
103 $z = (int) $pointerZ;
104 $vBlockX = $pointerX >= $x ? $x : $x - 1;
105 $vBlockY = $pointerY >= $y ? $y : $y - 1;
106 $vBlockZ = $pointerZ >= $z ? $z : $z - 1;
108 $pointerX += $shiftX;
109 $pointerY += $shiftY;
110 $pointerZ += $shiftZ;
115 $subChunk = $this->subChunkExplorer->currentSubChunk;
116 if($subChunk ===
null){
120 $state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);
122 $blastResistance = $blockFactory->blastResistance[$state] ?? 0;
123 if($blastResistance >= 0){
124 $blastForce -= ($blastResistance / 5 + 0.3) * $this->stepLen;
126 if(!isset($this->affectedBlocks[
World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){
127 $_block = $this->world->getBlockAt($vBlockX, $vBlockY, $vBlockZ,
true,
false);
128 foreach($_block->getAffectedBlocks() as $_affectedBlock){
129 $_affectedBlockPos = $_affectedBlock->getPosition();
130 $this->affectedBlocks[
World::blockHash($_affectedBlockPos->x, $_affectedBlockPos->y, $_affectedBlockPos->z)] = $_affectedBlock;
149 $source = (new
Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
150 $yield = min(100, (1 / $this->radius) * 100);
152 if($this->what instanceof
Entity){
153 $ev =
new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield);
155 if($ev->isCancelled()){
158 $yield = $ev->getYield();
159 $this->affectedBlocks = $ev->getBlockList();
163 $explosionSize = $this->radius * 2;
164 $minX = (int) floor($this->source->x - $explosionSize - 1);
165 $maxX = (int) ceil($this->source->x + $explosionSize + 1);
166 $minY = (int) floor($this->source->y - $explosionSize - 1);
167 $maxY = (int) ceil($this->source->y + $explosionSize + 1);
168 $minZ = (int) floor($this->source->z - $explosionSize - 1);
169 $maxZ = (int) ceil($this->source->z + $explosionSize + 1);
171 $explosionBB =
new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
174 $list = $this->world->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what :
null);
175 foreach($list as $entity){
176 $entityPos = $entity->getPosition();
177 $distance = $entityPos->distance($this->source) / $explosionSize;
180 $motion = $entityPos->subtractVector($this->source)->normalize();
182 $impact = (1 - $distance) * ($exposure = 1);
184 $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1);
186 if($this->what instanceof Entity){
187 $ev =
new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
188 }elseif($this->what instanceof Block){
189 $ev =
new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
191 $ev =
new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
194 $entity->attack($ev);
195 $entity->setMotion($entity->getMotion()->addVector($motion->multiply($impact)));
199 $air = VanillaItems::AIR();
200 $airBlock = VanillaBlocks::AIR();
202 foreach($this->affectedBlocks as $block){
203 $pos = $block->getPosition();
204 if($block instanceof TNT){
205 $block->ignite(mt_rand(10, 30));
207 if(mt_rand(0, 100) < $yield){
208 foreach($block->getDrops($air) as $drop){
209 $this->world->dropItem($pos->add(0.5, 0.5, 0.5), $drop);
212 if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !==
null){
213 $t->onBlockDestroyed();
215 $this->world->setBlockAt($pos->x, $pos->y, $pos->z, $airBlock);
219 $this->world->addParticle($source,
new HugeExplodeSeedParticle());
220 $this->world->addSound($source,
new ExplodeSound());