Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
14 583
src/client/java/com/lordclient/client/LordClient.java
package com.lordclient.client;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Locale;
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.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.option.Perspective;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.effect.StatusEffectUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
public final class LordClient implements ClientModInitializer {
private static KeyBinding menu;
private static KeyBinding zoom;
private static KeyBinding freeLook;
private static Perspective previousPerspective;
public static float freeLookYaw;
public static float freeLookPitch;
private static final Deque<Long> leftClicks = new ArrayDeque<>();
private static final Deque<Long> rightClicks = new ArrayDeque<>();
@Override
public void onInitializeClient() {
LordConfig.load();
KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("lordclient", "main"));
menu = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.lordclient.menu", GLFW.GLFW_KEY_RIGHT_SHIFT, category));
zoom = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.lordclient.zoom", GLFW.GLFW_KEY_C, category));
freeLook = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.lordclient.freelook", GLFW.GLFW_KEY_LEFT_ALT, category));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
boolean held = freeLook.isPressed() && client.currentScreen == null && client.player != null;
if (held && previousPerspective == null) {
previousPerspective = client.options.getPerspective();
freeLookYaw = client.player.getYaw();
freeLookPitch = client.player.getPitch();
client.options.setPerspective(Perspective.THIRD_PERSON_BACK);
} else if (!held && previousPerspective != null) {
client.options.setPerspective(previousPerspective);
previousPerspective = null;
}
while (menu.wasPressed()) {
if (client.currentScreen == null) client.setScreen(new LordScreen());
}
});
HudElementRegistry.addLast(Identifier.of("lordclient", "hud"), (context, tickCounter) -> renderHud(context));
}
public static boolean zooming() {
MinecraftClient client = MinecraftClient.getInstance();
return zoom != null && zoom.isPressed() && client.currentScreen == null && client.player != null;
}
public static boolean freeLooking() {
return previousPerspective != null;
}
public static void moveFreeLook(double x, double y) {
freeLookYaw += (float) x * 0.15f;
freeLookPitch = Math.max(-90.0f, Math.min(90.0f, freeLookPitch + (float) y * 0.15f));
}
public static void click(int button) {
if (button == 0) leftClicks.addLast(System.nanoTime());
if (button == 1) rightClicks.addLast(System.nanoTime());
}
private static int count(Deque<Long> clicks) {
long cutoff = System.nanoTime() - 1_000_000_000L;
while (!clicks.isEmpty() && clicks.peekFirst() < cutoff) clicks.removeFirst();
return clicks.size();
}
private static void renderHud(DrawContext context) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null || client.options.hudHidden) return;
int y = 6;
badge(context, client, "LORDCLIENT", 7, y);
y += 18;
if (LordConfig.fps) { badge(context, client, client.getCurrentFps() + " FPS", 7, y); y += 18; }
if (LordConfig.coordinates) {
String coords = String.format(Locale.ROOT, "XYZ %.1f %.1f %.1f", client.player.getX(), client.player.getY(), client.player.getZ());
badge(context, client, coords, 7, y);
y += 18;
}
if (LordConfig.cps) { badge(context, client, count(leftClicks) + " L | " + count(rightClicks) + " R CPS", 7, y); y += 18; }
if (LordConfig.keystrokes) {
key(context, client, "W", 30, y, client.options.forwardKey.isPressed());
key(context, client, "A", 7, y + 23, client.options.leftKey.isPressed());
key(context, client, "S", 30, y + 23, client.options.backKey.isPressed());
key(context, client, "D", 53, y + 23, client.options.rightKey.isPressed());
context.fill(7, y + 46, 74, y + 58, client.options.jumpKey.isPressed() ? 0xDD287EEB : 0xBB101C30);
context.drawTextWithShadow(client.textRenderer, "SPACE", 25, y + 48, 0xFFFFFFFF);
y += 64;
}
if (LordConfig.ping && client.getNetworkHandler() != null) {
var entry = client.getNetworkHandler().getPlayerListEntry(client.player.getUuid());
if (entry != null) { badge(context, client, entry.getLatency() + " ms", 7, y); y += 18; }
}
if (LordConfig.cooldown) {
badge(context, client, "Attack " + Math.round(client.player.getAttackCooldownProgress(0.0f) * 100) + "%", 7, y);
y += 18;
}
if (LordConfig.totems) {
int total = 0;
for (ItemStack stack : client.player.getInventory().getMainStacks()) {
if (stack.isOf(Items.TOTEM_OF_UNDYING)) total += stack.getCount();
}
ItemStack offhand = client.player.getEquippedStack(EquipmentSlot.OFFHAND);
if (offhand.isOf(Items.TOTEM_OF_UNDYING)) total += offhand.getCount();
badge(context, client, "Totems " + total, 7, y);
y += 18;
}
if (LordConfig.armor) {
StringBuilder armor = new StringBuilder("Armor");
for (EquipmentSlot slot : new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}) {
ItemStack stack = client.player.getEquippedStack(slot);
armor.append(" ");
if (stack.getMaxDamage() > 0) armor.append(Math.round(100f * (stack.getMaxDamage() - stack.getDamage()) / stack.getMaxDamage())).append('%');
else armor.append('-');
}
badge(context, client, armor.toString(), 7, y);
y += 18;
}
if (LordConfig.effects) {
for (var effect : client.player.getStatusEffects()) {
String label = effect.getEffectType().value().getName().getString() + " " + (effect.getAmplifier() + 1) + " " + StatusEffectUtil.getDurationText(effect, 1.0f, 20.0f).getString();
badge(context, client, label, 7, y);
y += 18;
}
}
}
private static void badge(DrawContext context, MinecraftClient client, String text, int x, int y) {
int width = client.textRenderer.getWidth(text) + 12;
context.fill(x, y, x + width, y + 15, 0xCC101C30);
context.fill(x, y, x + 2, y + 15, 0xFF439BFF);
context.drawTextWithShadow(client.textRenderer, text, x + 6, y + 4, 0xFFF1F7FF);
}
private static void key(DrawContext context, MinecraftClient client, String label, int x, int y, boolean pressed) {
context.fill(x, y, x + 21, y + 21, pressed ? 0xDD287EEB : 0xBB101C30);
context.drawTextWithShadow(client.textRenderer, label, x + 7, y + 6, 0xFFFFFFFF);
}
}