fixed closestPlayerEID being not in entityList

This commit is contained in:
GameHerobrine 2024-04-29 22:01:09 +03:00
parent 0022bfb321
commit 236f641d6c
6 changed files with 12 additions and 6 deletions

View file

@ -170,7 +170,7 @@ class PocketMinecraftServer{
public function titleTick(){ public function titleTick(){
$time = microtime(true); $time = microtime(true);
if(defined("DEBUG") and DEBUG >= 0){ if(defined("DEBUG") and DEBUG >= 0){
echo "\x1b]0;NostalgiaCore " . MAJOR_VERSION . " | Online " . count($this->clients) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07"; //echo "\x1b]0;NostalgiaCore " . MAJOR_VERSION . " | Online " . count($this->clients) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07";
} }
$this->interface->bandwidth = [0, 0, $time]; $this->interface->bandwidth = [0, 0, $time];

View file

@ -16,6 +16,11 @@ abstract class Creature extends Living{
$this->searchForClosestPlayers = true; $this->searchForClosestPlayers = true;
} }
public function update($now){
$this->handlePrePlayerSearcher();
return parent::update($now);
}
public function handlePrePlayerSearcher(){ public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher(); parent::handlePrePlayerSearcher();
if($this->closestPlayerEID !== false && !isset($this->level->entityList[$this->closestPlayerEID])){ if($this->closestPlayerEID !== false && !isset($this->level->entityList[$this->closestPlayerEID])){

View file

@ -70,7 +70,7 @@ class TaskAttackPlayer extends TaskBase
} }
} }
$closestTarget = $e->closestPlayerDist <= $this->rangeSquared ? ($e->level->entityList[$e->closestPlayerEID] ?? null) : null; $closestTarget = $e->closestPlayerDist <= $this->rangeSquared ? $e->level->entityList[$e->closestPlayerEID] : null;
if($closestTarget != null){ if($closestTarget != null){
$e->target = $closestTarget; //TODO dont save entity object ? $e->target = $closestTarget; //TODO dont save entity object ?

View file

@ -12,7 +12,7 @@ class TaskLookAtPlayer extends TaskBase{
} }
protected function findTarget(Creature $e, $r){ protected function findTarget(Creature $e, $r){
return $e->closestPlayerDist > $r*$r ? null : ($e->level->entityList[$e->closestPlayerEID] ?? null); return $e->closestPlayerDist > $r*$r ? null : $e->level->entityList[$e->closestPlayerEID];
} }
public function onStart(EntityAI $ai){ public function onStart(EntityAI $ai){

View file

@ -113,8 +113,8 @@ class TaskRangedAttack extends \TaskBase
return true; return true;
} }
} }
//TODO fix closestPlayerEID being not in entityList
$closestTarget = $e->closestPlayerDist <= $this->rangeSquared ? ($e->level->entityList[$e->closestPlayerEID] ?? null) : null; $closestTarget = $e->closestPlayerDist <= $this->rangeSquared ? $e->level->entityList[$e->closestPlayerEID] : null;
if($closestTarget != null){ if($closestTarget != null){
$e->target = $closestTarget; //TODO dont save entity object ? $e->target = $closestTarget; //TODO dont save entity object ?

View file

@ -670,8 +670,9 @@ class Level{
} }
public function addBlockToSendQueue($x, $y, $z, $id, $meta){ public function addBlockToSendQueue($x, $y, $z, $id, $meta){
if(!$this->forceDisableBlockQueue) if(!$this->forceDisableBlockQueue){
$this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta]; $this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta];
}
} }
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){ public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){