Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
8 228
src/client/java/dev/trailfinder/client/TrailfinderClient.java
package dev.trailfinder.client;
import java.util.HashMap;
import java.util.Map;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.block.AbstractPlantStemBlock;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.WorldChunk;
import org.lwjgl.glfw.GLFW;
public class TrailfinderClient implements ClientModInitializer {
public static boolean playerEsp = true;
public static boolean suspiciousChunks = true;
public static boolean matureKelp = true;
private static final int RADIUS = 8;
private static final int SIDE = RADIUS * 2 + 1;
private static final Map<Long, Findings> findings = new HashMap<>();
private static ClientWorld lastWorld;
private static int scanIndex;
private record Findings(int chunkX, int chunkZ, int activityY, int kelpY) {}
@Override
public void onInitializeClient() {
KeyBinding menu = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.trailfinder.menu", GLFW.GLFW_KEY_RIGHT_SHIFT,
KeyBinding.Category.create(Identifier.of("trailfinder", "main"))));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (menu.wasPressed()) {
if (client.currentScreen == null) client.setScreen(new TrailfinderScreen());
else if (client.currentScreen instanceof TrailfinderScreen) client.setScreen(null);
}
tick(client);
});
HudElementRegistry.addLast(Identifier.of("trailfinder", "player_esp"), (context, tickCounter) -> {
MinecraftClient client = MinecraftClient.getInstance();
if (client.world == null || client.player == null) return;
int y = 8;
if (playerEsp) {
for (var player : client.world.getPlayers()) {
if (player == client.player) continue;
context.drawTextWithShadow(client.textRenderer, player.getName(), 8, y, 0xFFFF5555);
y += 10;
}
}
for (Findings found : findings.values()) {
if (suspiciousChunks && found.activityY != Integer.MIN_VALUE) {
context.drawTextWithShadow(client.textRenderer, "Activity hint: chunk " + found.chunkX + ", " + found.chunkZ, 8, y, 0xFFFFAA00);
y += 10;
}
if (matureKelp && found.kelpY != Integer.MIN_VALUE) {
context.drawTextWithShadow(client.textRenderer, "Mature kelp: chunk " + found.chunkX + ", " + found.chunkZ, 8, y, 0xFF55FFAA);
y += 10;
}
}
});
}
private static void tick(MinecraftClient client) {
if (client.world != lastWorld) {
findings.clear();
lastWorld = client.world;
scanIndex = 0;
}
if (client.world == null || client.player == null) return;
ChunkPos center = new ChunkPos(client.player.getBlockPos());
findings.values().removeIf(f -> Math.abs(f.chunkX - center.x) > RADIUS || Math.abs(f.chunkZ - center.z) > RADIUS);
if (!suspiciousChunks && !matureKelp) return;
int x = center.x + scanIndex % SIDE - RADIUS;
int z = center.z + scanIndex / SIDE - RADIUS;
scanIndex = (scanIndex + 1) % (SIDE * SIDE);
long key = ((long) x << 32) | (z & 0xffffffffL);
WorldChunk chunk = client.world.getChunkManager().getChunk(x, z, ChunkStatus.FULL, false);
if (chunk == null) {
findings.remove(key);
return;
}
int[] y = {Integer.MIN_VALUE, Integer.MIN_VALUE};
chunk.forEachBlockMatchingPredicate(state -> state.isOf(Blocks.CHEST) || state.isOf(Blocks.TRAPPED_CHEST)
|| state.isOf(Blocks.CRAFTING_TABLE) || state.isOf(Blocks.FURNACE)
|| state.isOf(Blocks.ENDER_CHEST) || state.isOf(Blocks.KELP), (pos, state) -> {
if (state.isOf(Blocks.KELP)) {
if (state.get(AbstractPlantStemBlock.AGE) == AbstractPlantStemBlock.MAX_AGE) y[1] = pos.getY();
} else {
y[0] = pos.getY();
}
});
if (y[0] == Integer.MIN_VALUE && y[1] == Integer.MIN_VALUE) findings.remove(key);
else findings.put(key, new Findings(x, z, y[0], y[1]));
}
}