mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-03 21:52:05 -07:00
Optimize Level.hasChunkAt(BlockPosition)Z
Reduce method invocations for World.isLoaded(BlockPosition)Z
This commit is contained in:
@@ -210,7 +210,7 @@
|
|||||||
public boolean isInWorldBounds(BlockPos pos) {
|
public boolean isInWorldBounds(BlockPos pos) {
|
||||||
return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
|
return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
|
||||||
}
|
}
|
||||||
@@ -179,18 +298,68 @@
|
@@ -179,18 +298,73 @@
|
||||||
return y < -20000000 || y >= 20000000;
|
return y < -20000000 || y >= 20000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@
|
|||||||
|
|
||||||
+ // Paper start - if loaded
|
+ // Paper start - if loaded
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
+ @Override
|
||||||
+ public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) {
|
+ public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) {
|
||||||
+ return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z);
|
+ return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z);
|
||||||
+ }
|
+ }
|
||||||
@@ -260,6 +260,11 @@
|
|||||||
+ return chunk == null ? null : chunk.getFluidState(blockposition);
|
+ return chunk == null ? null : chunk.getFluidState(blockposition);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public final boolean hasChunkAt(BlockPos pos) {
|
||||||
|
+ return getChunkIfLoaded(pos.getX() >> 4, pos.getZ() >> 4) != null; // Paper - Perf: Optimize Level.hasChunkAt(BlockPosition)Z
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ public final boolean isLoadedAndInBounds(BlockPos blockposition) { // Paper - final for inline
|
+ public final boolean isLoadedAndInBounds(BlockPos blockposition) { // Paper - final for inline
|
||||||
+ return getWorldBorder().isWithinBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
|
+ return getWorldBorder().isWithinBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
|
||||||
+ }
|
+ }
|
||||||
@@ -276,13 +281,13 @@
|
|||||||
+ return getWorldBorder().isWithinBounds(blockposition) ? getBlockStateIfLoaded(blockposition) : null;
|
+ return getWorldBorder().isWithinBounds(blockposition) ? getBlockStateIfLoaded(blockposition) : null;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
@Override
|
||||||
public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
|
public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create);
|
ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
|
||||||
if (ichunkaccess == null && create) {
|
if (ichunkaccess == null && create) {
|
||||||
@@ -207,6 +376,18 @@
|
@@ -207,6 +381,18 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
|
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
|
||||||
@@ -301,7 +306,7 @@
|
|||||||
if (this.isOutsideBuildHeight(pos)) {
|
if (this.isOutsideBuildHeight(pos)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (!this.isClientSide && this.isDebug()) {
|
} else if (!this.isClientSide && this.isDebug()) {
|
||||||
@@ -214,45 +395,124 @@
|
@@ -214,45 +400,124 @@
|
||||||
} else {
|
} else {
|
||||||
LevelChunk chunk = this.getChunkAt(pos);
|
LevelChunk chunk = this.getChunkAt(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
@@ -441,7 +446,7 @@
|
|||||||
public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {}
|
public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -340,10 +600,18 @@
|
@@ -340,10 +605,18 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlockState(BlockPos pos) {
|
public BlockState getBlockState(BlockPos pos) {
|
||||||
@@ -461,7 +466,7 @@
|
|||||||
|
|
||||||
return chunk.getBlockState(pos);
|
return chunk.getBlockState(pos);
|
||||||
}
|
}
|
||||||
@@ -446,14 +714,21 @@
|
@@ -446,14 +719,21 @@
|
||||||
this.pendingBlockEntityTickers.clear();
|
this.pendingBlockEntityTickers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +492,7 @@
|
|||||||
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
|
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
|
||||||
tickingblockentity.tick();
|
tickingblockentity.tick();
|
||||||
}
|
}
|
||||||
@@ -461,17 +736,19 @@
|
@@ -461,17 +741,19 @@
|
||||||
|
|
||||||
this.tickingBlockEntities = false;
|
this.tickingBlockEntities = false;
|
||||||
gameprofilerfiller.pop();
|
gameprofilerfiller.pop();
|
||||||
@@ -512,7 +517,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,13 +787,29 @@
|
@@ -510,13 +792,29 @@
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||||
@@ -543,7 +548,7 @@
|
|||||||
this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity);
|
this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -643,7 +936,7 @@
|
@@ -643,7 +941,7 @@
|
||||||
|
|
||||||
for (int k = 0; k < j; ++k) {
|
for (int k = 0; k < j; ++k) {
|
||||||
EnderDragonPart entitycomplexpart = aentitycomplexpart[k];
|
EnderDragonPart entitycomplexpart = aentitycomplexpart[k];
|
||||||
@@ -552,7 +557,7 @@
|
|||||||
|
|
||||||
if (t0 != null && predicate.test(t0)) {
|
if (t0 != null && predicate.test(t0)) {
|
||||||
result.add(t0);
|
result.add(t0);
|
||||||
@@ -912,7 +1205,7 @@
|
@@ -912,7 +1210,7 @@
|
||||||
|
|
||||||
public static enum ExplosionInteraction implements StringRepresentable {
|
public static enum ExplosionInteraction implements StringRepresentable {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user