forked from RepoMirrors/kami-blue
fix offhandgap and actually test it this time
This commit is contained in:
parent
a8b7e93a33
commit
e054509ef2
|
@ -2,7 +2,6 @@ package me.zeroeightsix.kami.module.modules.combat;
|
||||||
|
|
||||||
import me.zero.alpine.listener.EventHandler;
|
import me.zero.alpine.listener.EventHandler;
|
||||||
import me.zero.alpine.listener.Listener;
|
import me.zero.alpine.listener.Listener;
|
||||||
import me.zeroeightsix.kami.command.Command;
|
|
||||||
import me.zeroeightsix.kami.event.events.PacketEvent;
|
import me.zeroeightsix.kami.event.events.PacketEvent;
|
||||||
import me.zeroeightsix.kami.module.Module;
|
import me.zeroeightsix.kami.module.Module;
|
||||||
import me.zeroeightsix.kami.module.ModuleManager;
|
import me.zeroeightsix.kami.module.ModuleManager;
|
||||||
|
@ -13,47 +12,42 @@ import net.minecraft.inventory.ClickType;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.*;
|
||||||
import net.minecraft.network.play.client.CPacketPlayerTryUseItem;
|
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 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
|
* 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!")
|
@Module.Info(name = "OffhandGap", category = Module.Category.COMBAT, description = "Holds a God apple when right clicking your sword!")
|
||||||
public class OffhandGap extends Module {
|
public class OffhandGap extends Module {
|
||||||
private Setting<Double> disableHealth = register(Settings.doubleBuilder("Disable Health").withMinimum(0.0).withValue(4.0).withMaximum(20.0).build());
|
private Setting<Double> disableHealth = register(Settings.doubleBuilder("Disable Health").withMinimum(0.0).withValue(4.0).withMaximum(20.0).build());
|
||||||
private Setting<Boolean> weaponCheck = register(Settings.b("Sword or Axe Only", true));
|
private Setting<Boolean> weaponCheck = register(Settings.b("Sword or Axe Only", true));
|
||||||
private Setting<Boolean> preventDesync = register(Settings.b("Prevent Desync", false));
|
private Setting<Boolean> eatWhileAttacking = register(Settings.b("Eat While Attacking", false));
|
||||||
// private Setting<Mode> modeSetting = register(Settings.e("Use Mode", Mode.GAPPLE));
|
// private Setting<Mode> 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 {
|
// private enum Mode {
|
||||||
// GAPPLE, FOOD, CUSTOM
|
// GAPPLE, FOOD, CUSTOM
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
int gaps = -1;
|
||||||
|
boolean autoTotemWasEnabled = false;
|
||||||
|
boolean notCancelled = false;
|
||||||
|
Item usedItem;
|
||||||
|
Item toUseItem;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private Listener<PacketEvent.Send> sendListener = new Listener<>(e ->{
|
private Listener<PacketEvent.Send> sendListener = new Listener<>(e ->{
|
||||||
if (e.getPacket() instanceof CPacketPlayerTryUseItem) {
|
if (e.getPacket() instanceof CPacketPlayerTryUseItem) {
|
||||||
if (cancelled) { /* Disable running code if your health doesn't meet requirements */
|
if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) {
|
||||||
forceTotems();
|
disableGaps();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mc.player.getHeldItemMainhand().getItem() instanceof ItemSword || mc.player.getHeldItemMainhand().getItem() instanceof ItemAxe || passItemCheck()) {
|
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 */
|
if (ModuleManager.isModuleEnabled("AutoTotem")) {
|
||||||
autoTotemLocalState = true;
|
autoTotemWasEnabled = true;
|
||||||
ModuleManager.getModuleByName("AutoTotem").disable();
|
ModuleManager.getModuleByName("AutoTotem").disable();
|
||||||
}
|
}
|
||||||
if (preventDesync.getValue()) { /* Save item for later when using preventDesync */
|
if (!eatWhileAttacking.getValue()) { /* Save item for later when using preventDesync */
|
||||||
usedItem = mc.player.getHeldItemMainhand().getItem();
|
usedItem = mc.player.getHeldItemMainhand().getItem();
|
||||||
}
|
}
|
||||||
enableGaps(gaps);
|
enableGaps(gaps);
|
||||||
|
@ -63,31 +57,26 @@ public class OffhandGap extends Module {
|
||||||
/* If you stop holding right click move totem back */
|
/* If you stop holding right click move totem back */
|
||||||
if (!mc.gameSettings.keyBindUseItem.isKeyDown() && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) disableGaps();
|
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 */
|
/* In case you didn't stop right clicking but you switched items by scrolling or something */
|
||||||
/* Only with preventDesync enabled */
|
else if ((usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
||||||
else if (preventDesync.getValue() && (usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
if (!eatWhileAttacking.getValue()) {
|
||||||
usedItem = mc.player.getHeldItemMainhand().getItem();
|
usedItem = mc.player.getHeldItemMainhand().getItem();
|
||||||
disableGaps();
|
disableGaps();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Force disable if under health limit */
|
/* Force disable if under health limit */
|
||||||
else if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) disableGaps();
|
else if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) {
|
||||||
} catch (NullPointerException ignored) { } // epic meme
|
disableGaps();
|
||||||
forceTotems(); /* After doing the safe cancel, make sure totems are in the offhand */
|
}
|
||||||
|
} catch (NullPointerException ignored) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
if (mc.player == null) return;
|
if (mc.player == null) return;
|
||||||
/* If your health doesn't meet the cutoff then set it to true */
|
/* If your health doesn't meet the cutoff then set it to true */
|
||||||
cancelled = mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue();
|
notCancelled = mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue();
|
||||||
// if (modeSetting.getValue().equals(Mode.GAPPLE)) {
|
|
||||||
toUseItem = Items.GOLDEN_APPLE;
|
toUseItem = Items.GOLDEN_APPLE;
|
||||||
// } else if (modeSetting.getValue().equals(Mode.FOOD)) {
|
|
||||||
// if (getFullInventory().containsKey(Items.))
|
|
||||||
// }
|
|
||||||
// Map<Integer, ItemStack> fullInventory = getFullInventory();
|
|
||||||
// System.out.println(fullInventory);
|
|
||||||
|
|
||||||
/* Find Golden Apples in your inventory */
|
|
||||||
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
|
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
|
||||||
for (int i = 0; i < 45; i++) {
|
for (int i = 0; i < 45; i++) {
|
||||||
if (mc.player.inventory.getStackInSlot(i).getItem() == Items.GOLDEN_APPLE) {
|
if (mc.player.inventory.getStackInSlot(i).getItem() == Items.GOLDEN_APPLE) {
|
||||||
|
@ -100,8 +89,6 @@ public class OffhandGap extends Module {
|
||||||
|
|
||||||
// private static Map<Integer, ItemStack> getFullInventory() { return getInventorySlots(0, 45); }
|
// private static Map<Integer, ItemStack> 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 */
|
/* If weaponCheck is disabled, check if they're not holding an item you'd want to use normally */
|
||||||
private boolean passItemCheck() {
|
private boolean passItemCheck() {
|
||||||
if (weaponCheck.getValue()) return false;
|
if (weaponCheck.getValue()) return false;
|
||||||
|
@ -122,23 +109,14 @@ public class OffhandGap extends Module {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceTotems() {
|
|
||||||
if (!ModuleManager.isModuleEnabled("AutoTotem")) {
|
|
||||||
moveGapsToInventory(gaps);
|
|
||||||
ModuleManager.getModuleByName("AutoTotem").enable();
|
|
||||||
autoTotemLocalState = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disableGaps() {
|
private void disableGaps() {
|
||||||
if (autoTotemLocalState != ModuleManager.isModuleEnabled("AutoTotem")) {
|
if (autoTotemWasEnabled != ModuleManager.isModuleEnabled("AutoTotem")) {
|
||||||
moveGapsToInventory(gaps);
|
moveGapsToInventory(gaps);
|
||||||
ModuleManager.getModuleByName("AutoTotem").enable();
|
ModuleManager.getModuleByName("AutoTotem").enable();
|
||||||
autoTotemLocalState = false;
|
autoTotemWasEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void enableGaps(int slot) {
|
private void enableGaps(int slot) {
|
||||||
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
|
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
|
||||||
mc.playerController.windowClick(0, slot < 9 ? slot + 36 : slot, 0, ClickType.PICKUP, mc.player);
|
mc.playerController.windowClick(0, slot < 9 ? slot + 36 : slot, 0, ClickType.PICKUP, mc.player);
|
||||||
|
|
Loading…
Reference in New Issue