mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
motion packet spam fix, explosion optimizations, tnt gravity fix
This commit is contained in:
parent
6e8d7bead3
commit
69d5589191
4 changed files with 96 additions and 53 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Explosion{
|
||||
|
||||
|
||||
public static $specialDrops = [
|
||||
GRASS => DIRT,
|
||||
STONE => COBBLESTONE,
|
||||
|
|
@ -18,7 +18,7 @@ class Explosion{
|
|||
private $rays = 16;
|
||||
private $air;
|
||||
private $nullPlayer;
|
||||
|
||||
|
||||
public function __construct(Position $center, $size){
|
||||
$this->level = $center->level;
|
||||
$this->source = $center;
|
||||
|
|
@ -26,7 +26,43 @@ class Explosion{
|
|||
$this->air = BlockAPI::getItem(AIR, 0, 1);
|
||||
$this->nullPlayer = new PlayerNull();
|
||||
}
|
||||
|
||||
|
||||
public function sub_expl(&$visited, $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;
|
||||
|
||||
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);
|
||||
$blockID = $BIDM[0];
|
||||
$blockMeta = $BIDM[1];
|
||||
if($blockID > 0){
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
|
||||
if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($vBlock->x, $vBlock->y, $vBlock->z, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
$visited[$index] = true;
|
||||
}
|
||||
|
||||
$blastForce -= (StaticBlock::getHardness($blockID) / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
if(!isset($this->affectedBlocks[$index])){
|
||||
$this->affectedBlocks[$index] = [
|
||||
"x" => $vBlock->x,
|
||||
"y" => $vBlock->y,
|
||||
"z" => $vBlock->z,
|
||||
"id" => $blockID,
|
||||
"meta" => $blockMeta
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$pointer = $pointer->add($vector);
|
||||
}
|
||||
}
|
||||
|
||||
public function explode(){
|
||||
$radius = 2 * $this->size;
|
||||
$server = ServerAPI::request();
|
||||
|
|
@ -54,48 +90,48 @@ class Explosion{
|
|||
}
|
||||
$visited = [];
|
||||
$mRays = $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 = 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();
|
||||
$BIDM = $this->level->level->getBlock($vBlock->x, $vBlock->y, $vBlock->z);
|
||||
$blockID = $BIDM[0];
|
||||
$blockMeta = $BIDM[1];
|
||||
if($blockID > 0){
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
|
||||
if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($vBlock->x, $vBlock->y, $vBlock->z, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
$visited[$index] = true;
|
||||
}
|
||||
|
||||
$blastForce -= (StaticBlock::getHardness($blockID) / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
if(!isset($this->affectedBlocks[$index])){
|
||||
$this->affectedBlocks[$index] = [
|
||||
"x" => $vBlock->x,
|
||||
"y" => $vBlock->y,
|
||||
"z" => $vBlock->z,
|
||||
"id" => $blockID,
|
||||
"meta" => $blockMeta
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$pointer = $pointer->add($vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
$i = 0;
|
||||
for($j = 0; $j <= $mRays; ++$j){
|
||||
for($k = 0; $k <= $mRays; ++$k){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k); //i wish there was #define or inline
|
||||
}
|
||||
}
|
||||
|
||||
$i = $mRays;
|
||||
for($j = 0; $j <= $mRays; ++$j){
|
||||
for($k = 0; $k <= $mRays; ++$k){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
|
||||
$j = 0;
|
||||
for($i = 1; $i < $mRays; ++$i){
|
||||
for($k = 0; $k <= $mRays; ++$k){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
|
||||
$j = $mRays;
|
||||
for($i = 1; $i < $mRays; ++$i){
|
||||
for($k = 0; $k <= $mRays; ++$k){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
|
||||
$k = 0;
|
||||
for($i = 1; $i < $mRays; ++$i){
|
||||
for($j = 1; $j < $mRays; ++$j){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
$k = $mRays;
|
||||
for($i = 1; $i < $mRays; ++$i){
|
||||
for($j = 1; $j < $mRays; ++$j){
|
||||
$this->sub_expl($visited, $i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
//if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){
|
||||
|
||||
|
||||
$send = [];
|
||||
$source = $this->source->floor();
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
|
|
@ -103,7 +139,7 @@ class Explosion{
|
|||
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
||||
$entity->harm($damage, "explosion");
|
||||
}
|
||||
|
||||
|
||||
foreach($this->affectedBlocks as $blockA){
|
||||
if($blockA["id"] === TNT){
|
||||
$data = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue