Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 325
src/client/java/com/goldclient/modules/SusChunksFinder.java
package com.goldclient.modules;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.levelgen.Heightmap;
import java.util.HashSet;
import java.util.Set;
public final class SusChunksFinder extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting<Integer> radius = sgGeneral.add(new IntSetting.Builder()
.name("radius")
.description("Chunk radius around you to inspect. Only already-loaded chunks are scanned.")
.defaultValue(6)
.range(1, 16)
.sliderRange(1, 12)
.build()
);
private final Setting<Integer> minimumContainers = sgGeneral.add(new IntSetting.Builder()
.name("minimum-containers")
.description("Flag chunks with at least this many chests, barrels, hoppers, or spawners.")
.defaultValue(3)
.range(1, 32)
.sliderRange(1, 12)
.build()
);
private final Setting<Integer> minimumCrops = sgGeneral.add(new IntSetting.Builder()
.name("minimum-crops")
.description("Flag surface crop patches with at least this many crop blocks.")
.defaultValue(32)
.range(8, 256)
.sliderRange(8, 96)
.build()
);
private final Set<Long> scannedChunks = new HashSet<>();
private final Set<Long> reportedChunks = new HashSet<>();
private ClientLevel lastLevel;
private int cursor;
private int ticks;
public SusChunksFinder() {
super(Categories.Render, "sus-chunks-finder", "Find loaded chunks with unusually dense storage or surface crop patches.");
}
@Override
public void onActivate() {
scannedChunks.clear();
reportedChunks.clear();
lastLevel = mc.level;
cursor = 0;
ticks = 0;
}
@EventHandler
private void onTick(TickEvent.Pre event) {
if (mc.level == null || mc.player == null) return;
if (lastLevel != mc.level) {
scannedChunks.clear();
reportedChunks.clear();
lastLevel = mc.level;
cursor = 0;
}
if (++ticks % 2 != 0) return;
int scanRadius = radius.get();
int diameter = scanRadius * 2 + 1;
int candidateCount = diameter * diameter;
int index = Math.floorMod(cursor++, candidateCount);
ChunkPos playerChunk = mc.player.chunkPosition();
int chunkX = playerChunk.x() + index % diameter - scanRadius;
int chunkZ = playerChunk.z() + index / diameter - scanRadius;
long key = pack(chunkX, chunkZ);
if (scannedChunks.contains(key)) return;
LevelChunk chunk = mc.level.getChunkSource().getChunk(chunkX, chunkZ, ChunkStatus.FULL, false);
if (chunk == null) return;
scannedChunks.add(key);
inspectChunk(mc.level, chunk, chunkX, chunkZ, key);
}
private void inspectChunk(ClientLevel level, LevelChunk chunk, int chunkX, int chunkZ, long key) {
int containers = 0;
for (BlockPos pos : chunk.getBlockEntities().keySet()) {
Block block = chunk.getBlockState(pos).getBlock();
if (block == Blocks.CHEST || block == Blocks.BARREL || block == Blocks.HOPPER || block == Blocks.SPAWNER) {
containers++;
}
}
int crops = countSurfaceCrops(level, chunk, chunkX, chunkZ);
if (containers < minimumContainers.get() && crops < minimumCrops.get()) return;
if (!reportedChunks.add(key)) return;
info("Suspicious chunk at X %d Z %d (%d containers, %d crops)", chunkX, chunkZ, containers, crops);
}
private int countSurfaceCrops(ClientLevel level, LevelChunk chunk, int chunkX, int chunkZ) {
int crops = 0;
for (int localX = 0; localX < 16; localX++) {
for (int localZ = 0; localZ < 16; localZ++) {
int surfaceY = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, localX, localZ);
int firstY = Math.max(level.getMinY(), surfaceY - 8);
int lastY = Math.min(level.getMaxY(), surfaceY);
for (int y = firstY; y < lastY; y++) {
Block block = chunk.getBlockState(new BlockPos(chunkX * 16 + localX, y, chunkZ * 16 + localZ)).getBlock();
if (block == Blocks.WHEAT || block == Blocks.CARROTS || block == Blocks.POTATOES || block == Blocks.BEETROOTS) {
crops++;
}
}
}
}
return crops;
}
private static long pack(int x, int z) {
return ((long) x << 32) ^ (z & 0xffffffffL);
}
@Override
public String getInfoString() {
return Integer.toString(reportedChunks.size());
}
}