/** * @return bool */ public function explodeA() : bool { if ($this->size < 0.1) { return false; } $vector = new Vector3(0, 0, 0); $vBlock = new Vector3(0, 0, 0); $mRays = intval($this->rays - 1); for ($i = 0; $i < $this->rays; ++$i) { for ($j = 0; $j < $this->rays; ++$j) { 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->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); $vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen); $pointerX = $this->source->x; $pointerY = $this->source->y; $pointerZ = $this->source->z; for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) { $x = (int) $pointerX; $y = (int) $pointerY; $z = (int) $pointerZ; $vBlock->x = $pointerX >= $x ? $x : $x - 1; $vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlock->z = $pointerZ >= $z ? $z : $z - 1; if ($vBlock->y < 0 or $vBlock->y > 127) { break; } $block = $this->level->getBlock($vBlock); if ($block->getId() !== 0) { $blastForce -= ($block->getResistance() / 5 + 0.3) * $this->stepLen; if ($blastForce > 0) { if (!isset($this->affectedBlocks[$index = Level::blockHash($block->x, $block->y, $block->z)])) { $this->affectedBlocks[$index] = $block; } } } $pointerX += $vector->x; $pointerY += $vector->y; $pointerZ += $vector->z; } } } } } return true; }
public function explodeBlocks(Position $source, $rays = 16, $size = 4) { $vector = new Vector3(0, 0, 0); $vBlock = new Vector3(0, 0, 0); $stepLen = 0.3; $mRays = \intval($rays - 1); $affectedBlocks = array(); for ($i = 0; $i < $rays; ++$i) { for ($j = 0; $j < $rays; ++$j) { for ($k = 0; $k < $rays; ++$k) { if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) { $vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); $vector->setComponents($vector->x / ($len = $vector->length()) * $stepLen, $vector->y / $len * $stepLen, $vector->z / $len * $stepLen); $pointerX = $source->x; $pointerY = $source->y; $pointerZ = $source->z; for ($blastForce = $size * (\mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $stepLen * 0.75) { $x = (int) $pointerX; $y = (int) $pointerY; $z = (int) $pointerZ; $vBlock->x = $pointerX >= $x ? $x : $x - 1; $vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlock->z = $pointerZ >= $z ? $z : $z - 1; if ($vBlock->y < 0 or $vBlock->y > 127) { break; } $block = $source->getLevel()->getBlock($vBlock); if ($block->getId() !== 0) { $blastForce -= (mt_rand(1, 3) / 5 + 0.3) * $stepLen; if ($blastForce > 0) { if (!isset($affectedBlocks[$index = \PHP_INT_SIZE === 8 ? ($block->x & 0xfffffff) << 35 | ($block->y & 0x7f) << 28 | $block->z & 0xfffffff : $block->x . ":" . $block->y . ":" . $block->z])) { $affectedBlocks[$index] = $block; } } } $pointerX += $vector->x; $pointerY += $vector->y; $pointerZ += $vector->z; } } } } } foreach ($affectedBlocks as $block) { if ($block instanceof Block) { $block->getLevel()->setBlock($block, new Air(), false, false); } } }
/** * @return bool */ public function explodeA() { if ($this->size < 0.1) { return \false; } $vector = new Vector3(0, 0, 0); $vBlock = new Vector3(0, 0, 0); $mRays = \intval($this->rays - 1); for ($i = 0; $i < $this->rays; ++$i) { for ($j = 0; $j < $this->rays; ++$j) { 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->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); $vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen); $pointerX = $this->source->x; $pointerY = $this->source->y; $pointerZ = $this->source->z; for ($blastForce = $this->size * (\mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) { $x = (int) $pointerX; $y = (int) $pointerY; $z = (int) $pointerZ; $vBlock->x = $pointerX >= $x ? $x : $x - 1; $vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlock->z = $pointerZ >= $z ? $z : $z - 1; if ($vBlock->y < 0 or $vBlock->y > 127) { break; } $block = $this->level->getBlock($vBlock); if ($block->getId() !== 0) { $blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen; if ($blastForce > 0) { if (!isset($this->affectedBlocks[$index = \PHP_INT_SIZE === 8 ? ($block->x & 0xfffffff) << 35 | ($block->y & 0x7f) << 28 | $block->z & 0xfffffff : $block->x . ":" . $block->y . ":" . $block->z])) { $this->affectedBlocks[$index] = $block; } } } $pointerX += $vector->x; $pointerY += $vector->y; $pointerZ += $vector->z; } } } } } return \true; }