137 $source = (
new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
140 if($this->what instanceof Entity){
141 $this->level->getServer()->getPluginManager()->callEvent($ev =
new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield));
142 if($ev->isCancelled()){
145 $yield = $ev->getYield();
146 $this->affectedBlocks = $ev->getBlockList();
150 $explosionSize = $this->size * 2;
158 $explosionBB =
new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
160 $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null);
161 foreach($list as $entity){
162 $distance = $entity->distance($this->source) / $explosionSize;
165 $motion = $entity->subtract($this->source)->normalize();
167 $impact = (1 - $distance) * ($exposure = 1);
169 $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1);
171 if($this->what instanceof Entity){
173 }elseif($this->what instanceof Block){
179 if($entity->attack($ev->getFinalDamage(), $ev) ===
true){
182 $entity->setMotion($motion->multiply($impact));
189 foreach($this->affectedBlocks as $block){
191 $mot = (
new Random())->nextSignedFloat() * M_PI * 2;
194 new DoubleTag(
"", $block->x + 0.5),
195 new DoubleTag(
"", $block->y),
196 new DoubleTag(
"", $block->z + 0.5)
198 "Motion" =>
new ListTag(
"Motion", [
199 new DoubleTag(
"", -sin($mot) * 0.02),
200 new DoubleTag(
"", 0.2),
201 new DoubleTag(
"", -cos($mot) * 0.02)
203 "Rotation" =>
new ListTag(
"Rotation", [
207 "Fuse" =>
new ByteTag(
"Fuse", mt_rand(10, 30))
210 }elseif($this->dropItem and mt_rand(0, 100) < $yield){
211 foreach($block->getDrops($air) as $drop){
212 $this->level->dropItem($block->add(0.5, 0.5, 0.5),
Item::get(...$drop));
216 $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0);
218 $pos =
new Vector3($block->x, $block->y, $block->z);
220 for($side = 0; $side < 5; $side++){
221 $sideBlock = $pos->getSide($side);
222 if(!isset($this->affectedBlocks[$index =
Level::blockHash($sideBlock->x, $sideBlock->y, $sideBlock->z)]) and !isset($updateBlocks[$index])){
223 $this->level->getServer()->getPluginManager()->callEvent($ev =
new BlockUpdateEvent($this->level->getBlock($sideBlock)));
224 if(!$ev->isCancelled()){
227 $updateBlocks[$index] =
true;
233 $pk =
new ExplodePacket();
234 $pk->x = $this->source->x;
235 $pk->y = $this->source->y;
236 $pk->z = $this->source->z;
238 $pk->records = $send;
239 $this->level->addChunkPacket(
$source->x >> 4,
$source->z >> 4, $pk);
241 $this->level->addParticle(
new HugeExplodeSeedParticle(
$source));