forked from RepoMirrors/kami-blue
code cleanup and prepare autototem support
This commit is contained in:
parent
9ee5f19b3a
commit
1fff7ba1c4
|
@ -77,4 +77,8 @@ public class AutoTotem extends Module {
|
||||||
public String getHudInfo() {
|
public String getHudInfo() {
|
||||||
return String.valueOf(totems);
|
return String.valueOf(totems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEnable() { OffhandGap.autoTotemGlobalState = false; }
|
||||||
|
public void onDisable() { OffhandGap.autoTotemGlobalState = true; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,28 +30,26 @@ public class OffhandGap extends Module {
|
||||||
private Setting<Boolean> preventDesync = register(Settings.b("Prevent Desync", false));
|
private Setting<Boolean> preventDesync = register(Settings.b("Prevent Desync", false));
|
||||||
// private Setting<Mode> modeSetting = register(Settings.e("Use Mode", Mode.GAPPLE));
|
// private Setting<Mode> modeSetting = register(Settings.e("Use Mode", Mode.GAPPLE));
|
||||||
|
|
||||||
private enum Mode {
|
public static boolean autoTotemGlobalState = false;
|
||||||
GAPPLE, FOOD, CUSTOM
|
boolean autoTotemLocalState = false;
|
||||||
}
|
|
||||||
|
|
||||||
int gaps = -1;
|
|
||||||
boolean autoTotemWasEnabled = false;
|
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
boolean autoTotemUserEnabled = false;
|
|
||||||
boolean changingState = false;
|
|
||||||
Item usedItem;
|
Item usedItem;
|
||||||
Item toUseItem;
|
Item toUseItem;
|
||||||
|
int gaps = -1;
|
||||||
|
|
||||||
|
// private enum Mode {
|
||||||
|
// GAPPLE, FOOD, CUSTOM
|
||||||
|
// }
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private Listener<PacketEvent.Send> sendListener = new Listener<>(e ->{
|
private Listener<PacketEvent.Send> sendListener = new Listener<>(e ->{
|
||||||
while (!cancelled) {
|
while (!cancelled) { /* Super safe cancel everything method */
|
||||||
if (e.getPacket() instanceof CPacketPlayerTryUseItem) {
|
if (e.getPacket() instanceof CPacketPlayerTryUseItem) {
|
||||||
if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) {
|
/* Disable running code if your health doesn't meet requirements */
|
||||||
return;
|
if (cancelled) 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")) {
|
if (ModuleManager.isModuleEnabled("AutoTotem")) { /* Save used state of AutoTotem to use later */
|
||||||
autoTotemWasEnabled = true;
|
autoTotemLocalState = true;
|
||||||
ModuleManager.getModuleByName("AutoTotem").disable();
|
ModuleManager.getModuleByName("AutoTotem").disable();
|
||||||
}
|
}
|
||||||
if (preventDesync.getValue()) { /* Save item for later when using preventDesync */
|
if (preventDesync.getValue()) { /* Save item for later when using preventDesync */
|
||||||
|
@ -62,29 +60,28 @@ public class OffhandGap extends Module {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
/* 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) {
|
if (!mc.gameSettings.keyBindUseItem.isKeyDown() && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) disableGaps();
|
||||||
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 */
|
||||||
else if ((usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
|
||||||
/* Only with preventDesync enabled */
|
/* Only with preventDesync enabled */
|
||||||
if (preventDesync.getValue()) {
|
else if (preventDesync.getValue() && (usedItem != mc.player.getHeldItemMainhand().getItem()) && mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
||||||
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()) {
|
else if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue()) disableGaps();
|
||||||
disableGaps();
|
} catch (NullPointerException ignored) { } // epic meme
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) { }
|
|
||||||
}
|
}
|
||||||
|
forceTotems(); /* After doing the safe cancel, make sure totems are in the offhand */
|
||||||
});
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
if (mc.player == null) return;
|
if (mc.player == null) return;
|
||||||
|
// if (autoTotemGlobalState) {
|
||||||
|
// Command.sendChatMessage("uwu");
|
||||||
|
// } else {
|
||||||
|
// Command.sendChatMessage("owo");
|
||||||
|
// }
|
||||||
/* 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();
|
cancelled = mc.player.getHealth() + mc.player.getAbsorptionAmount() <= disableHealth.getValue();
|
||||||
// if (modeSetting.getValue().equals(Mode.GAPPLE)) {
|
// if (modeSetting.getValue().equals(Mode.GAPPLE)) {
|
||||||
|
@ -95,6 +92,7 @@ public class OffhandGap extends Module {
|
||||||
// Map<Integer, ItemStack> fullInventory = getFullInventory();
|
// Map<Integer, ItemStack> fullInventory = getFullInventory();
|
||||||
// System.out.println(fullInventory);
|
// 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) {
|
||||||
|
@ -105,7 +103,9 @@ 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() {
|
||||||
|
@ -127,16 +127,23 @@ public class OffhandGap extends Module {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableGaps() {
|
private void forceTotems() {
|
||||||
changingState = true;
|
if (!ModuleManager.isModuleEnabled("AutoTotem")) {
|
||||||
if (autoTotemWasEnabled != ModuleManager.isModuleEnabled("AutoTotem")) {
|
moveGapsToInventory(gaps);
|
||||||
moveGapsFromOffhand(gaps);
|
|
||||||
ModuleManager.getModuleByName("AutoTotem").enable();
|
ModuleManager.getModuleByName("AutoTotem").enable();
|
||||||
autoTotemWasEnabled = false;
|
autoTotemLocalState = false;
|
||||||
}
|
}
|
||||||
changingState = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableGaps() {
|
||||||
|
if (autoTotemLocalState != ModuleManager.isModuleEnabled("AutoTotem")) {
|
||||||
|
moveGapsToInventory(gaps);
|
||||||
|
ModuleManager.getModuleByName("AutoTotem").enable();
|
||||||
|
autoTotemLocalState = 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);
|
||||||
|
@ -144,7 +151,7 @@ public class OffhandGap extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveGapsFromOffhand(int slot) {
|
private void moveGapsToInventory(int slot) {
|
||||||
if (mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
if (mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE) {
|
||||||
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
|
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
|
||||||
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