mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-24 05:29:44 +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
|
|
@ -1190,7 +1190,7 @@ class Player{
|
||||||
$headSent = true;
|
$headSent = true;
|
||||||
}
|
}
|
||||||
if($packets <= 0) return;
|
if($packets <= 0) return;
|
||||||
|
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
|
||||||
$MTU = $this->MTU - 24;
|
$MTU = $this->MTU - 24;
|
||||||
if(($this->entityMovementQueueLength + $len) >= $MTU){
|
if(($this->entityMovementQueueLength + $len) >= $MTU){
|
||||||
$this->sendEntityMovementUpdateQueue();
|
$this->sendEntityMovementUpdateQueue();
|
||||||
|
|
|
||||||
|
|
@ -565,6 +565,10 @@ class Entity extends Position
|
||||||
$savedSpeedY = $this->speedY;
|
$savedSpeedY = $this->speedY;
|
||||||
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
|
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
|
||||||
$water = false;
|
$water = false;
|
||||||
|
if($this->hasGravity){
|
||||||
|
$this->speedY -= $this->inWater ? 0.02 : ($this->gravity);
|
||||||
|
}
|
||||||
|
$savedSpeedY = $this->speedY;
|
||||||
$aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ);
|
$aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ);
|
||||||
$x0 = floor($aABB->minX);
|
$x0 = floor($aABB->minX);
|
||||||
$x1 = ceil($aABB->maxX);
|
$x1 = ceil($aABB->maxX);
|
||||||
|
|
@ -573,8 +577,6 @@ class Entity extends Position
|
||||||
$z0 = floor($aABB->minZ);
|
$z0 = floor($aABB->minZ);
|
||||||
$z1 = ceil($aABB->maxZ);
|
$z1 = ceil($aABB->maxZ);
|
||||||
|
|
||||||
$ywMin = floor($aABB->minY + 0.4);
|
|
||||||
$ywMax = ceil($aABB->maxY - 0.4);
|
|
||||||
for($x = $x0; $x <= $x1; ++$x){
|
for($x = $x0; $x <= $x1; ++$x){
|
||||||
for($y = $y0; $y <= $y1; ++$y){
|
for($y = $y0; $y <= $y1; ++$y){
|
||||||
for($z = $z0; $z <= $z1; ++$z){
|
for($z = $z0; $z <= $z1; ++$z){
|
||||||
|
|
@ -621,10 +623,7 @@ class Entity extends Position
|
||||||
$this->onGround = $support;
|
$this->onGround = $support;
|
||||||
|
|
||||||
|
|
||||||
if($this->hasGravity){ //TODO causes setEntityMotion packet flood, fix
|
if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
|
||||||
$this->speedY -= $this->inWater ? 0.02 : ($this->gravity);
|
|
||||||
$update = true;
|
|
||||||
}elseif($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
|
|
||||||
// $this->speedX = 0;
|
// $this->speedX = 0;
|
||||||
// $this->speedY = 0;
|
// $this->speedY = 0;
|
||||||
// $this->speedZ = 0;
|
// $this->speedZ = 0;
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ class PrimedTNT extends Entity{
|
||||||
if(!isset($this->data["fuse"])){
|
if(!isset($this->data["fuse"])){
|
||||||
$this->data["fuse"] = 0;
|
$this->data["fuse"] = 0;
|
||||||
}
|
}
|
||||||
|
$this->hasGravity = true;
|
||||||
|
$this->gravity = 0.04;
|
||||||
$this->setHealth(10000000, "generic");
|
$this->setHealth(10000000, "generic");
|
||||||
$this->server->schedule(5, [$this, "updateFuse"], [], true);
|
$this->server->schedule(5, [$this, "updateFuse"], [], true);
|
||||||
$this->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata(){
|
public function getMetadata(){
|
||||||
|
|
@ -18,7 +19,14 @@ class PrimedTNT extends Entity{
|
||||||
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
|
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
|
||||||
return $d;
|
return $d;
|
||||||
}
|
}
|
||||||
|
public function createSaveData(){
|
||||||
|
$data = parent::createSaveData();
|
||||||
|
|
||||||
|
$data["fuse"] = $this->data["fuse"];
|
||||||
|
$data["power"] = $this->data["power"];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
public function updateFuse(){
|
public function updateFuse(){
|
||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -27,37 +27,7 @@ class Explosion{
|
||||||
$this->nullPlayer = new PlayerNull();
|
$this->nullPlayer = new PlayerNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function explode(){
|
public function sub_expl(&$visited, $i, $mRays, $j, $k){
|
||||||
$radius = 2 * $this->size;
|
|
||||||
$server = ServerAPI::request();
|
|
||||||
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
|
|
||||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
|
||||||
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //pla>
|
|
||||||
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
|
||||||
$entity->harm($damage, "explosion");
|
|
||||||
}
|
|
||||||
$pk = new ExplodePacket; //sound fix
|
|
||||||
$pk->x = $this->source->x;
|
|
||||||
$pk->y = $this->source->y;
|
|
||||||
$pk->z = $this->source->z;
|
|
||||||
$pk->radius = $this->size;
|
|
||||||
$pk->records = [];
|
|
||||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [
|
|
||||||
"level" => $this->level,
|
|
||||||
"source" => $this->source,
|
|
||||||
"size" => $this->size
|
|
||||||
]) === false){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$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 = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1
|
||||||
$vector = $vector->normalize()->multiply($this->stepLen);
|
$vector = $vector->normalize()->multiply($this->stepLen);
|
||||||
$pointer = clone $this->source;
|
$pointer = clone $this->source;
|
||||||
|
|
@ -92,9 +62,75 @@ class Explosion{
|
||||||
$pointer = $pointer->add($vector);
|
$pointer = $pointer->add($vector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function explode(){
|
||||||
|
$radius = 2 * $this->size;
|
||||||
|
$server = ServerAPI::request();
|
||||||
|
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
|
||||||
|
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||||
|
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //pla>
|
||||||
|
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
||||||
|
$entity->harm($damage, "explosion");
|
||||||
|
}
|
||||||
|
$pk = new ExplodePacket; //sound fix
|
||||||
|
$pk->x = $this->source->x;
|
||||||
|
$pk->y = $this->source->y;
|
||||||
|
$pk->z = $this->source->z;
|
||||||
|
$pk->radius = $this->size;
|
||||||
|
$pk->records = [];
|
||||||
|
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [
|
||||||
|
"level" => $this->level,
|
||||||
|
"source" => $this->source,
|
||||||
|
"size" => $this->size
|
||||||
|
]) === false){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$visited = [];
|
||||||
|
$mRays = $this->rays - 1;
|
||||||
|
$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 = [];
|
$send = [];
|
||||||
$source = $this->source->floor();
|
$source = $this->source->floor();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue