Provide E/TE/Chunk count stat methods

Provides counts without the ineffeciency of using .getEntities().size()
which creates copy of the collections.
This commit is contained in:
Aikar 2017-01-07 15:24:46 -05:00
parent 2aa9d5bf18
commit 4ca188a20e
2 changed files with 60 additions and 10 deletions

View file

@ -57,6 +57,15 @@
public abstract class Level implements LevelAccessor, AutoCloseable {
public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
@@ -94,7 +117,7 @@
public static final int TICKS_PER_DAY = 24000;
public static final int MAX_ENTITY_SPAWN_Y = 20000000;
public static final int MIN_ENTITY_SPAWN_Y = -20000000;
- protected final List<TickingBlockEntity> blockEntityTickers = Lists.newArrayList();
+ public final List<TickingBlockEntity> blockEntityTickers = Lists.newArrayList(); // Paper - public
protected final NeighborUpdater neighborUpdater;
private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
private boolean tickingBlockEntities;
@@ -121,23 +144,74 @@
private final DamageSources damageSources;
private long subTickCount;
@ -306,7 +315,7 @@
if (this.isOutsideBuildHeight(pos)) {
return false;
} else if (!this.isClientSide && this.isDebug()) {
@@ -214,45 +400,124 @@
@@ -214,44 +400,123 @@
} else {
LevelChunk chunk = this.getChunkAt(pos);
Block block = state.getBlock();
@ -390,10 +399,10 @@
+ // CraftBukkit end
+
return true;
}
}
}
+ }
+ }
+ }
+
+ // CraftBukkit start - Split off from above in order to directly send client and physic updates
+ public void notifyAndUpdatePhysics(BlockPos blockposition, LevelChunk chunk, BlockState oldBlock, BlockState newBlock, BlockState actualBlock, int i, int j) {
+ BlockState iblockdata = newBlock;
@ -406,7 +415,7 @@
+
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
+ this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
+ }
}
+
+ if ((i & 1) != 0) {
+ this.blockUpdated(blockposition, iblockdata1.getBlock());
@ -439,13 +448,12 @@
+ this.onBlockStateChange(blockposition, iblockdata1, iblockdata2);
+ }
+ // CraftBukkit end
+ }
+ }
}
}
+ // CraftBukkit end
+
public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {}
@Override
@@ -340,10 +605,18 @@
@Override

View file

@ -169,6 +169,48 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY);
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
// Paper start - Provide fast information methods
@Override
public int getEntityCount() {
int ret = 0;
for (net.minecraft.world.entity.Entity entity : world.getEntities().getAll()) {
if (entity.isChunkLoaded()) {
++ret;
}
}
return ret;
}
@Override
public int getTileEntityCount() {
// We don't use the full world tile entity list, so we must iterate chunks
int size = 0;
for (ChunkHolder playerchunk : ca.spottedleaf.moonrise.common.util.ChunkSystem.getVisibleChunkHolders(this.world)) {
net.minecraft.world.level.chunk.LevelChunk chunk = playerchunk.getTickingChunk();
if (chunk == null) {
continue;
}
size += chunk.blockEntities.size();
}
return size;
}
@Override
public int getTickableTileEntityCount() {
return world.blockEntityTickers.size();
}
@Override
public int getChunkCount() {
return this.world.getChunkSource().getFullChunksCount();
}
@Override
public int getPlayerCount() {
return world.players().size();
}
// Paper end
private static final Random rand = new Random();
public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, Environment env) {