Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 769
src/main/java/com/adygan/sobachka/SobachkaClient.java
package com.adygan.sobachka;
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.message.v1.ClientSendMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexRendering;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.glfw.GLFW;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
public final class SobachkaClient implements ClientModInitializer {
static boolean killAuraEnabled;
static boolean aimEnabled = true;
static boolean matrixEnabled;
static boolean autoSwapEnabled;
static boolean targetEspEnabled;
static boolean markerHammer = true;
static boolean markerCircle = true;
static boolean markerDiamond = true;
static boolean filterArmouredPlayers = true;
static boolean filterUnarmouredPlayers = true;
static boolean filterInvisibleEntities;
static boolean filterMobs = true;
enum SwapItem {
TOTEM("Totem"),
PLAYER_HEAD("Player head");
final String label;
SwapItem(String label) {
this.label = label;
}
boolean matches(ItemStack stack) {
return this == TOTEM ? stack.isOf(Items.TOTEM_OF_UNDYING) : stack.isOf(Items.PLAYER_HEAD);
}
SwapItem next() {
return this == TOTEM ? PLAYER_HEAD : TOTEM;
}
}
static final SwapItem[][] SWAP_SEQUENCE = {
{SwapItem.TOTEM, SwapItem.TOTEM},
{SwapItem.TOTEM, SwapItem.PLAYER_HEAD},
{SwapItem.PLAYER_HEAD, SwapItem.TOTEM},
{SwapItem.PLAYER_HEAD, SwapItem.PLAYER_HEAD}
};
private static final Map<String, KeyBinding> MODULE_KEYS = new LinkedHashMap<>();
private static final Map<String, String> MOUSE_BINDINGS = new LinkedHashMap<>();
private static MinecraftClient client;
private static KeyBinding guiKey;
private static int swapStep;
private static long lastSwapAt;
private static long lastAttackAt;
@Override
public void onInitializeClient() {
MODULE_KEYS.put("killaura", registerKey("killaura", -1));
MODULE_KEYS.put("autoswap", registerKey("autoswap", GLFW.GLFW_KEY_O));
MODULE_KEYS.put("targetesp", registerKey("targetesp", -1));
guiKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.sobachka_dlc.gui",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_RIGHT_SHIFT,
KeyBinding.MISC_CATEGORY
));
ClientTickEvents.END_CLIENT_TICK.register(SobachkaClient::tick);
ClientSendMessageEvents.ALLOW_CHAT.register(SobachkaClient::interceptChat);
WorldRenderEvents.AFTER_ENTITIES.register(SobachkaClient::renderTargetEsp);
}
private static KeyBinding registerKey(String function, int code) {
return KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.sobachka_dlc." + function,
InputUtil.Type.KEYSYM,
code,
KeyBinding.MISC_CATEGORY
));
}
private static void tick(MinecraftClient minecraftClient) {
client = minecraftClient;
for (Map.Entry<String, KeyBinding> entry : MODULE_KEYS.entrySet()) {
while (entry.getValue().wasPressed()) {
toggleFunction(entry.getKey());
}
}
if (guiKey.wasPressed()) {
minecraftClient.setScreen(new SobachkaScreen());
}
if (minecraftClient.player == null || minecraftClient.world == null) {
return;
}
long now = System.currentTimeMillis();
tickAutoSwap(minecraftClient, now);
tickKillAura(minecraftClient, now);
}
static void toggleFunction(String function) {
switch (function) {
case "killaura" -> killAuraEnabled = !killAuraEnabled;
case "autoswap" -> {
autoSwapEnabled = !autoSwapEnabled;
if (autoSwapEnabled) {
swapStep = 0;
lastSwapAt = System.currentTimeMillis();
}
}
case "targetesp" -> targetEspEnabled = !targetEspEnabled;
}
}
static void cycleSwapItem(int sequence, int side) {
SWAP_SEQUENCE[sequence][side] = SWAP_SEQUENCE[sequence][side].next();
}
public static boolean handleMouseWheel(double vertical) {
if (vertical == 0.0) {
return false;
}
String direction = vertical > 0.0 ? "wheelup" : "wheeldown";
boolean handled = false;
for (Map.Entry<String, String> entry : MOUSE_BINDINGS.entrySet()) {
if (entry.getValue().equals(direction)) {
toggleFunction(entry.getKey());
handled = true;
}
}
return handled;
}
private static boolean interceptChat(String message) {
String trimmed = message.trim();
if (!trimmed.equalsIgnoreCase(".bind") && !trimmed.toLowerCase(Locale.ROOT).startsWith(".bind ")) {
return true;
}
String[] parts = trimmed.split("\\s+");
if (parts.length == 4 && parts[1].equalsIgnoreCase("add")) {
String function = canonicalFunction(parts[2]);
if (function == null) {
sendFeedback("Unknown function. Use killaura, autoswap, or targetesp.");
return false;
}
assignBinding(function, parts[3]);
return false;
}
if (parts.length == 3 && parts[1].equalsIgnoreCase("remove")) {
String function = canonicalFunction(parts[2]);
if (function == null) {
sendFeedback("Unknown function. Use killaura, autoswap, or targetesp.");
return false;
}
MODULE_KEYS.get(function).setBoundKey(InputUtil.UNKNOWN_KEY);
MOUSE_BINDINGS.remove(function);
KeyBinding.updateKeysByCode();
sendFeedback("Unbound " + function + ".");
return false;
}
sendFeedback("Usage: .bind add [function] [key] or .bind remove [function]");
return false;
}
private static String canonicalFunction(String input) {
return switch (input.toLowerCase(Locale.ROOT).replace("-", "").replace("_", "")) {
case "killaura" -> "killaura";