2019-10-27 15:45:44 +00:00
|
|
|
package me.rigamortis.seppuku.impl.module.combat;
|
|
|
|
|
|
|
|
import me.rigamortis.seppuku.api.event.EventStageable;
|
|
|
|
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate;
|
|
|
|
import me.rigamortis.seppuku.api.module.Module;
|
2019-11-30 00:54:21 +00:00
|
|
|
import me.rigamortis.seppuku.api.value.Value;
|
2019-10-27 15:45:44 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.inventory.ClickType;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author Seth
|
|
|
|
* 4/30/2019 @ 3:37 AM.
|
|
|
|
*/
|
|
|
|
public final class AutoTotemModule extends Module {
|
|
|
|
|
2019-11-30 00:54:21 +00:00
|
|
|
public final Value<Float> health = new Value("Health", new String[]{"Hp"}, "The amount of health needed to acquire a totem.", 16.0f, 0.0f, 20.0f, 0.5f);
|
2019-10-27 15:45:44 +00:00
|
|
|
|
|
|
|
public AutoTotemModule() {
|
2020-11-25 20:00:59 +00:00
|
|
|
super("AutoTotem", new String[]{"Totem"}, "Automatically places a totem of undying in your offhand", "NONE", -1, ModuleType.COMBAT);
|
2019-10-27 15:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getMetaData() {
|
|
|
|
return "" + this.getItemCount(Items.TOTEM_OF_UNDYING);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Listener
|
|
|
|
public void onUpdate(EventPlayerUpdate event) {
|
|
|
|
if (event.getStage() == EventStageable.EventStage.PRE) {
|
|
|
|
final Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
2020-11-25 20:00:59 +00:00
|
|
|
if (mc.currentScreen == null || mc.currentScreen instanceof GuiInventory) {
|
|
|
|
if (mc.player.getHealth() <= this.health.getValue()) {
|
2019-10-27 15:45:44 +00:00
|
|
|
final ItemStack offHand = mc.player.getHeldItemOffhand();
|
|
|
|
|
|
|
|
if (offHand.getItem() == Items.TOTEM_OF_UNDYING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int slot = this.getItemSlot(Items.TOTEM_OF_UNDYING);
|
|
|
|
|
2020-11-25 20:00:59 +00:00
|
|
|
if (slot != -1) {
|
2019-10-27 15:45:44 +00:00
|
|
|
mc.playerController.windowClick(mc.player.inventoryContainer.windowId, slot, 0, ClickType.PICKUP, mc.player);
|
|
|
|
mc.playerController.windowClick(mc.player.inventoryContainer.windowId, 45, 0, ClickType.PICKUP, mc.player);
|
|
|
|
mc.playerController.windowClick(mc.player.inventoryContainer.windowId, slot, 0, ClickType.PICKUP, mc.player);
|
|
|
|
mc.playerController.updateController();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getItemSlot(Item input) {
|
2020-11-25 20:00:59 +00:00
|
|
|
for (int i = 0; i < 36; i++) {
|
2019-10-27 15:45:44 +00:00
|
|
|
final Item item = Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getItem();
|
2020-11-25 20:00:59 +00:00
|
|
|
if (item == input) {
|
2019-10-27 15:45:44 +00:00
|
|
|
if (i < 9) {
|
|
|
|
i += 36;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getItemCount(Item input) {
|
|
|
|
int items = 0;
|
|
|
|
|
2020-11-25 20:00:59 +00:00
|
|
|
for (int i = 0; i < 45; i++) {
|
2019-10-27 15:45:44 +00:00
|
|
|
final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i);
|
2020-11-25 20:00:59 +00:00
|
|
|
if (stack.getItem() == input) {
|
2019-10-27 15:45:44 +00:00
|
|
|
items += stack.getCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|