From e054509ef2c6f00d028a2f54f52dfb0d689edeb7 Mon Sep 17 00:00:00 2001 From: Bella Date: Thu, 5 Mar 2020 21:19:22 -0500 Subject: [PATCH] fix offhandgap and actually test it this time --- .../module/modules/combat/OffhandGap.java | 100 +++++++----------- 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/OffhandGap.java b/src/main/java/me/zeroeightsix/kami/module/modules/combat/OffhandGap.java index 19650816..d5524a13 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/OffhandGap.java +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/OffhandGap.java @@ -2,7 +2,6 @@ package me.zeroeightsix.kami.module.modules.combat; import me.zero.alpine.listener.EventHandler; import me.zero.alpine.listener.Listener; -import me.zeroeightsix.kami.command.Command; import me.zeroeightsix.kami.event.events.PacketEvent; import me.zeroeightsix.kami.module.Module; import me.zeroeightsix.kami.module.ModuleManager; @@ -13,81 +12,71 @@ import net.minecraft.inventory.ClickType; import net.minecraft.item.*; import net.minecraft.network.play.client.CPacketPlayerTryUseItem; -import java.util.Map; - -import static me.zeroeightsix.kami.module.modules.combat.AutoReplenish.getInventorySlots; - /** * @author polymer (main listener switch function xd) - * @author S-B99 (made epic and smooth and cleaned up code <3) + * @author S-B99 (made epic and smooth and cleaned up code <3) (why did i rewrite this 4 times) * Created by polymer on 21/02/20 - * Updated by S-B99 on 24/02/20 + * Updated by S-B99 on 05/03/20 */ @Module.Info(name = "OffhandGap", category = Module.Category.COMBAT, description = "Holds a God apple when right clicking your sword!") public class OffhandGap extends Module { private Setting disableHealth = register(Settings.doubleBuilder("Disable Health").withMinimum(0.0).withValue(4.0).withMaximum(20.0).build()); private Setting weaponCheck = register(Settings.b("Sword or Axe Only", true)); - private Setting preventDesync = register(Settings.b("Prevent Desync", false)); + private Setting eatWhileAttacking = register(Settings.b("Eat While Attacking", false)); // private Setting modeSetting = register(Settings.e("Use Mode", Mode.GAPPLE)); - public static boolean autoTotemGlobalState = false; - boolean autoTotemLocalState = false; - boolean cancelled = false; - Item usedItem; - Item toUseItem; - int gaps = -1; - // private enum Mode { // GAPPLE, FOOD, CUSTOM // } + int gaps = -1; + boolean autoTotemWasEnabled = false; + boolean notCancelled = false; + Item usedItem; + Item toUseItem; + @EventHandler private Listener sendListener = new Listener<>(e ->{ - if (e.getPacket() instanceof CPacketPlayerTryUseItem) { - if (cancelled) { /* Disable running code if your health doesn't meet requirements */ - forceTotems(); - return; - } - if (mc.player.getHeldItemMainhand().getItem() instanceof ItemSword || mc.player.getHeldItemMainhand().getItem() instanceof ItemAxe || passItemCheck()) { - if (ModuleManager.isModuleEnabled("AutoTotem")) { /* Save used state of AutoTotem to use later */ - autoTotemLocalState = true; - ModuleManager.getModuleByName("AutoTotem").disable(); - } - if (preventDesync.getValue()) { /* Save item for later when using preventDesync */ - usedItem = mc.player.getHeldItemMainhand().getItem(); - } - enableGaps(gaps); - } + if (e.getPacket() instanceof CPacketPlayerTryUseItem) { + if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) { + disableGaps(); + return; } - try { - /* If you stop holding right click move totem back */ - if (!mc.gameSettings.keyBindUseItem.isKeyDown() && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) disableGaps(); + if (mc.player.getHeldItemMainhand().getItem() instanceof ItemSword || mc.player.getHeldItemMainhand().getItem() instanceof ItemAxe || passItemCheck()) { + if (ModuleManager.isModuleEnabled("AutoTotem")) { + autoTotemWasEnabled = true; + ModuleManager.getModuleByName("AutoTotem").disable(); + } + if (!eatWhileAttacking.getValue()) { /* Save item for later when using preventDesync */ + usedItem = mc.player.getHeldItemMainhand().getItem(); + } + enableGaps(gaps); + } + } + try { + /* If you stop holding right click move totem back */ + if (!mc.gameSettings.keyBindUseItem.isKeyDown() && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) disableGaps(); /* In case you didn't stop right clicking but you switched items by scrolling or something */ - /* Only with preventDesync enabled */ - else if (preventDesync.getValue() && (usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) { + else if ((usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) { + if (!eatWhileAttacking.getValue()) { usedItem = mc.player.getHeldItemMainhand().getItem(); disableGaps(); } - /* Force disable if under health limit */ - else if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) disableGaps(); - } catch (NullPointerException ignored) { } // epic meme - forceTotems(); /* After doing the safe cancel, make sure totems are in the offhand */ + } + /* Force disable if under health limit */ + else if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) { + disableGaps(); + } + } catch (NullPointerException ignored) { } }); @Override public void onUpdate() { if (mc.player == null) return; /* If your health doesn't meet the cutoff then set it to true */ - cancelled = mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue(); - // if (modeSetting.getValue().equals(Mode.GAPPLE)) { - toUseItem = Items.GOLDEN_APPLE; -// } else if (modeSetting.getValue().equals(Mode.FOOD)) { -// if (getFullInventory().containsKey(Items.)) -// } -// Map fullInventory = getFullInventory(); -// System.out.println(fullInventory); + notCancelled = mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue(); + toUseItem = Items.GOLDEN_APPLE; - /* Find Golden Apples in your inventory */ if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) { for (int i = 0; i < 45; i++) { if (mc.player.inventory.getStackInSlot(i).getItem() == Items.GOLDEN_APPLE) { @@ -100,8 +89,6 @@ public class OffhandGap extends Module { // private static Map getFullInventory() { return getInventorySlots(0, 45); } -// public void setAutoTotemGlobalStateChange(boolean newValue) { autoTotemGlobalState = newValue; } - /* If weaponCheck is disabled, check if they're not holding an item you'd want to use normally */ private boolean passItemCheck() { if (weaponCheck.getValue()) return false; @@ -122,23 +109,14 @@ public class OffhandGap extends Module { return true; } - private void forceTotems() { - if (!ModuleManager.isModuleEnabled("AutoTotem")) { - moveGapsToInventory(gaps); - ModuleManager.getModuleByName("AutoTotem").enable(); - autoTotemLocalState = false; - } - } - private void disableGaps() { - if (autoTotemLocalState != ModuleManager.isModuleEnabled("AutoTotem")) { + if (autoTotemWasEnabled != ModuleManager.isModuleEnabled("AutoTotem")) { moveGapsToInventory(gaps); ModuleManager.getModuleByName("AutoTotem").enable(); - autoTotemLocalState = false; + autoTotemWasEnabled = false; } } - private void enableGaps(int slot) { if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) { mc.playerController.windowClick(0, slot < 9 ? slot + 36 : slot, 0, ClickType.PICKUP, mc.player);