From 31ba17d0856b809ed71291323be06e89046f6edd Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Fri, 18 Mar 2022 19:49:02 +0000 Subject: [PATCH 1/2] Don't wait for the chunk to be loaded when checking for monitors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's a couple of alternative ways to solve this. Ideally we'd send our network messages at the same time as MC does (ChunkManager.playerLoadedChunk), but this'd require a mixin. Instead we just rely on the fact that if the chunk isn't loaded, monitors won't have done anything and so we don't need to send their contents! Fixes #1047, probably doesn't cause any regressions. I've not seen any issues on 1.16, but I also hadn't before so ¯\_(ツ)_/¯. --- .../shared/peripheral/monitor/MonitorWatcher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java index 81caa89e2..c390d7b30 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java @@ -15,7 +15,6 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.world.ChunkWatchEvent; @@ -47,8 +46,10 @@ static void enqueue( TileMonitor monitor ) @SubscribeEvent public static void onWatch( ChunkWatchEvent.Watch event ) { + // Get the current chunk if it has been loaded. This is safe as, if the chunk hasn't been loaded yet, then the + // monitor will have no contents, and so we won't need to send an update anyway. ChunkPos chunkPos = event.getPos(); - Chunk chunk = (Chunk) event.getWorld().getChunk( chunkPos.x, chunkPos.z, ChunkStatus.FULL, false ); + Chunk chunk = event.getWorld().getChunkSource().getChunkNow( chunkPos.x, chunkPos.z ); if( chunk == null ) return; for( TileEntity te : chunk.getBlockEntities().values() ) From 2c6418696525b84e5142960d9073d42ad5898839 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 23 Mar 2022 08:36:09 +0000 Subject: [PATCH 2/2] Bump version to 1.100.4 --- gradle.properties | 2 +- .../resources/data/computercraft/lua/rom/help/changelog.md | 5 +++++ .../resources/data/computercraft/lua/rom/help/whatsnew.md | 7 ++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1595760c5..3e2464221 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Mod properties -mod_version=1.100.3 +mod_version=1.100.4 # Minecraft properties (update mods.toml when changing) mc_version=1.16.5 diff --git a/src/main/resources/data/computercraft/lua/rom/help/changelog.md b/src/main/resources/data/computercraft/lua/rom/help/changelog.md index 4d5888949..a27cc478c 100644 --- a/src/main/resources/data/computercraft/lua/rom/help/changelog.md +++ b/src/main/resources/data/computercraft/lua/rom/help/changelog.md @@ -1,3 +1,8 @@ +# New features in CC: Tweaked 1.100.4 + +Several bug fixes: +* Fix the monitor watching blocking the main thread when chunks are slow to load. + # New features in CC: Tweaked 1.100.3 Several bug fixes: diff --git a/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md b/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md index ce9e428f4..190f08559 100644 --- a/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md +++ b/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md @@ -1,9 +1,6 @@ -New features in CC: Tweaked 1.100.3 +New features in CC: Tweaked 1.100.4 Several bug fixes: -* Fix client disconnect when uploading large files. -* Correctly handling empty computer ID file. -* Fix the normal turtle recipe not being unlocked. -* Remove turtle fake EntityType. +* Fix the monitor watching blocking the main thread when chunks are slow to load. Type "help changelog" to see the full version history.