Skip to content

Commit

Permalink
Only tick entity tracker if players are tracking or if at entity ticking
Browse files Browse the repository at this point in the history
Vanilla will only tick if the entity moves or is at entity ticking
level. For Paper, I am concerned that using exact Vanilla behavior
may cause problems with plugins - so we will settle on ticking the
tracker as well if players are tracking the entity.

This should reduce ticking for larger VD settings.
  • Loading branch information
Spottedleaf committed Sep 2, 2024
1 parent 1f1a0a5 commit 901a417
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.spottedleaf.moonrise.common.list.ReferenceList;
import ca.spottedleaf.moonrise.common.misc.NearbyPlayers;
import ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup;
import ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity;
Expand All @@ -10,6 +11,7 @@
import com.mojang.datafixers.DataFixer;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.GeneratingChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -77,7 +79,10 @@ private boolean newTrackerTick(final Iterator<?> iterator) {
continue;
}
((EntityTrackerTrackedEntity)tracker).moonrise$tick(nearbyPlayers.getChunk(entity.chunkPosition()));
tracker.serverEntity.sendChanges();
if (((EntityTrackerTrackedEntity)tracker).moonrise$hasPlayers()
|| ((ChunkSystemEntity)entity).moonrise$getChunkStatus().isOrAfter(FullChunkStatus.ENTITY_TICKING)) {
tracker.serverEntity.sendChanges();
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ abstract class TrackedEntityMixin implements EntityTrackerTrackedEntity {
this.removePlayer(player);
}
}

@Override
public final boolean moonrise$hasPlayers() {
return !this.seenBy.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface EntityTrackerTrackedEntity {

public void moonrise$clearPlayers();

public boolean moonrise$hasPlayers();

}

0 comments on commit 901a417

Please sign in to comment.