blob: 41ba9a7ad67e2067d93ce5e4442653c6ce0b7a3f (
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
81
82
83
84
85
|
package rosegoldaddons.features;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import rosegoldaddons.Main;
import rosegoldaddons.commands.UseCooldown;
import java.lang.reflect.Method;
public class CustomItemMacro {
private Thread thread;
private int milis = 0;
@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
if (!Main.autoUseItems) return;
if (thread == null || !thread.isAlive()) {
thread = new Thread(() -> {
try {
int prevItem = Minecraft.getMinecraft().thePlayer.inventory.currentItem;
for (String i : UseCooldown.RCitems.keySet()) {
if (milis % Math.floor(UseCooldown.RCitems.get(i)/100) == 0) {
int slot = findItemInHotbar(i);
if (slot != -1) {
Minecraft.getMinecraft().thePlayer.inventory.currentItem = slot;
Minecraft.getMinecraft().playerController.sendUseItem(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(slot));
}
}
}
for (String i : UseCooldown.LCitems.keySet()) {
if (milis % Math.floor(UseCooldown.LCitems.get(i)/100) == 0) {
int slot = findItemInHotbar(i);
if (slot != -1) {
Minecraft.getMinecraft().thePlayer.inventory.currentItem = slot;
Thread.sleep(100);
click();
}
}
}
Minecraft.getMinecraft().thePlayer.inventory.currentItem = prevItem;
milis++;
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}, "Custom Item Use");
thread.start();
}
}
public static void click() {
/*try {
Method clickMouse;
try {
clickMouse = Minecraft.class.getDeclaredMethod("func_147116_af");
} catch (NoSuchMethodException e) {
clickMouse = Minecraft.class.getDeclaredMethod("clickMouse");
}
clickMouse.setAccessible(true);
clickMouse.invoke(Minecraft.getMinecraft());
} catch (Exception e) {
e.printStackTrace();
}*/
Minecraft.getMinecraft().thePlayer.swingItem();
}
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;
}
}
|