aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/features/AutoClicker.java
blob: 0411df3c4c8fe412b76f87b5b7a680949e2df315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package rosegoldaddons.features;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;
import rosegoldaddons.Main;
import rosegoldaddons.events.MillisecondEvent;
import rosegoldaddons.utils.ChatUtils;

import java.lang.reflect.Method;

public class AutoClicker {
    private static final KeyBinding keyBinding = new KeyBinding("Auto Clicker", Keyboard.KEY_NONE, "RoseGoldAddons - Combat");
    private boolean toggled = false;
    private int count = 0;
    private long startedAt = 0;
    private long lastClickTime = 0;

    @SubscribeEvent
    public void onMillisecond(MillisecondEvent event) {
        if(!toggled) return;
        if(System.currentTimeMillis() - lastClickTime < (long) (1000 / Main.configFile.autoClickerCPS)) return;
        switch (Main.configFile.autoClickerMode) {
            case 1:
                MovingObjectPosition movingObjectPosition = Main.mc.objectMouseOver;
                if (movingObjectPosition != null && movingObjectPosition.entityHit != null) {
                    Main.mc.playerController.attackEntity(Main.mc.thePlayer, movingObjectPosition.entityHit);
                    Main.mc.thePlayer.swingItem();
                    count++;
                } else if (movingObjectPosition != null) {
                    Main.mc.thePlayer.swingItem();
                }
                break;
            case 0:
                rightClick();
                count++;
                break;
        }
        lastClickTime = System.currentTimeMillis();
    }

    @SubscribeEvent
    public void onKeyInput(InputEvent.KeyInputEvent event) {
        int eventKey = Keyboard.getEventKey();
        if(eventKey != keyBinding.getKeyCode()) return;
        if(Keyboard.isKeyDown(eventKey)) {
            if(!toggled) {
                toggled = true;
                count = 0;
                startedAt = System.currentTimeMillis();
            }
        } else {
            toggled = false;
            ChatUtils.sendMessage(String.format("%s Clicks in %s milliseconds", count, System.currentTimeMillis() - startedAt));
        }
    }

    public static void init() {
        ClientRegistry.registerKeyBinding(keyBinding);
    }

    public static void rightClick() {
        try {
            Method rightClickMouse;
            try {
                rightClickMouse = Minecraft.class.getDeclaredMethod("func_147121_ag");
            } catch (NoSuchMethodException e) {
                rightClickMouse = Minecraft.class.getDeclaredMethod("rightClickMouse");
            }
            rightClickMouse.setAccessible(true);
            rightClickMouse.invoke(Main.mc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}