explosion tweaks

This commit is contained in:
GameHerobrine 2022-05-17 11:58:20 +03:00
parent a82b271b2f
commit 2a3b36f509
2 changed files with 39 additions and 32 deletions

View file

@ -33,13 +33,35 @@ class Explosion{
public $size;
public $affectedBlocks = array();
public $stepLen = 0.3;
private $air;
public function __construct(Position $center, $size){
$this->level = $center->level;
$this->source = $center;
$this->size = max($size, 0);
$this->air = BlockAPI::getItem(AIR, 0, 1);
console($this->air);
}
private function explodeBlocks($send, $source, $block){
$server = ServerAPI::request();
if($block instanceof TNTBlock){
$data = array(
"x" => $block->x + 0.5,
"y" => $block->y + 0.5,
"z" => $block->z + 0.5,
"power" => 4,
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
);
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
$server->api->entity->spawnToAll($e);
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
foreach($block->getDrops($this->air,new PlayerNull()) as $drop){
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], 0));
}
}
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
return $send;
}
public function explode(){
$server = ServerAPI::request();
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
@ -49,7 +71,11 @@ class Explosion{
)) === false){
return false;
}
$send = array();
$source = $this->source->floor();
$radius = 2 * $this->size;
$mRays = $this->rays - 1;
for($i = 0; $i < $this->rays; ++$i){
for($j = 0; $j < $this->rays; ++$j){
@ -72,7 +98,8 @@ class Explosion{
if($blastForce > 0){
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
if(!isset($this->affectedBlocks[$index])){
$this->affectedBlocks[$index] = $block;
$send = $this->explodeBlocks($send, $source,$block);
}
}
}
@ -82,38 +109,14 @@ class Explosion{
}
}
}
$send = array();
$source = $this->source->floor();
$radius = 2 * $this->size;
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
if($entity->type === OBJECT_PRIMEDTNT){
continue;
}
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
$entity->harm($damage, "explosion");
}
foreach($this->affectedBlocks as $block){
if($block instanceof TNTBlock){
$data = array(
"x" => $block->x + 0.5,
"y" => $block->y + 0.5,
"z" => $block->z + 0.5,
"power" => 4,
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
);
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
$server->api->entity->spawnToAll($e);
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
if(isset(self::$specialDrops[$block->getID()])){
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
}else{
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
}
}
$this->level->level->setBlockID($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;