From 467b2343aa0fa237769bdbd658fb6b76f64bd17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:08:55 +0800 Subject: [PATCH 1/2] refactor: use Minecraft executors --- .../modules/render/blockesp/BlockESP.java | 52 +++++++++---------- .../modules/render/blockesp/ESPChunk.java | 4 +- .../meteorclient/utils/network/Http.java | 5 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java index 8cfe86c072..1ca0ed117d 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java @@ -21,6 +21,7 @@ import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.orbit.EventHandler; import net.minecraft.block.Block; +import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.Chunk; @@ -30,8 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.Executor; public class BlockESP extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); @@ -80,7 +80,7 @@ public class BlockESP extends Module { private final Long2ObjectMap chunks = new Long2ObjectOpenHashMap<>(); private final Set groups = new ReferenceOpenHashSet<>(); - private final ExecutorService workerThread = Executors.newSingleThreadExecutor(); + private final Executor workerThread = Util.getMainWorkerExecutor().named("BlockESP"); private DimensionType lastDimension; @@ -159,7 +159,7 @@ private void onChunkData(ChunkDataEvent event) { } private void searchChunk(Chunk chunk) { - workerThread.submit(() -> { + workerThread.execute(() -> { if (!isActive()) return; ESPChunk schunk = ESPChunk.searchChunk(chunk, blocks.get()); @@ -192,36 +192,36 @@ private void onBlockUpdate(BlockUpdateEvent event) { boolean added = blocks.get().contains(event.newState.getBlock()) && !blocks.get().contains(event.oldState.getBlock()); boolean removed = !added && !blocks.get().contains(event.newState.getBlock()) && blocks.get().contains(event.oldState.getBlock()); - if (added || removed) { - workerThread.submit(() -> { - synchronized (chunks) { - ESPChunk chunk = chunks.get(key); + if (!added && !removed) return; - if (chunk == null) { - chunk = new ESPChunk(chunkX, chunkZ); - if (chunk.shouldBeDeleted()) return; + workerThread.execute(() -> { + synchronized (chunks) { + ESPChunk chunk = chunks.get(key); - chunks.put(key, chunk); - } + if (chunk == null) { + chunk = new ESPChunk(chunkX, chunkZ); + if (chunk.shouldBeDeleted()) return; + + chunks.put(key, chunk); + } - blockPos.set(bx, by, bz); + blockPos.set(bx, by, bz); - if (added) chunk.add(blockPos); - else chunk.remove(blockPos); + if (added) chunk.add(blockPos); + else chunk.remove(blockPos); - // Update neighbour blocks - for (int x = -1; x < 2; x++) { - for (int z = -1; z < 2; z++) { - for (int y = -1; y < 2; y++) { - if (x == 0 && y == 0 && z == 0) continue; + // Update neighbour blocks + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + for (int y = -1; y < 2; y++) { + if (x == 0 && y == 0 && z == 0) continue; - updateBlock(bx + x, by + y, bz + z); - } + updateBlock(bx + x, by + y, bz + z); } } } - }); - } + } + }); } @EventHandler @@ -239,7 +239,7 @@ private void onRender(Render3DEvent event) { ESPChunk chunk = it.next(); if (chunk.shouldBeDeleted()) { - workerThread.submit(() -> { + workerThread.execute(() -> { for (ESPBlock block : chunk.blocks.values()) { block.group.remove(block, false); block.loaded = false; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPChunk.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPChunk.java index 0fac693cf3..f116134dc7 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPChunk.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPChunk.java @@ -15,7 +15,7 @@ import net.minecraft.world.Heightmap; import net.minecraft.world.chunk.Chunk; -import java.util.List; +import java.util.Collection; import static meteordevelopment.meteorclient.MeteorClient.mc; import static meteordevelopment.meteorclient.utils.Utils.getRenderDistance; @@ -86,7 +86,7 @@ public void render(Render3DEvent event) { } - public static ESPChunk searchChunk(Chunk chunk, List blocks) { + public static ESPChunk searchChunk(Chunk chunk, Collection blocks) { ESPChunk schunk = new ESPChunk(chunk.getPos().x, chunk.getPos().z); if (schunk.shouldBeDeleted()) return schunk; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java b/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java index f74b7b04f5..95e8fd13b4 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java @@ -8,6 +8,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import meteordevelopment.meteorclient.utils.other.JsonDateDeserializer; +import net.minecraft.util.Util; import javax.annotation.Nullable; import java.io.IOException; @@ -29,7 +30,9 @@ public class Http { public static final int FORBIDDEN = 403; public static final int NOT_FOUND = 404; - private static final HttpClient CLIENT = HttpClient.newHttpClient(); + private static final HttpClient CLIENT = HttpClient.newBuilder() + .executor(Util.getDownloadWorkerExecutor()) + .build(); private static final Gson GSON = new GsonBuilder() .registerTypeAdapter(Date.class, new JsonDateDeserializer()) From a8f34c8309945319ab78a6df11f927fee626795c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Sat, 11 Oct 2025 01:46:23 +0800 Subject: [PATCH 2/2] revert BlockESP --- .../modules/render/blockesp/BlockESP.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java index 1ca0ed117d..9ca00c7a30 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/BlockESP.java @@ -17,21 +17,22 @@ import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.Utils; +import meteordevelopment.meteorclient.utils.player.PlayerUtils; import meteordevelopment.meteorclient.utils.render.color.RainbowColors; import meteordevelopment.meteorclient.utils.render.color.SettingColor; +import meteordevelopment.meteorclient.utils.world.Dimension; import meteordevelopment.orbit.EventHandler; import net.minecraft.block.Block; -import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.dimension.DimensionType; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class BlockESP extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); @@ -80,9 +81,9 @@ public class BlockESP extends Module { private final Long2ObjectMap chunks = new Long2ObjectOpenHashMap<>(); private final Set groups = new ReferenceOpenHashSet<>(); - private final Executor workerThread = Util.getMainWorkerExecutor().named("BlockESP"); + private final ExecutorService workerThread = Executors.newSingleThreadExecutor(); - private DimensionType lastDimension; + private Dimension lastDimension; public BlockESP() { super(Categories.Render, "block-esp", "Renders specified blocks through walls.", "search"); @@ -101,7 +102,7 @@ public void onActivate() { searchChunk(chunk); } - lastDimension = mc.world.getDimension(); + lastDimension = PlayerUtils.getDimension(); } @Override @@ -159,7 +160,7 @@ private void onChunkData(ChunkDataEvent event) { } private void searchChunk(Chunk chunk) { - workerThread.execute(() -> { + workerThread.submit(() -> { if (!isActive()) return; ESPChunk schunk = ESPChunk.searchChunk(chunk, blocks.get()); @@ -192,43 +193,44 @@ private void onBlockUpdate(BlockUpdateEvent event) { boolean added = blocks.get().contains(event.newState.getBlock()) && !blocks.get().contains(event.oldState.getBlock()); boolean removed = !added && !blocks.get().contains(event.newState.getBlock()) && blocks.get().contains(event.oldState.getBlock()); - if (!added && !removed) return; - - workerThread.execute(() -> { - synchronized (chunks) { - ESPChunk chunk = chunks.get(key); + if (added || removed) { + workerThread.submit(() -> { + synchronized (chunks) { + ESPChunk chunk = chunks.get(key); - if (chunk == null) { - chunk = new ESPChunk(chunkX, chunkZ); - if (chunk.shouldBeDeleted()) return; + if (chunk == null) { + chunk = new ESPChunk(chunkX, chunkZ); + if (chunk.shouldBeDeleted()) return; - chunks.put(key, chunk); - } + chunks.put(key, chunk); + } - blockPos.set(bx, by, bz); + blockPos.set(bx, by, bz); - if (added) chunk.add(blockPos); - else chunk.remove(blockPos); + if (added) chunk.add(blockPos); + else chunk.remove(blockPos); - // Update neighbour blocks - for (int x = -1; x < 2; x++) { - for (int z = -1; z < 2; z++) { - for (int y = -1; y < 2; y++) { - if (x == 0 && y == 0 && z == 0) continue; + // Update neighbour blocks + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + for (int y = -1; y < 2; y++) { + if (x == 0 && y == 0 && z == 0) continue; - updateBlock(bx + x, by + y, bz + z); + updateBlock(bx + x, by + y, bz + z); + } } } } - } - }); + }); + } } @EventHandler private void onPostTick(TickEvent.Post event) { - DimensionType dimension = mc.world.getDimension(); + Dimension dimension = PlayerUtils.getDimension(); if (lastDimension != dimension) onActivate(); + lastDimension = dimension; }