From cec8e6fd9d265f2d18f8263b303f1d630f4100b8 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Tue, 16 Jul 2024 18:32:30 -0700 Subject: [PATCH] Optimise chunk tick checking during chunk tick We don't need to check for this with the chunk system, as ticking chunks are actually guaranteed to ticking. Additionally, ticking chunks may only become non-ticking during the chunk holder manager tick - which will not happen during chunk ticking. --- .../chunk_system/DistanceManagerMixin.java | 3 +- .../chunk_system/ServerChunkCacheMixin.java | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java index b7a115d5..af78d2a5 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java @@ -86,8 +86,7 @@ public abstract class DistanceManagerMixin implements ChunkSystemDistanceManager value = "RETURN" ) ) - private void destroyFields(final Executor executor, final Executor executor2, - final CallbackInfo ci) { + private void destroyFields(final CallbackInfo ci) { this.tickets = null; this.ticketTracker = null; this.tickingTicketsTracker = null; diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCacheMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCacheMixin.java index 54472225..c17034c1 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCacheMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCacheMixin.java @@ -16,6 +16,7 @@ import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkSource; import net.minecraft.world.level.chunk.LevelChunk; @@ -298,4 +299,36 @@ private void midTickChunks(final CallbackInfo ci) { ((ChunkSystemMinecraftServer)this.level.getServer()).moonrise$executeMidTickTasks(); } + + /** + * @reason In the chunk system, ticking chunks always have loaded entities. Of course, they are also always + * marked to be as ticking as well. + * @author Spottedleaf + */ + @Redirect( + method = "tickChunks", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/level/ServerLevel;isNaturalSpawningAllowed(Lnet/minecraft/world/level/ChunkPos;)Z" + ) + ) + private boolean shortNaturalSpawning(final ServerLevel instance, final ChunkPos chunkPos) { + return true; + } + + /** + * @reason In the chunk system, ticking chunks always have loaded entities. Of course, they are also always + * marked to be as ticking as well. + * @author Spottedleaf + */ + @Redirect( + method = "tickChunks", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/level/ServerLevel;shouldTickBlocksAt(J)Z" + ) + ) + private boolean shortShouldTickBlocks(final ServerLevel instance, final long pos) { + return true; + } }