all entities will always tick

This commit is contained in:
GameHerobrine 2025-06-05 01:15:20 +03:00
parent 4430ab5b65
commit 60c29e9dd1
2 changed files with 11 additions and 29 deletions

View file

@ -18,6 +18,10 @@ class Entity extends Position
public $canBeAttacked; public $canBeAttacked;
public $moveTime, $lookTime, $idleTime, $knockbackTime = 0; public $moveTime, $lookTime, $idleTime, $knockbackTime = 0;
public $attackTimeout = 0; public $attackTimeout = 0;
/**
* @deprecated always true
* @var boolean
*/
public $needsUpdate = true; public $needsUpdate = true;
public $speedModifer; public $speedModifer;
public $hasGravity; public $hasGravity;
@ -418,8 +422,6 @@ class Entity extends Position
public function environmentUpdate($time) public function environmentUpdate($time)
{ {
$hasUpdate = $this->class === ENTITY_MOB; // force true for mobs
$tickDiff = ($time - $this->lastUpdate) / 0.05; $tickDiff = ($time - $this->lastUpdate) / 0.05;
if($this->attackTimeout > 0) $this->attackTimeout -= $tickDiff; if($this->attackTimeout > 0) $this->attackTimeout -= $tickDiff;
if($this->attackTimeout < 0) $this->attackTimeout = 0; if($this->attackTimeout < 0) $this->attackTimeout = 0;
@ -480,8 +482,6 @@ class Entity extends Position
if($this->fire <= 0){ if($this->fire <= 0){
$this->updateMetadata(); $this->updateMetadata();
} else{
$hasUpdate = true;
} }
} }
@ -495,7 +495,6 @@ class Entity extends Position
if($this->isInVoid()){ if($this->isInVoid()){
$this->outOfWorld(); $this->outOfWorld();
$hasUpdate = true;
} }
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix
@ -531,7 +530,7 @@ class Entity extends Position
$this->air = $this->maxAir; $this->air = $this->maxAir;
} }
} }
return $hasUpdate; return true;
} }
public function moveFlying($strafe, $forward, $speed){ //TODO rename? public function moveFlying($strafe, $forward, $speed){ //TODO rename?
@ -744,7 +743,7 @@ class Entity extends Position
$this->lastUpdate = $now; $this->lastUpdate = $now;
return; return;
} }
$hasUpdate = $this->environmentUpdate($now); $this->environmentUpdate($now);
if($this->closed === true){ if($this->closed === true){
return false; return false;
@ -756,18 +755,6 @@ class Entity extends Position
$this->updateLast(); $this->updateLast();
$this->updatePosition(); //TODO shouldnt be called in Entity $this->updatePosition(); //TODO shouldnt be called in Entity
$this->updateEntityMovement(); $this->updateEntityMovement();
$update = false;
if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
//$this->server->api->handle("entity.move", $this);
$update = true;
}elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) {
$update = true;
}
if($update === true){
$hasUpdate = true;
}
} else{ } else{
$prevGroundState = $this->onGround; $prevGroundState = $this->onGround;
$this->onGround = false; $this->onGround = false;
@ -929,8 +916,6 @@ class Entity extends Position
if(($oldFire > 0 && $this->fire <= 0) || ($oldFire <= 0 && $this->fire > 0)){ if(($oldFire > 0 && $this->fire <= 0) || ($oldFire <= 0 && $this->fire > 0)){
$this->updateMetadata(); //TODO rewrite metadata $this->updateMetadata(); //TODO rewrite metadata
} }
$hasUpdate = true;
} }
} }
@ -945,7 +930,7 @@ class Entity extends Position
$this->player->entityTick(); $this->player->entityTick();
} }
$this->needsUpdate = $hasUpdate; $this->needsUpdate = true;
$this->lastUpdate = $now; $this->lastUpdate = $now;
} }
public function isOnLadder(){ public function isOnLadder(){
@ -1197,9 +1182,7 @@ class Entity extends Position
if($this->knockbackTime > 0){ if($this->knockbackTime > 0){
--$this->knockbackTime; --$this->knockbackTime;
} }
if($this->delayBeforePickup > 0){
--$this->delayBeforePickup;
}
if($this->moveTime > 0){ if($this->moveTime > 0){
--$this->moveTime; --$this->moveTime;
} }

View file

@ -574,10 +574,9 @@ class Level{
if($e->class === ENTITY_MOB && !$e->isPlayer()){ if($e->class === ENTITY_MOB && !$e->isPlayer()){
++$this->totalMobsAmount; ++$this->totalMobsAmount;
} }
if($e->isPlayer() || $e->needsUpdate){
$e->update($currentTime); $e->update($currentTime);
if(!$e->isPlayer()) $post[] = $k; if(!$e->isPlayer()) $post[] = $k;
}
if($e instanceof Entity){ if($e instanceof Entity){
$newChunkX = (int)$e->x >> 4; $newChunkX = (int)$e->x >> 4;