Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
16 1,295
src/main/java/com/kingvisual/KingVisualClient.java
package com.kingvisual;
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.HudRenderCallback;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.ActionResult;
import org.lwjgl.glfw.GLFW;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class KingVisualClient implements ClientModInitializer {
public static KingConfig CONFIG;
private static KeyBinding menuKey, zoomKey;
public static float zoomSmooth = 1f;
private static final List<Long> CLICKS = new ArrayList<>();
private static boolean prevAttack;
private static float shownHp;
private static UUID shownId;
public static int kills = 0, streak = 0, combo = 0;
public static int hitMarkerTicks = 0, bannerTicks = 0;
public static String bannerText = "";
private long lastComboTick;
private final Set<UUID> handledDead = new HashSet<>();
private LivingEntity lastTarget;
private long lastHitTick;
@Override
public void onInitializeClient() {
CONFIG = KingConfig.load();
menuKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.kingvisual.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_RIGHT_SHIFT, KeyBinding.Category.MISC));
zoomKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.kingvisual.zoom", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, KeyBinding.Category.MISC));
AttackEntityCallback.EVENT.register((player, world, hand, entity, hit) -> {
if (world.isClient() && entity instanceof LivingEntity le) {
lastTarget = le;
lastHitTick = world.getTime();
combo = (world.getTime() - lastComboTick <= 60) ? combo + 1 : 1;
lastComboTick = world.getTime();
if (CONFIG.hitMarker) hitMarkerTicks = 6;
if (CONFIG.hitParticles) {
boolean crit = player.fallDistance > 0.0f && !player.isOnGround() && !player.isClimbing();
KingEffects.hit(le, crit);
}
}
return ActionResult.PASS;
});
ClientTickEvents.END_CLIENT_TICK.register(mc -> {
while (menuKey.wasPressed()) mc.setScreen(new KingConfigScreen(mc.currentScreen));
KingEffects.tick(mc);
boolean zooming = CONFIG.zoom && mc.currentScreen == null && zoomKey.isPressed();
zoomSmooth += ((zooming ? CONFIG.zoomFactor : 1f) - zoomSmooth) * 0.3f;
if (Math.abs(zoomSmooth - 1f) < 0.01f && !zooming) zoomSmooth = 1f;
boolean atk = mc.options.attackKey.isPressed();
if (atk && !prevAttack) CLICKS.add(System.currentTimeMillis());
prevAttack = atk;
long nowMs = System.currentTimeMillis();
CLICKS.removeIf(t -> nowMs - t > 1000);
if (mc.world == null || mc.player == null) { handledDead.clear(); return; }
if (mc.world.getTime() - lastComboTick > 60) combo = 0;
if (mc.player.getHealth() <= 0f) streak = 0;
if (hitMarkerTicks > 0) hitMarkerTicks--;
if (bannerTicks > 0) bannerTicks--;
for (Entity e : mc.world.getEntities()) {
if (!(e instanceof LivingEntity le) || le == mc.player) continue;
if (le.getHealth() > 0f) continue;
if (!handledDead.add(le.getUuid())) continue;
if (CONFIG.deathEffect) KingEffects.death(le);
boolean mine = le == lastTarget && mc.world.getTime() - lastHitTick <= 60;
if (mine) {
kills++; streak++;
bannerText = "SLEW " + le.getName().getString().toUpperCase();
if (CONFIG.killBanner) bannerTicks = 50;
if (CONFIG.killEffect) KingEffects.kill(le);
}
}
if (handledDead.size() > 512) handledDead.clear();
});
HudRenderCallback.EVENT.register((ctx, tickCounter) -> {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc.player == null) return;
if (CONFIG.screenPulse && KingEffects.pulseTicks > 0) {
float t = KingEffects.pulseTicks / (float) KingEffects.PULSE_MAX;
int alpha = Math.min((int) (70 * t * CONFIG.intensity), 140);
ctx.fill(0, 0, ctx.getScaledWindowWidth(), ctx.getScaledWindowHeight(), (alpha << 24) | CONFIG.color());
}
drawExtras(ctx, mc);
drawPerks(ctx, mc);
drawHud(ctx, mc);
});
}
private static void drawHud(DrawContext ctx, MinecraftClient mc) {
if (!CONFIG.hudWatermark && !CONFIG.hudStats && !CONFIG.hudInfo) return;
int accent = 0xFF000000 | CONFIG.color();
int x = 6, y = 6;
String title = "\u2654 KING VISUAL";
int w = mc.textRenderer.getWidth(title) + 14;
if (CONFIG.hudWatermark) {
ctx.fillGradient(x, y, x + w, y + 16, 0xB0101018, 0x90101018);
ctx.fill(x, y, x + 2, y + 16, accent);
ctx.drawTextWithShadow(mc.textRenderer, title, x + 8, y + 4, accent);
y += 18;
}
if (CONFIG.hudStats) {
String s = "Kills " + kills + " Streak " + streak + " Combo x" + combo;
int sw = mc.textRenderer.getWidth(s) + 14;
ctx.fillGradient(x, y, x + sw, y + 14, 0xA0101018, 0x80101018);
ctx.fill(x, y, x + 2, y + 14, accent);
ctx.drawTextWithShadow(mc.textRenderer, s, x + 8, y + 3, 0xFFFFFFFF);
y += 16;
}
if (CONFIG.hudInfo) {
String s = "FPS " + mc.getCurrentFps() + " XYZ " + (int) mc.player.getX() + " " + (int) mc.player.getY() + " " + (int) mc.player.getZ();
int sw = mc.textRenderer.getWidth(s) + 14;
ctx.fillGradient(x, y, x + sw, y + 14, 0xA0101018, 0x80101018);
ctx.fill(x, y, x + 2, y + 14, accent);
ctx.drawTextWithShadow(mc.textRenderer, s, x + 8, y + 3, 0xFFCCCCDD);
}
}
/** Hit marker, kill banner and low-health vignette. */
private static void drawExtras(DrawContext ctx, MinecraftClient mc) {
int w = ctx.getScaledWindowWidth(), h = ctx.getScaledWindowHeight();
int cx = w / 2, cy = h / 2;
int rgb = CONFIG.color();
if (hitMarkerTicks > 0) {
int a = 0xFF000000 | 0xFFFFFF;
for (int i = 4; i <= 9; i += 2) {
ctx.fill(cx - i - 1, cy - i - 1, cx - i + 1, cy - i + 1, a);
ctx.fill(cx + i - 1, cy - i - 1, cx + i + 1, cy - i + 1, a);
ctx.fill(cx - i - 1, cy + i - 1, cx - i + 1, cy + i + 1, a);
ctx.fill(cx + i - 1, cy + i - 1, cx + i + 1, cy + i + 1, a);
}
}
if (bannerTicks > 0) {
float t = bannerTicks / 50f;
int alpha = Math.max(5, (int) (255 * Math.min(1f, t * 3f)));
int by = h / 4;
int tw = mc.textRenderer.getWidth(bannerText);
ctx.fillGradient(cx - tw / 2 - 30, by - 6, cx + tw / 2 + 30, by + 16, (Math.max(5, alpha / 3) << 24) | 0x000000, (Math.max(5, alpha / 6) << 24));
ctx.fill(cx - tw / 2 - 30, by + 16, cx + tw / 2 + 30, by + 17, (alpha << 24) | rgb);
ctx.drawCenteredTextWithShadow(mc.textRenderer, "\u2654 " + bannerText + " \u2654", cx, by + 3, (alpha << 24) | rgb);
}
if (CONFIG.lowHealthVignette && mc.player.getHealth() <= 6f && mc.player.getHealth() > 0f) {
float pulse = 0.5f + 0.5f * (float) Math.sin(System.currentTimeMillis() / 250.0);
int a = (int) (40 + 60 * pulse);
int c = (a << 24) | 0xFF0000;
ctx.fillGradient(0, 0, w, h / 4, c, 0x00FF0000);
ctx.fillGradient(0, h * 3 / 4, w, h, 0x00FF0000, c);
}
}
/** Keystrokes + CPS and armor HUD. */
private static void drawPerks(DrawContext ctx, MinecraftClient mc) {
int w = ctx.getScaledWindowWidth(), h = ctx.getScaledWindowHeight();
int rgb = CONFIG.color();
int on = 0xB0000000 | rgb, off = 0x90101018;
if (CONFIG.targetHud && mc.targetedEntity instanceof LivingEntity tg && tg.isAlive()) {
if (!tg.getUuid().equals(shownId)) { shownId = tg.getUuid(); shownHp = tg.getHealth(); }
shownHp += (tg.getHealth() - shownHp) * 0.15f;
float ratio = Math.max(0f, Math.min(1f, shownHp / Math.max(1f, tg.getMaxHealth())));
int bx = w / 2 - 60, by = h / 2 + 26;
ctx.fillGradient(bx, by, bx + 120, by + 24, 0xB0101018, 0x90101018);
ctx.fill(bx, by, bx + 2, by + 24, 0xFF000000 | rgb);
ctx.drawTextWithShadow(mc.textRenderer, tg.getName().getString(), bx + 8, by + 3, 0xFFFFFFFF);
ctx.fill(bx + 8, by + 15, bx + 112, by + 19, 0xFF2A2A38);
int hc = ratio > 0.5f ? 0xFF39FF88 : ratio > 0.25f ? 0xFFFFD700 : 0xFFDC143C;
ctx.fill(bx + 8, by + 15, bx + 8 + (int) (104 * ratio), by + 19, hc);
}
if (CONFIG.keystrokes) {
int x = 6, y = h - 74;
key(ctx, mc, x + 20, y, 18, 18, "W", mc.options.forwardKey.isPressed(), on, off);
key(ctx, mc, x, y + 20, 18, 18, "A", mc.options.leftKey.isPressed(), on, off);