aaa i hate sql(mobs will cause less lags)

This commit is contained in:
GameHerobrine 2022-11-02 20:21:44 +03:00
parent f40fe179c1
commit 51442ed771
5 changed files with 1411 additions and 1210 deletions

View file

@ -152,6 +152,7 @@ class EntityAPI{
}else{
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
}
$level->entityList[$eid] = &$this->entities[$eid];
$this->server->handle("entity.add", $this->entities[$eid]);
return $this->entities[$eid];
}

View file

@ -1467,7 +1467,8 @@ class Player{
break;
}
$pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level);
$this->teleport($pos, $this->data->get("position")["yaw"], $this->data->get("position")["pitch"], true, true);
$pData = $this->data->get("position");
$this->teleport($pos, isset($pData["yaw"]) ? $pData["yaw"] : false, isset($pData["pitch"]) ? $pData["pitch"] : false, true, true);
$this->entity->setHealth($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->server->api->player->spawnAllPlayers($this);

View file

@ -71,7 +71,7 @@ class PocketMinecraftServer{
console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
"version" => "5",
"update-mobs-on-every-tick" => false,
"experemental-mob-features" => false,
"enable-nether-reactor" => true,
"enable-explosions" => true,
"enable-rail-connection" => false,
@ -83,9 +83,9 @@ class PocketMinecraftServer{
"discord-webhook-url" => "none",
"discord-bot-name" => "NostalgiaCore Logger"
]);
Entity::$updateOnTick = $this->extraprops->get("update-mobs-on-every-tick");
Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features");
if(Entity::$updateOnTick){
console("[WARNING] Mobs will update every tick. Might cause lags with a huge amount of entities.");
console("[WARNING] Experemental mob features are enabled. Unpredictable behavior.");
}
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,15 @@
<?php
class Level{
/**
* List of entities in this world
* @var array
*/
/**
* @var Config
*/
public $entities;
/**
* This is an array of entities in this world.
* @var Entity[]
*/
public $entityList;
public $tiles, $blockUpdates, $nextSave, $players = [], $level;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
@ -230,7 +233,7 @@ class Level{
if($e->level->getName() != $this->getName()){
return false; //not the same world
}
foreach($this->entities as $e1){
foreach($this->entityList as $e1){
if($e->boundingBox->intersectsWith($e1->boundingBox) && $e1->isCollidable){
$e->onCollideWith($e1);
$e1->onCollideWith($e);
@ -336,8 +339,12 @@ class Level{
}
public function onTick(PocketMinecraftServer $server){
$ents = $server->api->entity->getAll($this);
foreach($ents as $e){
//$ents = $server->api->entity->getAll($this);
foreach($this->entityList as $k => $e){
if(!($e instanceof Entity)){
unset($this->entityList[$k]);
continue;
}
if($e->needsUpdate){
$e->update();
}