add smart offhand

This commit is contained in:
Bella 2020-03-25 20:15:44 -04:00
parent a2ee194d0e
commit 297300f92d
No known key found for this signature in database
GPG Key ID: 815562EA23BFE344
2 changed files with 29 additions and 17 deletions

View File

@ -1,26 +1,27 @@
package me.zeroeightsix.kami.module.modules.combat;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Created by 086 on 22/01/2018.
* Updated by S-B99 on 24/02/20
* Updated by S-B99 on 25/03/20
*/
@Module.Info(name = "AutoTotem", category = Module.Category.COMBAT, description = "Refills your offhand with totems")
public class AutoTotem extends Module {
@Module.Info(name = "AutoOffhand", category = Module.Category.COMBAT, description = "Refills your offhand with totems or other items")
public class AutoOffhand extends Module {
private Setting<Mode> modeSetting = register(Settings.e("Mode", Mode.REPLACE_OFFHAND));
private Setting<Double> healthSetting = register(Settings.doubleBuilder("Max replace health").withValue(20.0).withVisibility(v -> modeSetting.getValue().equals(Mode.REPLACE_OFFHAND)));
private Setting<Boolean> smartOffhand = register(Settings.booleanBuilder("Custom Item").withValue(false).withVisibility(v -> modeSetting.getValue().equals(Mode.REPLACE_OFFHAND)));
private Setting<Double> healthSetting = register(Settings.doubleBuilder("Custom Item Health").withValue(14.0).withVisibility(v -> smartOffhand.getValue() && modeSetting.getValue().equals(Mode.REPLACE_OFFHAND)));
private Setting<CustomItem> smartItemSetting = register(Settings.enumBuilder(CustomItem.class).withName("Item").withValue(CustomItem.GAPPLE).withVisibility(v -> smartOffhand.getValue()).build());
private enum Mode {
NEITHER, REPLACE_OFFHAND, INVENTORY
}
private enum Mode { NEITHER, REPLACE_OFFHAND, INVENTORY;}
private enum CustomItem { CRYSTAL, GAPPLE }
int totems;
boolean moving = false;
@ -28,7 +29,6 @@ public class AutoTotem extends Module {
@Override
public void onUpdate() {
if (!passHealthCheck()) return;
if (!modeSetting.getValue().equals(Mode.INVENTORY) && mc.currentScreen instanceof GuiContainer)
return; // this stops autototem from running if you're in a chest or something
if (returnI) {
@ -42,10 +42,11 @@ public class AutoTotem extends Module {
mc.playerController.windowClick(0, t < 9 ? t + 36 : t, 0, ClickType.PICKUP, mc.player);
returnI = false;
}
totems = mc.player.inventory.mainInventory.stream().filter(itemStack -> itemStack.getItem() == Items.TOTEM_OF_UNDYING).mapToInt(ItemStack::getCount).sum();
if (mc.player.getHeldItemOffhand().getItem() == Items.TOTEM_OF_UNDYING) totems++;
totems = mc.player.inventory.mainInventory.stream().filter(itemStack -> itemStack.getItem() == settingToItem()).mapToInt(ItemStack::getCount).sum();
if (mc.player.getHeldItemOffhand().getItem() == settingToItem()) totems++;
else {
if (!modeSetting.getValue().equals(Mode.REPLACE_OFFHAND) && !mc.player.getHeldItemOffhand().isEmpty) return;
if (!modeSetting.getValue().equals(Mode.REPLACE_OFFHAND) && !mc.player.getHeldItemOffhand().isEmpty)
return;
if (moving) {
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
moving = false;
@ -56,7 +57,7 @@ public class AutoTotem extends Module {
if (totems == 0) return;
int t = -1;
for (int i = 0; i < 45; i++)
if (mc.player.inventory.getStackInSlot(i).getItem() == Items.TOTEM_OF_UNDYING) {
if (mc.player.inventory.getStackInSlot(i).getItem() == settingToItem()) {
t = i;
break;
}
@ -76,6 +77,17 @@ public class AutoTotem extends Module {
}
}
private Item settingToItem() {
if (!smartOffhand.getValue() || passHealthCheck()) return Items.TOTEM_OF_UNDYING;
switch (smartItemSetting.getValue()) {
case GAPPLE:
return Items.GOLDEN_APPLE;
case CRYSTAL:
return Items.END_CRYSTAL;
}
return null;
}
private boolean passHealthCheck() {
if (modeSetting.getValue().equals(Mode.REPLACE_OFFHAND)) {
return mc.player.getHealth() + mc.player.getAbsorptionAmount() <= healthSetting.getValue();

View File

@ -53,9 +53,9 @@ public class OffhandGap extends Module {
return;
}
if (mc.player.getHeldItemMainhand().getItem() instanceof ItemSword || mc.player.getHeldItemMainhand().getItem() instanceof ItemAxe || passItemCheck()) {
if (ModuleManager.isModuleEnabled("AutoTotem")) {
if (ModuleManager.isModuleEnabled("AutoOffhand")) {
autoTotemWasEnabled = true;
ModuleManager.getModuleByName("AutoTotem").disable();
ModuleManager.getModuleByName("AutoOffhand").disable();
}
if (!eatWhileAttacking.getValue()) { /* Save item for later when using preventDesync */
usedItem = mc.player.getHeldItemMainhand().getItem();
@ -135,9 +135,9 @@ public class OffhandGap extends Module {
}
private void disableGaps() {
if (autoTotemWasEnabled != ModuleManager.isModuleEnabled("AutoTotem")) {
if (autoTotemWasEnabled != ModuleManager.isModuleEnabled("AutoOffhand")) {
moveGapsToInventory(gaps);
ModuleManager.getModuleByName("AutoTotem").enable();
ModuleManager.getModuleByName("AutoOffhand").enable();
autoTotemWasEnabled = false;
}
}