diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 67981e29..680a6a23 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -1,8 +1,8 @@ server = ServerAPI::request(); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 8571ab67..e2b25adb 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -71,6 +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, "enable-nether-reactor" => true, "enable-explosions" => true, "enable-rail-connection" => false, @@ -82,6 +83,10 @@ class PocketMinecraftServer{ "discord-webhook-url" => "none", "discord-bot-name" => "NostalgiaCore Logger" ]); + Entity::$updateOnTick = $this->extraprops->get("update-mobs-on-every-tick"); + if(Entity::$updateOnTick){ + console("[WARNING] Mobs will update every tick. Might cause lags with a huge amount of entities."); + } Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); @@ -469,6 +474,9 @@ class PocketMinecraftServer{ } } $this->tick(); + foreach($this->api->level->levels as $l){ + $l->onTick($this); + } } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 2df89872..b9dc85a6 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -3,9 +3,11 @@ class Entity extends Position{ const TYPE = -1; const CLASS_TYPE = -1; - + public static $updateOnTick; public $isCollidable; public $canBeAttacked; + + public $needsUpdate; /** * @var AxisAlignedBB */ @@ -434,10 +436,9 @@ class Entity extends Position{ } if($this->class !== ENTITY_PLAYER){ $update = false; - if(($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false){ + if((($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false)){ $drag = 0.2; $blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ)); - foreach($blocks as $b){ $this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX); $this->speedY = $b->calculateYOffset($this->boundingBox, $this->speedY); @@ -549,10 +550,11 @@ class Entity extends Position{ if($this->class !== ENTITY_PLAYER){ $this->updateMovement(); - if($hasUpdate === true){ - $this->server->schedule(1, array($this, "update")); - } } + if(self::$updateOnTick && $this->class === ENTITY_MOB){ + $this->needsUpdate = $hasUpdate; + } + $this->lastUpdate = $now; } @@ -803,7 +805,7 @@ class Entity extends Position{ } public function updateAABB(){ - $this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius); + $this->boundingBox->setBounds($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius); } public function updatePosition(){ diff --git a/src/utils/Config.php b/src/utils/Config.php index 98433195..7c9db694 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -11,7 +11,6 @@ define("CONFIG_LIST", 5); // .txt, .list /** * Class Config - * * Config Class for simple config manipulation of multiple formats. */ class Config{ @@ -124,7 +123,6 @@ class Config{ } return true; } - /** * @return boolean */ diff --git a/src/world/Level.php b/src/world/Level.php index ecccc630..6d1739ca 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -329,7 +329,16 @@ class Level{ } return $ret; } - + + public function onTick(PocketMinecraftServer $server){ + $ents = $server->api->entity->getAll($this); + foreach($ents as $e){ + if($e->needsUpdate){ + $e->update(); + } + } + } + public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){ if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){ return false;