mobs will spawn only in loaded chunks, entities in unloaded chunks will automatically *rip*

This commit is contained in:
GameHerobrine 2023-07-04 03:57:40 +03:00
parent bc979c2853
commit 8d1e76f84d
7 changed files with 21 additions and 12 deletions

View file

@ -7,7 +7,7 @@ abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB;
public $inPanic;
public $ignited;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = false; //force for now
parent::__construct($level, $eid, $class, $type, $data);

View file

@ -508,6 +508,12 @@ class Entity extends Position
$this->lastUpdate = $now;
return;
}
if(!$this->isPlayer() && !isset($this->level->usedChunks[((int)$this->x >> 4).".".((int)$this->z >> 4)])){
$this->close();
return false;
}
$tdiff = $now - $this->lastUpdate;
if($this->tickCounter === 0){
$this->tickCounter = 1;
@ -1003,6 +1009,10 @@ class Entity extends Position
{
if($this->closed === false){
$this->closed = true;
if($this?->linkedEntity?->linkedEntity?->eid === $this->eid){
$this->linkedEntity->linkedEntity = false;
}
$this->linkedEntity = false;
$this->server->api->entity->remove($this->eid);
}
}

View file

@ -29,7 +29,6 @@ class EntityAI
* @param TaskBase $task
*/
public function addTask(TaskBase $task){
console("[DEBUG] Adding new task...",true, true, 2);
$this->tasks[$task->__toString()] = $task;
}
public function removeTask($name){