NewChunks module

NewChunks: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, LiquidBounce (Kotlin)).

2 implementationsRENDER

Full module source: 2 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/NewChunks.javaJava · 384 lines · 15.1 KB

Marks fresh and old chunks that load whilst this is on.

SettingsShow old chunksShow unjudgedNew colourOld colourUnjudged colourFillFollow heightHeightDistanceSettle timeMin spreadShow reasonsOpacityLog chunksNotice
NewChunks.javaJava · Minecraft 26.2 · 384 lines · 15.1 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.OfflineClient;
4
import com.jellypudding.offlineclient.event.Subscribe;
5
import com.jellypudding.offlineclient.event.events.PacketReceiveEvent;
6
import com.jellypudding.offlineclient.event.events.Render3DEvent;
7
import com.jellypudding.offlineclient.event.events.TickEvent;
8
import com.jellypudding.offlineclient.module.Category;
9
import com.jellypudding.offlineclient.module.Module;
10
import com.jellypudding.offlineclient.render.DrawBatch;
11
import com.jellypudding.offlineclient.setting.BoolSetting;
12
import com.jellypudding.offlineclient.setting.ColorSetting;
13
import com.jellypudding.offlineclient.setting.NumberSetting;
14
import com.jellypudding.offlineclient.util.ChatUtil;
15
import com.jellypudding.offlineclient.util.ColorUtil;
16
import net.minecraft.core.BlockPos;
17
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
18
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
19
import net.minecraft.world.level.ChunkPos;
20
import net.minecraft.world.level.Level;
21
import net.minecraft.world.level.block.state.BlockState;
22
import net.minecraft.world.level.chunk.LevelChunk;
23
import net.minecraft.world.level.chunk.LevelChunkSection;
24
import net.minecraft.world.level.chunk.status.ChunkStatus;
25
import net.minecraft.world.level.material.FluidState;
26
import net.minecraft.world.phys.AABB;
27
28
import java.lang.ref.WeakReference;
29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.HashSet;
32
import java.util.Iterator;
33
import java.util.LinkedHashMap;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Queue;
37
import java.util.Set;
38
import java.util.concurrent.ConcurrentLinkedQueue;
39
40
// Judges chunks fresh or old by watching when their liquid starts to flow.
41
// Liquid already flowing on arrival means the chunk was loaded from disk.
42
public final class NewChunks extends Module {
43
44
    private static final int MAX_CHUNKS = 16384;
45
46
    private final BoolSetting showOld = new BoolSetting("Show old chunks",
47
        "Also draws the chunks judged old since you switched this on.", false);
48
    private final BoolSetting showUnjudged = new BoolSetting("Show unjudged",
49
        "Also draws the chunks that arrived without enough liquid to judge.", false);
50
    private final ColorSetting newColor = new ColorSetting("New colour",
51
        "Colour of the fresh chunks.", 0, false);
52
    private final ColorSetting oldColor = new ColorSetting("Old colour",
53
        "Colour of the chunks that were already on disk.", 220, false)
54
        .under(showOld);
55
    private final ColorSetting unjudgedColor = new ColorSetting("Unjudged colour",
56
        "Colour of the chunks with no verdict.", 60, false)
57
        .under(showUnjudged);
58
    private final BoolSetting fill = new BoolSetting("Fill",
59
        "Adds a faint tint inside each square.", true);
60
    private final BoolSetting followHeight = new BoolSetting("Follow height",
61
        "Draws the squares at your own height instead of a fixed one.", true);
62
    private final NumberSetting drawHeight = new NumberSetting("Height",
63
        "The height the squares sit at.", 64, -64, 320, 1)
64
        .min(-2048).max(2048).unless(followHeight);
65
    private final NumberSetting distance = new NumberSetting("Distance",
66
        "How far away a chunk may be and still be drawn.", 16, 4, 64, 1, " chunks")
67
        .min(1).max(256);
68
    private final NumberSetting settle = new NumberSetting("Settle time",
69
        "How long after a chunk lands a liquid flow still counts as fresh.", 60, 5, 300, 5, "s")
70
        .min(1).max(3600);
71
    private final NumberSetting minSpread = new NumberSetting("Min spread",
72
        "How far a flow must have run from its source before it proves a chunk old. Raise it on servers that tick chunks before sending them.",
73
        3, 1, 7, 1, " blocks").min(1).max(7);
74
    private final BoolSetting showReasons = new BoolSetting("Show reasons",
75
        "Marks the liquid block that decided each verdict.", false);
76
    private final NumberSetting opacity = new NumberSetting("Opacity",
77
        "How solid the squares are drawn.", 75, 10, 100, 5, "%").min(1).max(100);
78
    private final BoolSetting logChunks = new BoolSetting("Log chunks",
79
        "Writes every verdict to the game log so you can read them back later.", false);
80
    private final BoolSetting notice = new BoolSetting("Notice",
81
        "Explains the limits in chat when you switch this on.", true);
82
83
    private final Set<Long> newChunks = new HashSet<>();
84
    private final Set<Long> oldChunks = new HashSet<>();
85
86
    // Insertion ordered. Every chunk that landed whilst this ran mapped to its tick.
87
    private final Map<Long, Integer> watched = new LinkedHashMap<>();
88
89
    // Filled from the network thread and drained on the next tick.
90
    private final Queue<BlockPos> flowing = new ConcurrentLinkedQueue<>();
91
92
    // The block that decided each verdict. Drawn by the Show reasons setting.
93
    private final Map<Long, BlockPos> reasons = new HashMap<>();
94
95
    // The chunks in range of the last rebuild kept apart by verdict. Colours are
96
    // resolved at draw time because a rainbow setting moves every frame.
97
    private final List<Long> visibleNew = new ArrayList<>();
98
    private final List<Long> visibleOld = new ArrayList<>();
99
    private final List<Long> visibleUnjudged = new ArrayList<>();
100
101
    private long visibleAt = Long.MIN_VALUE;
102
    private int revision;
103
    private int drawnRevision = -1;
104
    private int drawnLayout = -1;
105
106
    private WeakReference<Level> world;
107
    private int ticks;
108
109
    public NewChunks() {
110
        super("NewChunks", "Marks fresh and old chunks that load whilst this is on.",
111
            Category.RENDER);
112
        addSettings(showOld, showUnjudged, newColor, oldColor, unjudgedColor, opacity, fill,
113
            followHeight, drawHeight, distance, settle, minSpread, showReasons, logChunks, notice);
114
        searchTags("new chunks", "fresh terrain", "exploit");
115
    }
116
117
    @Override
118
    public String getSuffix() {
119
        int unjudged = Math.max(0, watched.size() - newChunks.size() - oldChunks.size());
120
        return newChunks.size() + " new " + oldChunks.size() + " old " + unjudged + " unjudged";
121
    }
122
123
    @Override
124
    protected void onEnable() {
125
        reset();
126
        if (notice.isOn()) {
127
            ChatUtil.message("§bNewChunks §7only judges chunks that load whilst it is on. "
128
                + "Switch it on before you explore. A server that ticks a chunk before sending it "
129
                + "can make a fresh one read as old. Raise Min spread if that happens.");
130
        }
131
    }
132
133
    @Override
134
    protected void onDisable() {
135
        reset();
136
    }
137
138
    private void reset() {
139
        newChunks.clear();
140
        oldChunks.clear();
141
        watched.clear();
142
        reasons.clear();
143
        flowing.clear();
144
        clearVisible();
145
        visibleAt = Long.MIN_VALUE;
146
        revision++;
147
        ticks = 0;
148
    }
149
150
    // The oldest chunk drops once the store is full.
151
    private void remember(long key) {
152
        watched.put(key, ticks);
153
        revision++;
154
        if (watched.size() <= MAX_CHUNKS) {
155
            return;
156
        }
157
        Iterator<Long> iterator = watched.keySet().iterator();
158
        while (watched.size() > MAX_CHUNKS && iterator.hasNext()) {
159
            long eldest = iterator.next();
160
            iterator.remove();
161
            newChunks.remove(eldest);
162
            oldChunks.remove(eldest);
163
            reasons.remove(eldest);
164
        }
165
    }
166
167
    // Called from ClientPacketListenerMixin the moment a chunk lands. Every later
168
    // packet is still waiting. No flow update has been written into it yet.
169
    public void onChunkLoaded(int x, int z) {
170
        if (!isEnabled() || mc.level == null || !sameWorld()) {
171
            return;
172
        }
173
        long key = ChunkPos.pack(x, z);
174
        if (watched.containsKey(key)) {
175
            // A second arrival keeps the first verdict.
176
            return;
177
        }
178
        remember(key);
179
180
        LevelChunk chunk = mc.level.getChunkSource().getChunk(x, z, ChunkStatus.FULL, false);
181
        if (chunk == null) {
182
            return;
183
        }
184
        BlockPos found = findFlowingLiquid(chunk, minSpread.getInt());
185
        if (found != null) {
186
            oldChunks.add(key);
187
            reasons.put(key, found);
188
            log("old", x, z);
189
        }
190
    }
191
192
    private void log(String verdict, int x, int z) {
193
        if (logChunks.isOn()) {
194
            OfflineClient.LOG.info("NewChunks {} chunk at {} {}", verdict, x * 16, z * 16);
195
        }
196
    }
197
198
    // A rejoin gives a fresh level object even in the same dimension.
199
    private boolean sameWorld() {
200
        if (world != null && world.get() == mc.level) {
201
            return true;
202
        }
203
        world = new WeakReference<>(mc.level);
204
        reset();
205
        return false;
206
    }
207
208
    // Fired on the netty thread.
209
    @Subscribe
210
    private void onPacketReceive(PacketReceiveEvent event) {
211
        if (event.getPacket() instanceof ClientboundBlockUpdatePacket update) {
212
            noteFlow(update.getPos(), update.getBlockState());
213
        } else if (event.getPacket() instanceof ClientboundSectionBlocksUpdatePacket update) {
214
            update.runUpdates(this::noteFlow);
215
        }
216
    }
217
218
    private void noteFlow(BlockPos pos, BlockState state) {
219
        FluidState fluid = state.getFluidState();
220
        if (!fluid.isEmpty() && !fluid.isSource()) {
221
            flowing.add(pos.immutable());
222
        }
223
    }
224
225
    @Subscribe
226
    private void onTick(TickEvent event) {
227
        if (!inGame()) {
228
            return;
229
        }
230
        if (!sameWorld()) {
231
            return;
232
        }
233
        ticks++;
234
235
        // A flow that turns up after the chunk landed means it was made just now.
236
        int window = settle.getInt() * 20;
237
        BlockPos pos;
238
        while ((pos = flowing.poll()) != null) {
239
            long key = ChunkPos.pack(pos);
240
            Integer seen = watched.get(key);
241
            if (seen == null || oldChunks.contains(key)) {
242
                continue;
243
            }
244
            if (ticks - seen <= window && newChunks.add(key)) {
245
                reasons.put(key, pos);
246
                revision++;
247
                log("new", ChunkPos.getX(key), ChunkPos.getZ(key));
248
            }
249
        }
250
    }
251
252
    // The first flowing liquid in the chunk or null. The palette test is only a prefilter
253
    // and every hit is confirmed against the real blocks.
254
    private static BlockPos findFlowingLiquid(LevelChunk chunk, int spread) {
255
        LevelChunkSection[] sections = chunk.getSections();
256
        int minY = chunk.getMinY();
257
        int minX = chunk.getPos().getMinBlockX();
258
        int minZ = chunk.getPos().getMinBlockZ();
259
        for (int i = 0; i < sections.length; i++) {
260
            LevelChunkSection section = sections[i];
261
            if (section == null || section.hasOnlyAir() || !section.hasFluid()
262
                || !section.maybeHas(NewChunks::isFlowing)) {
263
                continue;
264
            }
265
            for (int y = 0; y < 16; y++) {
266
                for (int x = 0; x < 16; x++) {
267
                    for (int z = 0; z < 16; z++) {
268
                        if (spreadOf(section.getBlockState(x, y, z)) >= spread) {
269
                            return new BlockPos(minX + x, minY + i * 16 + y, minZ + z);
270
                        }
271
                    }
272
                }
273
            }
274
        }
275
        return null;
276
    }
277
278
    private static boolean isFlowing(BlockState state) {
279
        FluidState fluid = state.getFluidState();
280
        return !fluid.isEmpty() && !fluid.isSource();
281
    }
282
283
    // How many blocks a flow has run from its source. A source is zero and
284
    // each block of flow drops the level by one. Falling liquid reads as one.
285
    private static int spreadOf(BlockState state) {
286
        FluidState fluid = state.getFluidState();
287
        if (fluid.isEmpty() || fluid.isSource()) {
288
            return 0;
289
        }
290
        return Math.max(1, 8 - fluid.getAmount());
291
    }
292
293
    @Subscribe
294
    private void onRender3D(Render3DEvent event) {
295
        if (!inGame()) {
296
            return;
297
        }
298
        int centerX = mc.player.chunkPosition().x();
299
        int centerZ = mc.player.chunkPosition().z();
300
        long here = ChunkPos.pack(centerX, centerZ);
301
        int layout = layoutKey();
302
        if (here != visibleAt || revision != drawnRevision || layout != drawnLayout) {
303
            rebuildVisible(centerX, centerZ);
304
            visibleAt = here;
305
            drawnRevision = revision;
306
            drawnLayout = layout;
307
        }
308
309
        double y = followHeight.isOn() ? mc.player.getY() : drawHeight.getValue();
310
        float share = opacity.getFloat() / 100f;
311
        drawAll(event.getBatch(), visibleNew, ColorUtil.fade(newColor.getColor(), share), y);
312
        drawAll(event.getBatch(), visibleOld, ColorUtil.fade(oldColor.getColor(), share), y);
313
        drawAll(event.getBatch(), visibleUnjudged,
314
            ColorUtil.fade(unjudgedColor.getColor(), share), y);
315
316
        if (showReasons.isOn()) {
317
            markReasons(event.getBatch(), visibleNew, newColor.getColor());
318
            markReasons(event.getBatch(), visibleOld, oldColor.getColor());
319
        }
320
    }
321
322
    // Draws the block that proved the verdict. Lets you check the call yourself.
323
    private void markReasons(DrawBatch batch, List<Long> chunks, int color) {
324
        for (long key : chunks) {
325
            BlockPos pos = reasons.get(key);
326
            if (pos != null) {
327
                batch.outlineBlock(pos, color, true);
328
            }
329
        }
330
    }
331
332
    private void drawAll(DrawBatch batch, List<Long> chunks, int color, double y) {
333
        for (long key : chunks) {
334
            square(batch, ChunkPos.getX(key) * 16, ChunkPos.getZ(key) * 16, y, color);
335
        }
336
    }
337
338
    private void clearVisible() {
339
        visibleNew.clear();
340
        visibleOld.clear();
341
        visibleUnjudged.clear();
342
    }
343
344
    // The settings that decide which chunks land in the visible lists.
345
    private int layoutKey() {
346
        return (showOld.isOn() ? 1 : 0) | (showUnjudged.isOn() ? 2 : 0) | distance.getInt() << 2;
347
    }
348
349
    // Walks the square of chunks around the player instead of the whole store. The work
350
    // per frame is then tied to the draw distance not to how far the player has gone.
351
    private void rebuildVisible(int centerX, int centerZ) {
352
        clearVisible();
353
        int limit = distance.getInt();
354
        boolean drawOld = showOld.isOn();
355
        boolean drawUnjudged = showUnjudged.isOn();
356
357
        for (int x = centerX - limit; x <= centerX + limit; x++) {
358
            for (int z = centerZ - limit; z <= centerZ + limit; z++) {
359
                long key = ChunkPos.pack(x, z);
360
                if (newChunks.contains(key)) {
361
                    visibleNew.add(key);
362
                } else if (oldChunks.contains(key)) {
363
                    if (drawOld) {
364
                        visibleOld.add(key);
365
                    }
366
                } else if (drawUnjudged && watched.containsKey(key)) {
367
                    visibleUnjudged.add(key);
368
                }
369
            }
370
        }
371
    }
372
373
    // A flat box has no edges to draw.
374
    private void square(DrawBatch batch, double x1, double z1, double y, int color) {
375
        double x2 = x1 + 16;
376
        double z2 = z1 + 16;
377
        batch.flatRect(x1, z1, x2, z2, y, color, true);
378
        if (fill.isOn()) {
379
            batch.solidBox(new AABB(x1, y, z1, x2, y + 0.02, z2),
380
                ColorUtil.withAlpha(color, 40), true);
381
        }
382
    }
383
}
384
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleNewChunks.ktKotlin · 155 lines · 5.4 KB

Highlights chunks that are likely newly generated.

SettingsRenderDistanceRenderYAutoYSmoothPersistNewColorOldColor
ModuleNewChunks.ktKotlin · Minecraft 26.2 · 155 lines · 5.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
package net.ccbluex.liquidbounce.features.module.modules.render
21
22
import net.ccbluex.liquidbounce.event.events.PacketEvent
23
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
24
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
25
import net.ccbluex.liquidbounce.event.handler
26
import net.ccbluex.liquidbounce.features.module.ClientModule
27
import net.ccbluex.liquidbounce.features.module.ModuleCategories
28
import net.ccbluex.liquidbounce.render.drawPlane
29
import net.ccbluex.liquidbounce.render.engine.type.Color4b
30
import net.ccbluex.liquidbounce.render.renderEnvironment
31
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
32
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket
33
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket
34
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket
35
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket
36
import net.minecraft.world.level.ChunkPos
37
import net.minecraft.world.level.ChunkPos.containing
38
import net.minecraft.world.phys.Vec3
39
import java.util.concurrent.ConcurrentHashMap
40
import kotlin.math.abs
41
import kotlin.math.max
42
43
/**
44
 * NewChunks module
45
 *
46
 * Highlights chunks that are likely newly generated.
47
 */
48
object ModuleNewChunks : ClientModule("NewChunks", ModuleCategories.RENDER) {
49
50
    private val renderDistance by int("RenderDistance", 32, 4..128, "chunks")
51
    private val renderY by float("RenderY", 0.0f, -64.0f..320.0f)
52
    private val autoY by boolean("AutoY", false)
53
54
    private val smooth by boolean("Smooth", true)
55
    private val persist by boolean("Persist", true)
56
57
    private val newColor by color("NewColor", Color4b(0, 255, 0, 80))
58
    private val oldColor by color("OldColor", Color4b(255, 0, 0, 80))
59
60
    private val chunks = ConcurrentHashMap<ChunkPos, Boolean>()
61
62
    private fun reset() {
63
        chunks.clear()
64
    }
65
66
    override fun onDisabled() = reset()
67
68
    @Suppress("unused")
69
    private val worldChangeHandler = handler<WorldChangeEvent> {
70
        reset()
71
    }
72
73
    @Suppress("unused")
74
    private val packetHandler = handler<PacketEvent> { event ->
75
        when (val packet = event.packet) {
76
            is ClientboundForgetLevelChunkPacket -> {
77
                if (!persist) {
78
                    chunks.remove(packet.pos)
79
                }
80
            }
81
82
            is ClientboundLevelChunkWithLightPacket -> {
83
                val pos = ChunkPos(packet.x, packet.z)
84
85
                chunks.putIfAbsent(pos, false)
86
            }
87
88
            is ClientboundSectionBlocksUpdatePacket -> {
89
                packet.runUpdates { bp, state ->
90
                    val fluid = state.fluidState
91
                    if (!fluid.isEmpty && !fluid.isSource) {
92
                        chunks[containing(bp)] = true
93
                    }
94
                }
95
            }
96
97
            is ClientboundBlockUpdatePacket -> {
98
                val fluid = packet.blockState.fluidState
99
                if (!fluid.isEmpty && !fluid.isSource) {
100
                    chunks[containing(packet.pos)] = true
101
                }
102
            }
103
        }
104
    }
105
106
    @Suppress("unused")
107
    private val renderHandler = handler<WorldRenderEvent> { event ->
108
        if (chunks.isEmpty()) return@handler
109
110
        val maxDist = renderDistance.toDouble() * 16.0
111
        val renderDistSq = maxDist * maxDist
112
113
        val drawY = if (autoY) player.y - 100.0 else renderY.toDouble()
114
115
        event.renderEnvironment {
116
            for ((chunk, isNew) in chunks) {
117
                val chunkX = chunk.minBlockX
118
                val chunkZ = chunk.minBlockZ
119
120
                if (player.distanceToSqr(chunkX + 8.0, player.y, chunkZ + 8.0) > renderDistSq) {
121
                    continue
122
                }
123
124
                var color = if (isNew) newColor else oldColor
125
126
                if (smooth && !isNew) {
127
                    var totalWeight = 0.0
128
129
                    for (dx in -2..2) {
130
                        for (dz in -2..2) {
131
                            if (dx == 0 && dz == 0) continue
132
133
                            if (chunks[ChunkPos(chunk.x + dx, chunk.z + dz)] == true) {
134
                                val dist = max(abs(dx), abs(dz))
135
136
                                totalWeight += (3.0 - dist) / 2.0
137
                            }
138
                        }
139
                    }
140
141
                    if (totalWeight > 0.0) {
142
                        val ratio = (totalWeight / 12.0).coerceAtMost(1.0)
143
144
                        color = oldColor.interpolateTo(newColor, ratio)
145
                    }
146
                }
147
148
                withPositionRelativeToCamera(Vec3(chunkX.toDouble(), drawY, chunkZ.toDouble())) {
149
                    drawPlane(16f, 16f, color, color.darker())
150
                }
151
            }
152
        }
153
    }
154
}
155