mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 19:55:33 +00:00
Using Vectors for explosions
This commit is contained in:
parent
7c9255e21e
commit
1abe7626bf
@ -20,11 +20,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Explosion{
|
class Explosion{
|
||||||
private $i = 16; //Rays
|
private $rays = 16; //Rays
|
||||||
public $level;
|
public $level;
|
||||||
public $source;
|
public $source;
|
||||||
public $size;
|
public $size;
|
||||||
public $affectedBlocks = array();
|
public $affectedBlocks = array();
|
||||||
|
public $stepLen = 0.3;
|
||||||
|
|
||||||
public function __construct(Position $center, $size){
|
public function __construct(Position $center, $size){
|
||||||
$this->level = $center->level;
|
$this->level = $center->level;
|
||||||
@ -42,40 +43,29 @@ class Explosion{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$drops = array();
|
$mRays = $this->rays - 1;
|
||||||
for($i = 0; $i < $this->i; ++$i){
|
for($i = 0; $i < $this->rays; ++$i){
|
||||||
for($j = 0; $j < $this->i; ++$j){
|
for($j = 0; $j < $this->rays; ++$j){
|
||||||
for($k = 0; $k < $this->i; ++$k){
|
for($k = 0; $k < $this->rays; ++$k){
|
||||||
if($i === 0 or $i === ($this->i - 1) or $j === 0 or $j === ($this->i - 1) or $k === 0 or $k === ($this->i - 1)){
|
if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){
|
||||||
$vectorX = $i / ($this->i - 1) * 2 - 1;
|
$vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
|
||||||
$vectorY = $j / ($this->i - 1) * 2 - 1;
|
$vector = $vector->normalize()->multiply($this->stepLen);
|
||||||
$vectorZ = $k / ($this->i - 1) * 2 - 1;
|
$pointer = clone $this->source;
|
||||||
$d6 = sqrt($vectorX * $vectorX + $vectorY * $vectorY + $vectorZ * $vectorZ);
|
|
||||||
$vectorX /= $d6;
|
|
||||||
$vectorY /= $d6;
|
|
||||||
$vectorZ /= $d6;
|
|
||||||
|
|
||||||
$blastForce = $this->size * (mt_rand(700, 1300) / 1000);
|
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
||||||
$X = $this->source->x;
|
$vBlock = $pointer->floor();
|
||||||
$Y = $this->source->y;
|
if($vBlock->y >= 128 or $vBlock->y < 0){
|
||||||
$Z = $this->source->z;
|
break;
|
||||||
|
}
|
||||||
for($stepLen = 0.3; $blastForce > 0; $blastForce -= $stepLen * 0.75){
|
$block = $this->level->getBlock($vBlock);
|
||||||
$x = (int) $X;
|
|
||||||
$y = (int) $Y;
|
|
||||||
$z = (int) $Z;
|
|
||||||
$block = $this->level->getBlock(new Vector3($x, $y, $z));
|
|
||||||
|
|
||||||
if(!($block instanceof AirBlock) and $y < 128 and $y >= 0){
|
if(!($block instanceof AirBlock)){
|
||||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $stepLen;
|
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||||
if($blastForce > 0){
|
if($blastForce > 0){
|
||||||
$this->affectedBlocks[$x.":".$y.":".$z] = $block;
|
$this->affectedBlocks[$vBlock->x.":".$vBlock->y.":".$vBlock->z] = $block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$pointer = $pointer->add($vector);
|
||||||
$X += $vectorX * $stepLen;
|
|
||||||
$Y += $vectorY * $stepLen;
|
|
||||||
$Z += $vectorZ * $stepLen;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user