diff options
author | Luck <git@lucko.me> | 2022-11-26 23:00:53 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2022-11-26 23:01:02 +0000 |
commit | 65f9460a1a27e930b3749525766fd44d57b65300 (patch) | |
tree | 8ddf02527b465bd63b768b5ca0c8ee448f272c67 /spark-forge/src | |
parent | dc52696138b2506b5a36e967b98af7e3f67ab0b0 (diff) | |
download | spark-65f9460a1a27e930b3749525766fd44d57b65300.tar.gz spark-65f9460a1a27e930b3749525766fd44d57b65300.tar.bz2 spark-65f9460a1a27e930b3749525766fd44d57b65300.zip |
Include player/entity/chunk counts in window statistics
Diffstat (limited to 'spark-forge/src')
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java | 42 | ||||
-rw-r--r-- | spark-forge/src/main/resources/META-INF/accesstransformer.cfg | 4 |
2 files changed, 41 insertions, 5 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java index 1d65d6a..4750c08 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeWorldInfoProvider.java @@ -34,6 +34,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.entity.EntityLookup; import net.minecraft.world.level.entity.EntitySection; import net.minecraft.world.level.entity.EntitySectionStorage; import net.minecraft.world.level.entity.PersistentEntitySectionManager; @@ -68,8 +69,25 @@ public abstract class ForgeWorldInfoProvider implements WorldInfoProvider { } @Override - public Result<ForgeChunkInfo> poll() { - Result<ForgeChunkInfo> data = new Result<>(); + public CountsResult pollCounts() { + int players = this.server.getPlayerCount(); + int entities = 0; + int chunks = 0; + + for (ServerLevel level : this.server.getAllLevels()) { + PersistentEntitySectionManager<Entity> entityManager = level.entityManager; + EntityLookup<Entity> entityIndex = entityManager.visibleEntityStorage; + + entities += entityIndex.count(); + chunks += level.getChunkSource().getLoadedChunksCount(); + } + + return new CountsResult(players, entities, -1, chunks); + } + + @Override + public ChunksResult<ForgeChunkInfo> pollChunks() { + ChunksResult<ForgeChunkInfo> data = new ChunksResult<>(); for (ServerLevel level : this.server.getAllLevels()) { PersistentEntitySectionManager<Entity> entityManager = level.entityManager; @@ -91,8 +109,24 @@ public abstract class ForgeWorldInfoProvider implements WorldInfoProvider { } @Override - public Result<ForgeChunkInfo> poll() { - Result<ForgeChunkInfo> data = new Result<>(); + public CountsResult pollCounts() { + ClientLevel level = this.client.level; + if (level == null) { + return null; + } + + TransientEntitySectionManager<Entity> entityManager = level.entityStorage; + EntityLookup<Entity> entityIndex = entityManager.entityStorage; + + int entities = entityIndex.count(); + int chunks = level.getChunkSource().getLoadedChunksCount(); + + return new CountsResult(-1, entities, -1, chunks); + } + + @Override + public ChunksResult<ForgeChunkInfo> pollChunks() { + ChunksResult<ForgeChunkInfo> data = new ChunksResult<>(); ClientLevel level = this.client.level; if (level == null) { diff --git a/spark-forge/src/main/resources/META-INF/accesstransformer.cfg b/spark-forge/src/main/resources/META-INF/accesstransformer.cfg index 39e9c1a..2699a0e 100644 --- a/spark-forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/spark-forge/src/main/resources/META-INF/accesstransformer.cfg @@ -1,5 +1,7 @@ public net.minecraft.server.level.ServerLevel f_143244_ # entityManager public net.minecraft.world.level.entity.PersistentEntitySectionManager f_157495_ # sectionStorage +public net.minecraft.world.level.entity.PersistentEntitySectionManager f_157494_ # visibleEntityStorage public net.minecraft.client.multiplayer.ClientLevel f_171631_ # entityStorage public net.minecraft.world.level.entity.TransientEntitySectionManager f_157638_ # sectionStorage -public net.minecraft.client.Minecraft f_91018_ # gameThread
\ No newline at end of file +public net.minecraft.world.level.entity.TransientEntitySectionManager f_157637_ # entityStorage +public net.minecraft.client.Minecraft f_91018_ # gameThread |