mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
task tempt rework(should give a huge tps bump with a larg amount of entities), small stoptime fix
This commit is contained in:
parent
159d49ebf3
commit
4f9764dee3
6 changed files with 21 additions and 21 deletions
|
|
@ -70,7 +70,7 @@ class EntityAPI{
|
||||||
}
|
}
|
||||||
elseif(is_numeric($args[1])){//summon <mob> [amount]
|
elseif(is_numeric($args[1])){//summon <mob> [amount]
|
||||||
$amount = (int) $args[1];
|
$amount = (int) $args[1];
|
||||||
if($amount > 100){
|
if($amount > 1000){
|
||||||
return "Cannot spawn > 100 mobs";
|
return "Cannot spawn > 100 mobs";
|
||||||
}
|
}
|
||||||
$isBaby = false;
|
$isBaby = false;
|
||||||
|
|
@ -167,10 +167,7 @@ class EntityAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($eid){
|
public function get($eid){
|
||||||
if(isset($this->entities[$eid])){
|
return nullsafe($this->entities[$eid], false);
|
||||||
return $this->entities[$eid];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove($eid){
|
public function remove($eid){
|
||||||
|
|
|
||||||
|
|
@ -1167,6 +1167,7 @@ class Player{
|
||||||
$this->resendQueue = [];
|
$this->resendQueue = [];
|
||||||
$this->ackQueue = [];
|
$this->ackQueue = [];
|
||||||
$this->server->api->player->remove($this->CID);
|
$this->server->api->player->remove($this->CID);
|
||||||
|
console($msg.":".$this->username.":".$this->spawned);
|
||||||
if($msg === true and $this->username != "" and $this->spawned !== false){
|
if($msg === true and $this->username != "" and $this->spawned !== false){
|
||||||
$this->server->api->chat->broadcast($this->username . " left the game: " . $reason);
|
$this->server->api->chat->broadcast($this->username . " left the game: " . $reason);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -409,12 +409,12 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$startX = (int) (round($this->x - 0.5) - 1);
|
$startX = $this->boundingBox->minX;
|
||||||
$startY = (int) (round($this->y) - 1);
|
$startY = $this->boundingBox->minY;
|
||||||
$startZ = (int) (round($this->z - 0.5) - 1);
|
$startZ = $this->boundingBox->minZ;
|
||||||
$endX = $startX + 2;
|
$endX = $this->boundingBox->maxX;
|
||||||
$endY = $startY + 2;
|
$endY = $this->boundingBox->maxY;
|
||||||
$endZ = $startZ + 2;
|
$endZ = $this->boundingBox->maxZ;
|
||||||
$waterDone = false;
|
$waterDone = false;
|
||||||
for ($y = $startY; $y <= $endY; ++$y){
|
for ($y = $startY; $y <= $endY; ++$y){
|
||||||
for ($x = $startX; $x <= $endX; ++$x){
|
for ($x = $startX; $x <= $endX; ++$x){
|
||||||
|
|
@ -432,7 +432,7 @@ class Entity extends Position
|
||||||
$this->harm(2, "water");
|
$this->harm(2, "water");
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
$waterDone = true;
|
$waterDone = true;
|
||||||
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($b->getMetadata() % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and ! $waterDone) {
|
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($b->getMetadata() % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and !$waterDone) {
|
||||||
$this->air -= 1;
|
$this->air -= 1;
|
||||||
$waterDone = true;
|
$waterDone = true;
|
||||||
$this->updateMetadata();
|
$this->updateMetadata();
|
||||||
|
|
@ -463,7 +463,7 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ($this->inBlock($pos, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) {
|
if ($this->inBlock($pos, 0.7) and $y == $endY and !$b->isTransparent and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) {
|
||||||
$this->harm(1, "suffocation"); // Suffocation
|
$this->harm(1, "suffocation"); // Suffocation
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)) {
|
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)) {
|
||||||
|
|
@ -576,7 +576,6 @@ class Entity extends Position
|
||||||
$x1 = $x1 > 256 ? 256 : $x1;
|
$x1 = $x1 > 256 ? 256 : $x1;
|
||||||
$y1 = $y1 > 128 ? 128 : $y1;
|
$y1 = $y1 > 128 ? 128 : $y1;
|
||||||
$z1 = $z1 > 256 ? 256 : $z1;
|
$z1 = $z1 > 256 ? 256 : $z1;
|
||||||
$waterDone = false;
|
|
||||||
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){
|
||||||
|
|
|
||||||
|
|
@ -45,23 +45,26 @@ class TaskTempt extends TaskBase
|
||||||
protected function findTarget($e, $r){
|
protected function findTarget($e, $r){
|
||||||
$svd = null;
|
$svd = null;
|
||||||
$svdDist = -1;
|
$svdDist = -1;
|
||||||
foreach($e->server->api->entity->getRadius($e, $r * 3, ENTITY_PLAYER) as $p){
|
foreach($e->level->players as $p){
|
||||||
|
$p = $p->entity;
|
||||||
|
if(Utils::distance_noroot($e, $p) > $r*$r){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if($svdDist === -1){
|
if($svdDist === -1){
|
||||||
$svdDist = Utils::manh_distance($e, $p);
|
$svdDist = Utils::distance_noroot($e, $p);
|
||||||
$svd = $p;
|
$svd = $p;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($svd != null && $svdDist === 0){
|
if($svd != null && $svdDist === 0){
|
||||||
$svd = $p;
|
$svd = $p;
|
||||||
}
|
}
|
||||||
|
if(($cd = Utils::distance_noroot($e, $p)) < $svdDist){
|
||||||
if(($cd = Utils::manh_distance($e, $p)) < $svdDist){
|
|
||||||
$svdDist = $cd;
|
$svdDist = $cd;
|
||||||
$svd = $p;
|
$svd = $p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($svd == null || Utils::distance_noroot($e, $svd) > ($r * $r)){
|
if($svd == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -558,7 +558,7 @@ class Utils{
|
||||||
return round($number, 0, PHP_ROUND_HALF_DOWN);
|
return round($number, 0, PHP_ROUND_HALF_DOWN);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* manhattan distance, less accurate, but still useful sometimes
|
* manhattan distance
|
||||||
*/
|
*/
|
||||||
public static function manh_distance($pos1, $pos2){
|
public static function manh_distance($pos1, $pos2){
|
||||||
if($pos1 instanceof Vector3){
|
if($pos1 instanceof Vector3){
|
||||||
|
|
|
||||||
|
|
@ -502,7 +502,7 @@ class Level{
|
||||||
}
|
}
|
||||||
$now = microtime(true);
|
$now = microtime(true);
|
||||||
if($this->stopTime == true){
|
if($this->stopTime == true){
|
||||||
|
$time = $this->startTime;
|
||||||
}else{
|
}else{
|
||||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue