diff --git a/src/main/java/meteordevelopment/meteorclient/events/world/ChunkDataEvent.java b/src/main/java/meteordevelopment/meteorclient/events/world/ChunkDataEvent.java index 340f2583cc..438c8f1f57 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/world/ChunkDataEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/world/ChunkDataEvent.java @@ -5,21 +5,10 @@ package meteordevelopment.meteorclient.events.world; -import meteordevelopment.meteorclient.utils.misc.Pool; import net.minecraft.world.chunk.WorldChunk; -public class ChunkDataEvent { - private static final Pool INSTANCE = new Pool<>(ChunkDataEvent::new); - - public WorldChunk chunk; - - public static ChunkDataEvent get(WorldChunk chunk) { - ChunkDataEvent event = INSTANCE.get(); - event.chunk = chunk; - return event; - } - - public static void returnChunkDataEvent(ChunkDataEvent event) { - INSTANCE.free(event); - } -} +/** + * @implNote Shouldn't be put in a {@link meteordevelopment.meteorclient.utils.misc.Pool} to avoid a race-condition, or in a {@link ThreadLocal} as it is shared between threads. + * @author Crosby + */ +public record ChunkDataEvent(WorldChunk chunk) {} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java index f15d1c2750..cf9b5d7bb2 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java @@ -96,7 +96,7 @@ private void onPlaySound(PlaySoundS2CPacket packet, CallbackInfo info) { @Inject(method = "onChunkData", at = @At("TAIL")) private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo info) { WorldChunk chunk = client.world.getChunk(packet.getChunkX(), packet.getChunkZ()); - MeteorClient.EVENT_BUS.post(ChunkDataEvent.get(chunk)); + MeteorClient.EVENT_BUS.post(new ChunkDataEvent(chunk)); } @Inject(method = "onScreenHandlerSlotUpdate", at = @At("TAIL")) 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 2f9a9063bc..39b6096f4a 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 @@ -96,7 +96,7 @@ public void onActivate() { } for (Chunk chunk : Utils.chunks()) { - searchChunk(chunk, null); + searchChunk(chunk); } lastDimension = PlayerUtils.getDimension(); @@ -153,10 +153,10 @@ public void removeGroup(ESPGroup group) { @EventHandler private void onChunkData(ChunkDataEvent event) { - searchChunk(event.chunk, event); + searchChunk(event.chunk()); } - private void searchChunk(Chunk chunk, ChunkDataEvent event) { + private void searchChunk(Chunk chunk) { MeteorExecutor.execute(() -> { if (!isActive()) return; ESPChunk schunk = ESPChunk.searchChunk(chunk, blocks.get()); @@ -173,8 +173,6 @@ private void searchChunk(Chunk chunk, ChunkDataEvent event) { updateChunk(chunk.getPos().x, chunk.getPos().z + 1); } } - - if (event != null) ChunkDataEvent.returnChunkDataEvent(event); }); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java index 3cfc6b6d86..92b79a7c65 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java @@ -94,13 +94,13 @@ public void onActivate() { @EventHandler private void onChunkData(ChunkDataEvent event) { // Check the distance. - double chunkXAbs = Math.abs(event.chunk.getPos().x * 16); - double chunkZAbs = Math.abs(event.chunk.getPos().z * 16); + double chunkXAbs = Math.abs(event.chunk().getPos().x * 16); + double chunkZAbs = Math.abs(event.chunk().getPos().z * 16); if (Math.sqrt(chunkXAbs * chunkXAbs + chunkZAbs * chunkZAbs) < minimumDistance.get()) return; - Chunk chunk = new Chunk(event.chunk.getPos()); + Chunk chunk = new Chunk(event.chunk().getPos()); - for (BlockEntity blockEntity : event.chunk.getBlockEntities().values()) { + for (BlockEntity blockEntity : event.chunk().getBlockEntities().values()) { if (!storageBlocks.get().contains(blockEntity.getType())) continue; if (blockEntity instanceof ChestBlockEntity) chunk.chests++; @@ -133,8 +133,6 @@ private void onChunkData(ChunkDataEvent event) { } } } - - ChunkDataEvent.returnChunkDataEvent(event); } @Override