explosion doesnt use vectors anymore

This commit is contained in:
GameHerobrine 2024-06-07 06:53:52 +03:00
parent 529f2d37dc
commit 2a47f92d9a
4 changed files with 23 additions and 10 deletions

View file

@ -1,6 +1,5 @@
<?php
class AxisAlignedBB{
public $minX;
public $minY;
public $minZ;

View file

@ -1,7 +1,6 @@
<?php
class Vector3{
public $x, $y, $z;
public function __construct($x = 0, $y = 0, $z = 0){

View file

@ -12,7 +12,7 @@ abstract class RakNetDataPacket extends stdClass{
public $splitID;
public $splitIndex;
private $offset = 0;
abstract public function encode();
abstract public function decode();

View file

@ -28,17 +28,30 @@ class Explosion{
}
public function sub_expl($i, $mRays, $j, $k){
$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;
$vx = $i / $mRays * 2 - 1;
$vy = $j / $mRays * 2 - 1;
$vz = $k / $mRays * 2 - 1;
$vlen = sqrt($vx*$vx + $vy*$vy + $vz*$vz);
if($vlen != 0){
$vx = $vx / $vlen * $this->stepLen;
$vy = $vy / $vlen * $this->stepLen;
$vz = $vz / $vlen * $this->stepLen;
}else{
$vx = $vy = $vz = 0;
}
$px = $this->source->x;
$py = $this->source->y;
$pz = $this->source->z;
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
$vBlock = $pointer->floor();
$BIDM = $this->level->level->getBlock($vBlock->x, $vBlock->y, $vBlock->z);
$bx = floor($px);
$by = floor($py);
$bz = floor($pz);
$BIDM = $this->level->level->getBlock($bx, $by, $bz);
$blockID = $BIDM[0];
$blockMeta = $BIDM[1];
if($blockID > 0){
$index = ($vBlock->x << 16) + ($vBlock->z << 8) + $vBlock->y;
$index = ($bx << 16) + ($bz << 8) + $by;
$blastForce -= (StaticBlock::getHardness($blockID) / 5 + 0.3) * $this->stepLen;
if($blastForce > 0){
if(!isset($this->affectedBlocks[$index])){
@ -46,7 +59,9 @@ class Explosion{
}
}
}
$pointer = $pointer->add($vector);
$px += $vx;
$py += $vy;
$pz += $vz;
}
}