From 417ae7972b4a0c59daec5ed663fbf39e40f5d812 Mon Sep 17 00:00:00 2001 From: Kg <88619756+KgDW@users.noreply.github.com> Date: Fri, 12 Jul 2024 20:28:32 +0800 Subject: [PATCH] add originalSlot in AutoHeal (#87) --- .../module/impl/player/AutoHeal.java | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/main/java/keystrokesmod/module/impl/player/AutoHeal.java b/src/main/java/keystrokesmod/module/impl/player/AutoHeal.java index e897d610..92bde962 100644 --- a/src/main/java/keystrokesmod/module/impl/player/AutoHeal.java +++ b/src/main/java/keystrokesmod/module/impl/player/AutoHeal.java @@ -9,7 +9,6 @@ import keystrokesmod.module.setting.utils.ModeOnly; import keystrokesmod.utility.ContainerUtils; import keystrokesmod.utility.Utils; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.item.ItemSkull; import net.minecraft.item.ItemSoup; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -24,6 +23,7 @@ public class AutoHeal extends Module { private long lastHeal = -1; private long lastSwitchTo = -1; private long lastDoneUse = -1; + private int originalSlot = -1; public AutoHeal() { super("AutoHeal", category.player); this.registerSetting(new DescriptionSetting("help you win by auto use healing item.")); @@ -31,48 +31,54 @@ public AutoHeal() { this.registerSetting(autoThrow = new ButtonSetting("Auto throw", false, new ModeOnly(item, 1))); this.registerSetting(minHealth = new SliderSetting("Min health", 10, 0, 20, 1)); this.registerSetting(healDelay = new SliderSetting("Heal delay", 500, 0, 1500, 1)); - this.registerSetting(startDelay = new SliderSetting("Start delay", 30, 0, 300, 1)); + this.registerSetting(startDelay = new SliderSetting("Start delay", 0, 0, 300, 1)); } @SubscribeEvent public void onRender(TickEvent.RenderTickEvent event) { - if (!Utils.nullCheck() || mc.thePlayer.isDead) return; - if (System.currentTimeMillis() - lastHeal < healDelay.getInput()) return; + if (!Utils.nullCheck() || mc.thePlayer.isDead) return; + if (System.currentTimeMillis() - lastHeal < healDelay.getInput()) return; - if (mc.thePlayer.getHealth() <= minHealth.getInput()) { - if (lastSwitchTo == -1) { - int toSlot; - switch ((int) item.getInput()) { - default: - case 0: - toSlot = ContainerUtils.getSlot(ItemSkull.class); - break; - case 1: - toSlot = ContainerUtils.getSlot(ItemSoup.class); - break; - } + if (mc.thePlayer.getHealth() <= minHealth.getInput()) { + if (lastSwitchTo == -1) { + int toSlot; + switch ((int) item.getInput()) { + default: + case 0: + toSlot = ContainerUtils.getSlot(ItemSkull.class); + break; + case 1: + toSlot = ContainerUtils.getSlot(ItemSoup.class); + break; + } - if (toSlot == -1) return; + if (toSlot == -1) return; - SlotHandler.setCurrentSlot(toSlot); - lastSwitchTo = System.currentTimeMillis(); - } - } + originalSlot = mc.thePlayer.inventory.currentItem; + SlotHandler.setCurrentSlot(toSlot); + lastSwitchTo = System.currentTimeMillis(); + } + } - if (lastSwitchTo != -1) { - if (lastDoneUse == -1) { - if (System.currentTimeMillis() - lastSwitchTo < startDelay.getInput()) return; - mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, SlotHandler.getHeldItem()); - lastDoneUse = System.currentTimeMillis(); - } else { - if (item.getInput() == 1 && autoThrow.isToggled()) { - mc.playerController.sendPacketDropItem(SlotHandler.getHeldItem()); - } + if (lastSwitchTo != -1) { + if (lastDoneUse == -1) { + if (System.currentTimeMillis() - lastSwitchTo < startDelay.getInput()) return; + mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, SlotHandler.getHeldItem()); + lastDoneUse = System.currentTimeMillis(); + } else { + if (item.getInput() == 1 && autoThrow.isToggled()) { + mc.playerController.sendPacketDropItem(SlotHandler.getHeldItem()); + } - lastSwitchTo = -1; - lastDoneUse = -1; - lastHeal = System.currentTimeMillis(); - } - } + if (originalSlot != -1) { + SlotHandler.setCurrentSlot(originalSlot); + originalSlot = -1; + } + + lastSwitchTo = -1; + lastDoneUse = -1; + lastHeal = System.currentTimeMillis(); + } + } } -} +} \ No newline at end of file