pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.25k stars 1.53k forks source link

Players don't tick chunks that come back in simulation distance if they never left the player's view distance #5699

Closed kenzeve closed 1 year ago

kenzeve commented 1 year ago

Issue description

Entity stops to tick normally after I fly away and then come back (but ticks when I stay very close to it)

Steps to reproduce the issue

I used this code which spawns a villager to track ticks:

$entity = new class($location) extends Villager{
            public function entityBaseTick(int $tickDiff = 1): bool{
                Server::getInstance()->broadcastMessage("tick");
                return parent::entityBaseTick($tickDiff);
            }
};
$entity->spawnToAll();

Then I fly away and come back after a while, and after that entity stops to tick normally.

Reproduced on 5.0.0-BETA2 and 4.19.0, not reproducable on 4.18.x

OS and versions

Crashdump, backtrace or other files

Video: https://youtu.be/v2u6MLtUF7U

Matze997 commented 1 year ago

Return true and run the parent not in the return statement. Its intentional to prevent too much entity updates on every tick

kenzeve commented 1 year ago

Return true and run the parent not in the return statement. Its intentional to prevent too much entity updates on every tick

Well, your solution does fix my particular situation (but then it will tick non-stop even if there is no need), but as I mentioned this code works fine on 4.18.x, so definitely there's a behavioral change between 4.18 and 4.19

dktapps commented 1 year ago

I don't understand the issue. Are you saying it doesn't start ticking again when you return to the location?

dktapps commented 1 year ago

Technical detail: Simulation distance is usually smaller than render distance.

What happened here: The chunk containing the villager left your simulation distance and stopped being ticked (all fine so far).

However, when returning to the area, the chunk is not re-registered as a ticking chunk, since it never left your render distance (i.e. this code is never executed).

The entity ticks when you're very close to it because this code causes it to be scheduled for an update.