level = $center->getLevel(); $this->source = $center; $this->size = max($size, 0); $this->what = $what; } /** * @deprecated * @return bool */ public function explode(){ if($this->explodeA()){ return $this->explodeB(); } return false; } /** * @return bool */ public function explodeA(){ if($this->size < 0.1){ return false; } $mRays = $this->rays - 1; for($i = 0; $i < $this->rays; ++$i){ for($j = 0; $j < $this->rays; ++$j){ //break 2 gets here for($k = 0; $k < $this->rays; ++$k){ if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){ $vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1 $vector = $vector->normalize()->multiply($this->stepLen); $pointer = clone $this->source; for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){ $vBlock = $pointer->floor(); if($vBlock->y < 0 or $vBlock->y > 127){ break; } $block = $this->level->getBlock($vBlock); if(!($block instanceof Air)){ $block->x = $vBlock->x; $block->y = $vBlock->y; $block->z = $vBlock->z; $blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ $index = ($block->x << 15) + ($block->z << 7) + $block->y; if(!isset($this->affectedBlocks[$index])){ $this->affectedBlocks[$index] = $block; } } } $pointer = $pointer->add($vector); } } } } } return true; } public function explodeB(){ $send = []; $source = $this->source->floor(); $yield = (1 / $this->size) * 100; if($this->what instanceof Entity){ $this->level->getServer()->getPluginManager()->callEvent($ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield)); if($ev->isCancelled()){ return false; }else{ $yield = $ev->getYield(); $this->affectedBlocks = $ev->getBlockList(); } } $explosionSize = $this->size * 2; $minX = Math::floorFloat($this->source->x - $explosionSize - 1); $maxX = Math::floorFloat($this->source->x + $explosionSize + 1); $minY = Math::floorFloat($this->source->y - $explosionSize - 1); $maxY = Math::floorFloat($this->source->y + $explosionSize + 1); $minZ = Math::floorFloat($this->source->z - $explosionSize - 1); $maxZ = Math::floorFloat($this->source->z + $explosionSize + 1); $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null); foreach($list as $entity){ $distance = $entity->distance($this->source) / $explosionSize; if($distance <= 1){ $motion = $entity->subtract($this->source)->normalize(); $impact = (1 - $distance) * ($exposure = 1); $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1); if($this->what instanceof Entity){ $ev = new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage); }elseif($this->what instanceof Block){ $ev = new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); }else{ $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); } $this->level->getServer()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $entity->attack($ev->getFinalDamage(), $ev); $entity->setMotion($motion->multiply($impact)); } } } $air = Item::get(Item::AIR); foreach($this->affectedBlocks as $block){ $block->setDamage($this->level->getBlockDataAt($block->x, $block->y, $block->z)); if($block instanceof TNT){ $mot = (new Random())->nextSignedFloat() * M_PI * 2; $tnt = new PrimedTNT($this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [ "Pos" => new Enum("Pos", [ new Double("", $block->x + 0.5), new Double("", $block->y + 0.5), new Double("", $block->z + 0.5) ]), "Motion" => new Enum("Motion", [ new Double("", -sin($mot) * 0.02), new Double("", 0.2), new Double("", -cos($mot) * 0.02) ]), "Rotation" => new Enum("Rotation", [ new Float("", 0), new Float("", 0) ]), "Fuse" => new Byte("Fuse", mt_rand(10, 30)) ])); $tnt->spawnToAll(); }elseif(mt_rand(0, 100) < $yield){ foreach($block->getDrops($air) as $drop){ $this->level->dropItem($block, Item::get(...$drop)); } } $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); } $pk = new ExplodePacket; $pk->x = $this->source->x; $pk->y = $this->source->y; $pk->z = $this->source->z; $pk->radius = $this->size; $pk->records = $send; Server::broadcastPacket($this->level->getUsingChunk($source->x >> 4, $source->z >> 4), $pk); return true; } }