diff options
Diffstat (limited to 'src/main/java/rosegoldaddons/features/SwordSwapping.java')
-rw-r--r-- | src/main/java/rosegoldaddons/features/SwordSwapping.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/main/java/rosegoldaddons/features/SwordSwapping.java b/src/main/java/rosegoldaddons/features/SwordSwapping.java new file mode 100644 index 0000000..099b9d7 --- /dev/null +++ b/src/main/java/rosegoldaddons/features/SwordSwapping.java @@ -0,0 +1,106 @@ +package rosegoldaddons.features; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.StringUtils; +import net.minecraft.world.World; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import rosegoldaddons.Main; + +import java.lang.reflect.Method; + +public class SwordSwapping { + public static int tickCount = 0; + private Thread thread; + + public static void rightClick() { + try { + Method rightClickMouse = null; + try { + rightClickMouse = Minecraft.class.getDeclaredMethod("rightClickMouse"); + } catch (NoSuchMethodException e) { + rightClickMouse = Minecraft.class.getDeclaredMethod("func_147121_ag"); + } + rightClickMouse.setAccessible(true); + rightClickMouse.invoke(Minecraft.getMinecraft()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static int findItemInHotbar(String name) { + InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory; + for (int i = 0; i < 9; i++) { + ItemStack curStack = inv.getStackInSlot(i); + if (curStack != null) { + if (curStack.getDisplayName().contains(name)) { + return i; + } + } + } + return -1; + } + + @SubscribeEvent + public void onTick(TickEvent.PlayerTickEvent event) { + if (Minecraft.getMinecraft().currentScreen != null) return; + if (!Main.AOTSMacro && !Main.SoulWhipMacro) { + tickCount = 0; + return; + } + if (thread == null || !thread.isAlive()) { + thread = new Thread(() -> { + try { + Thread.sleep(Main.configFile.swapFrequency); + int prevItem = Minecraft.getMinecraft().thePlayer.inventory.currentItem; + int orbSlot = findItemInHotbar("Power Orb"); + int tubaSlot = findItemInHotbar("Tuba"); + int wandSlot = findItemInHotbar("Atonement"); + int whipSlot = -1; + int aotsSlot = -1; + if(Main.AOTSMacro) { + aotsSlot = findItemInHotbar("Shredded"); + } + if(Main.SoulWhipMacro) { + whipSlot = findItemInHotbar("Whip"); + } + if(whipSlot != -1) { + Minecraft.getMinecraft().thePlayer.inventory.currentItem = whipSlot; + rightClick(); + } + if(aotsSlot != -1) { + Minecraft.getMinecraft().thePlayer.inventory.currentItem = aotsSlot; + rightClick(); + } + if(Main.configFile.UseUtility) { + if(tickCount % Math.round((1000/Main.configFile.swapFrequency*20)) == 1 && tubaSlot != -1) { + Thread.sleep(1); + Minecraft.getMinecraft().thePlayer.inventory.currentItem = tubaSlot; + rightClick(); + } + if(tickCount % Math.round((1000/Main.configFile.swapFrequency*59)) == 1 && orbSlot != -1) { + Thread.sleep(1); + Minecraft.getMinecraft().thePlayer.inventory.currentItem = orbSlot; + rightClick(); + } + if(tickCount % Math.round((1000/Main.configFile.swapFrequency*7)) == 1 && wandSlot != -1) { + Thread.sleep(1); + Minecraft.getMinecraft().thePlayer.inventory.currentItem = wandSlot; + rightClick(); + } + } + Minecraft.getMinecraft().thePlayer.inventory.currentItem = prevItem; + tickCount++; + } catch (Exception e) { + e.printStackTrace(); + } + }, "Sword Swap"); + thread.start(); + } + } +} |