Files
src
build.gradle
README.md
settings.gradle
Code
12 780
src/main/java/net/vaultscout/VaultScoutClient.java
package net.vaultscout;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.vaultscout.config.VaultScoutConfig;
import net.vaultscout.detect.HeavyCoreDetector;
import net.vaultscout.detect.VaultScanner;
import net.vaultscout.hud.VaultScoutHud;
/**
* VaultScout — a client-side, display-only quality-of-life mod.
*
* SAFETY / DESIGN INVARIANT:
* This mod NEVER automatically interacts with blocks, clicks, farms, or
* performs any player action. Every piece of it either:
* (a) reads world/entity/inventory state that the client already has, or
* (b) renders text / plays a local sound / shows a title.
* Nothing here sends interaction packets, moves the player, or opens
* inventories/vault UIs.
*/
public class VaultScoutClient implements ClientModInitializer {
public static final String MOD_ID = "vaultscout";
private int tickCounter = 0;
// Latest read-only scan snapshots, refreshed on a timer. Purely informational.
private VaultScanner.VaultScanResult latestVault = VaultScanner.VaultScanResult.none();
private HeavyCoreDetector.NearbyResult latestHeavyCoreNearby = HeavyCoreDetector.NearbyResult.none();
private boolean heavyCoreInInventory = false;
private boolean previousHeavyCoreInInventory = false;
@Override
public void onInitializeClient() {
VaultScoutCommands.register();
VaultScoutKeybinds.register();
ClientTickEvents.END_CLIENT_TICK.register(this::onClientTick);
HudRenderCallback.EVENT.register(this::onHudRender);
}
private void onClientTick(MinecraftClient client) {
if (client.player == null || client.world == null) {
return;
}
VaultScoutConfig cfg = VaultScoutConfig.INSTANCE;
// Cheap check every tick: does the inventory currently contain a Heavy Core?
heavyCoreInInventory = checkInventoryForHeavyCore(client);
if (heavyCoreInInventory && !previousHeavyCoreInInventory) {
onHeavyCoreObtained(client);
}
previousHeavyCoreInInventory = heavyCoreInInventory;
// Throttle the more expensive world scans (vault blocks + nearby item entities).
tickCounter++;
if (tickCounter >= cfg.scanIntervalTicks) {
tickCounter = 0;
latestVault = VaultScanner.findNearestVault(client, cfg.scanRadius);
latestHeavyCoreNearby = HeavyCoreDetector.findNearbyHeavyCore(client, cfg.scanRadius);
}
}
private boolean checkInventoryForHeavyCore(MinecraftClient client) {
var inventory = client.player.getInventory();
for (int i = 0; i < inventory.size(); i++) {
ItemStack stack = inventory.getStack(i);
if (!stack.isEmpty() && stack.isOf(Items.HEAVY_CORE)) {
return true;
}
}
return false;
}
/**
* Fired once, the moment a Heavy Core is first detected in the player's
* inventory. Purely presentational: shows a title and plays a local
* beep. Does not touch the inventory, the world, or send any packets.
*/
private void onHeavyCoreObtained(MinecraftClient client) {
VaultScoutConfig cfg = VaultScoutConfig.INSTANCE;
client.inGameHud.setTitle(Text.literal("HEAVY CORE FOUND!"));
client.inGameHud.setTitleTicks(5, 60, 15);
client.getSoundManager().play(
PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0f, cfg.volume)
);
}
private void onHudRender(DrawContext context, RenderTickCounter tickCounter) {
VaultScoutHud.render(context, latestVault, latestHeavyCoreNearby, heavyCoreInInventory);
}
}