Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
20 4,028
src/client/java/com/kodari/basefinder/VisualModulesClient.java
package com.kodari.basefinder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
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.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.WorldChunk;
import org.lwjgl.glfw.GLFW;
public final class VisualModulesClient implements ClientModInitializer {
private static final String MOD_ID = "basefinder";
private static final int MAX_BLOCK_HIGHLIGHTS = 256;
private static final int BLOCK_SCAN_INTERVAL = 20;
private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(Identifier.of(MOD_ID, "visuals"));
private static final KeyBinding BLOCK_ESP_KEY = registerKey("key.basefinder.toggle_block_esp", GLFW.GLFW_KEY_F10);
private static final KeyBinding BLOCK_NOTIFIER_KEY = registerKey("key.basefinder.toggle_block_notifier", GLFW.GLFW_KEY_F11);
private static final KeyBinding FREE_CAM_KEY = registerKey("key.basefinder.toggle_free_cam", GLFW.GLFW_KEY_F4);
private static final KeyBinding FULLBRIGHT_KEY = registerKey("key.basefinder.toggle_fullbright", GLFW.GLFW_KEY_F5);
private static final KeyBinding JUMP_CIRCLES_KEY = registerKey("key.basefinder.toggle_jump_circles", GLFW.GLFW_KEY_F6);
private static final KeyBinding MOB_ESP_KEY = registerKey("key.basefinder.toggle_mob_esp", GLFW.GLFW_KEY_K);
private static final KeyBinding NAMETAGS_KEY = registerKey("key.basefinder.toggle_nametags", GLFW.GLFW_KEY_L);
private static final KeyBinding ORE_ESP_KEY = registerKey("key.basefinder.toggle_ore_esp", GLFW.GLFW_KEY_O);
private static final KeyBinding PEARL_TRAILS_KEY = registerKey("key.basefinder.toggle_pearl_trails", GLFW.GLFW_KEY_P);
private static boolean blockEspEnabled;
private static boolean blockNotifierEnabled;
private static boolean freeCamEnabled;
private static boolean fullbrightEnabled;
private static boolean jumpCirclesEnabled;
private static boolean mobEspEnabled;
private static boolean nametagsEnabled;
private static boolean oreEspEnabled;
private static boolean pearlTrailsEnabled;
private static int ticksUntilBlockScan;
private static int ticksUntilNotifierScan;
private static int ticksUntilMobScan;
private static int clientTick;
private static boolean wasAirborne;
private static boolean notifierInitialized;
private static double previousGamma;
private static boolean gammaCaptured;
private static ClientWorld observedWorld;
private static ArmorStandEntity freeCamera;
private static Map<Long, String> blockSnapshots = new HashMap<>();
private static List<Box> blockBoxes = List.of();
private static List<Box> oreBoxes = List.of();
private static List<Box> mobBoxes = List.of();
private static List<LivingEntity> nearbyLivingEntities = List.of();
private static final List<JumpCircle> jumpCircles = new ArrayList<>();
private static final Map<UUID, PearlTrail> pearlTrails = new HashMap<>();
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(VisualModulesClient::tick);
HudElementRegistry.addLast(Identifier.of(MOD_ID, "nametags"), (context, tickCounter) -> renderHud(context));
}
static void load(Properties properties) {
blockEspEnabled = readBoolean(properties, "block_esp.enabled");
blockNotifierEnabled = readBoolean(properties, "block_notifier.enabled");
freeCamEnabled = readBoolean(properties, "free_cam.enabled");
fullbrightEnabled = readBoolean(properties, "fullbright.enabled");
jumpCirclesEnabled = readBoolean(properties, "jump_circles.enabled");
mobEspEnabled = readBoolean(properties, "mob_esp.enabled");
nametagsEnabled = readBoolean(properties, "nametags.enabled");
oreEspEnabled = readBoolean(properties, "ore_esp.enabled");
pearlTrailsEnabled = readBoolean(properties, "pearl_trails.enabled");
}
static void save(Properties properties) {
properties.setProperty("block_esp.enabled", Boolean.toString(blockEspEnabled));
properties.setProperty("block_notifier.enabled", Boolean.toString(blockNotifierEnabled));
properties.setProperty("free_cam.enabled", Boolean.toString(freeCamEnabled));
properties.setProperty("fullbright.enabled", Boolean.toString(fullbrightEnabled));
properties.setProperty("jump_circles.enabled", Boolean.toString(jumpCirclesEnabled));
properties.setProperty("mob_esp.enabled", Boolean.toString(mobEspEnabled));
properties.setProperty("nametags.enabled", Boolean.toString(nametagsEnabled));
properties.setProperty("ore_esp.enabled", Boolean.toString(oreEspEnabled));
properties.setProperty("pearl_trails.enabled", Boolean.toString(pearlTrailsEnabled));
}
private static KeyBinding registerKey(String translationKey, int keyCode) {
return KeyBindingHelper.registerKeyBinding(new KeyBinding(translationKey, keyCode, CATEGORY));
}
private static boolean readBoolean(Properties properties, String key) {
return Boolean.parseBoolean(properties.getProperty(key, "false"));
}
private static void tick(MinecraftClient client) {
handleToggle(client, BLOCK_ESP_KEY, () -> blockEspEnabled, value -> blockEspEnabled = value);
handleToggle(client, BLOCK_NOTIFIER_KEY, () -> blockNotifierEnabled, value -> setBlockNotifierEnabled(value));
handleToggle(client, FREE_CAM_KEY, () -> freeCamEnabled, value -> freeCamEnabled = value);
handleToggle(client, FULLBRIGHT_KEY, () -> fullbrightEnabled, value -> fullbrightEnabled = value);
handleToggle(client, JUMP_CIRCLES_KEY, () -> jumpCirclesEnabled, value -> jumpCirclesEnabled = value);
handleToggle(client, MOB_ESP_KEY, () -> mobEspEnabled, value -> mobEspEnabled = value);
handleToggle(client, NAMETAGS_KEY, () -> nametagsEnabled, value -> nametagsEnabled = value);
handleToggle(client, ORE_ESP_KEY, () -> oreEspEnabled, value -> oreEspEnabled = value);
handleToggle(client, PEARL_TRAILS_KEY, () -> pearlTrailsEnabled, value -> pearlTrailsEnabled = value);
if (!BaseFinderClient.isLegacySuiteEnabled() || client.world == null || client.player == null) {
stopFreeCamera(client);
restoreGamma(client);
observedWorld = null;
blockBoxes = List.of();
oreBoxes = List.of();
mobBoxes = List.of();
nearbyLivingEntities = List.of();
blockSnapshots.clear();
notifierInitialized = false;
pearlTrails.clear();
jumpCircles.clear();
return;
}
if (observedWorld != client.world) {
stopFreeCamera(client);
observedWorld = client.world;
blockSnapshots.clear();
notifierInitialized = false;
pearlTrails.clear();
jumpCircles.clear();
ticksUntilBlockScan = 0;
ticksUntilNotifierScan = 0;
ticksUntilMobScan = 0;
}
clientTick++;
updateGamma(client);
updateFreeCamera(client);
updateJumpCircles(client);
if (blockEspEnabled || oreEspEnabled) {
if (ticksUntilBlockScan-- <= 0) {
scanBlocks(client.world, client.player);
ticksUntilBlockScan = BLOCK_SCAN_INTERVAL;
}
} else {
blockBoxes = List.of();
oreBoxes = List.of();
}
if (blockNotifierEnabled && ticksUntilNotifierScan-- <= 0) {
scanNearbyBlockChanges(client);
ticksUntilNotifierScan = 10;
}
if (mobEspEnabled || nametagsEnabled) {
if (ticksUntilMobScan-- <= 0) {
scanEntities(client);
ticksUntilMobScan = 5;
}
} else {
mobBoxes = List.of();
nearbyLivingEntities = List.of();
}
if (pearlTrailsEnabled) {
updatePearlTrails(client);
} else {
pearlTrails.clear();
}
}
private static void handleToggle(MinecraftClient client, KeyBinding key, BooleanSupplier getter, Consumer<Boolean> setter) {
if (key.wasPressed()) {
setter.accept(!getter.getAsBoolean());
BaseFinderConfig.save(client);
}
}
private static void updateGamma(MinecraftClient client) {
if (fullbrightEnabled) {
if (!gammaCaptured) {