package com.example.client.module;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import org.lwjgl.glfw.GLFW;
public class AutoGappleModule {
private static final MinecraftClient mc = MinecraftClient.getInstance();
private boolean enabled = false;
private float healthThreshold = 10.0f;
private int tickDelay = 20; )
private int tickCounter = 0;
private int previousSlot = -1;
public void toggle() {
enabled = !enabled;
System.out.println("AutoGapple " + (enabled ? "enabled" : "disabled"));
}
public void setHealthThreshold(float threshold) {
this.healthThreshold = Math.max(1.0f, Math.min(20.0f, threshold));
}
public void setTickDelay(int delay) {
this.tickDelay = Math.max(0, delay);
}
public void onTick() {
if (!enabled || mc.player == null || mc.world == null) return;
tickCounter++;
if (tickCounter < tickDelay) return;
tickCounter = 0;
ClientPlayerEntity player = mc.player;
if (player.getHealth() <= healthThreshold) {
int appleSlot = findGoldenApple();
if (appleSlot != -1) {
useGoldenApple(appleSlot);
}
}
}
private int findGoldenApple() {
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.getInventory().getStack(i);
if (stack.getItem() == Items.GOLDEN_APPLE || stack.getItem() == Items.ENCHANTED_GOLDEN_APPLE) {
return i;
}
}
return -1; // Яблоко не найдено
}
private void useGoldenApple(int slot) {
if (mc.player == null) return;
previousSlot = mc.player.getInventory().selectedSlot;
mc.player.getInventory().selectedSlot = slot;
mc.options.useKey.setPressed(true);
mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND);
mc.options.useKey.setPressed(false);
if (previousSlot != -1) {
mc.player.getInventory().selectedSlot = previousSlot;
}
}
public boolean isEnabled() {
return enabled;
}
public float getHealthThreshold() {
return healthThreshold;
}
public int getTickDelay() {
return tickDelay;
}
}
<