Skip to content

Commit 9e33b58

Browse files
author
Ahmed Mahmud
committed
bug fixes
1 parent 1f92073 commit 9e33b58

File tree

9 files changed

+253
-161
lines changed

9 files changed

+253
-161
lines changed

src/main/java/com/jelly/FarmHelper/FarmHelper.java

Lines changed: 121 additions & 36 deletions
Large diffs are not rendered by default.

src/main/java/com/jelly/FarmHelper/gui/ProfitGUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ProfitGUI(Window window) {
3333
})
3434
.setChildOf(window);
3535

36-
UIComponent topBar = new UIBlock(new Color(18, 19, 20, 40))
36+
UIComponent topBar = new UIBlock(new Color(18, 19, 20, 100))
3737
.setX(new PixelConstraint(0))
3838
.setY(new PixelConstraint(0))
3939
.setWidth(new RelativeConstraint(1f))
@@ -93,7 +93,7 @@ public Stat(String iconURL) {
9393
this.setY(new SiblingConstraint())
9494
.setHeight(new ChildBasedSizeConstraint())
9595
.setWidth(new RelativeConstraint(1f))
96-
.setColor(new Color(36, 37, 39, 40));
96+
.setColor(new Color(36, 37, 39, 85));
9797

9898
try {
9999
UIImage.ofURL(new URL(iconURL))

src/main/java/com/jelly/FarmHelper/gui/menus/AutoSellMenu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public AutoSellMenu() {
2323
mc.thePlayer.closeScreen();
2424
FarmHelper.cookie = true;
2525
Utils.ExecuteRunnable(FarmHelper.checkFooter);
26+
FarmHelper.timeoutStart = System.currentTimeMillis();
2627
if (FarmHelper.cookie) LogUtils.debugLog("Executing sell in 1 second");
2728
Utils.ScheduleRunnable(FarmHelper.autoSell, 1, TimeUnit.SECONDS);
2829
return null;

src/main/java/com/jelly/FarmHelper/gui/menus/MiscMenu.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ public MiscMenu() {
2222
((Button) new Button("Buy Cookie").setChildOf(this)).setOnClick((component, uiClickEvent) -> {
2323
FarmHelper.openedGUI = false;
2424
mc.thePlayer.closeScreen();
25-
Utils.ExecuteRunnable(FarmHelper.checkFooter);
25+
FarmHelper.buying = true;
26+
FarmHelper.timeoutStart = System.currentTimeMillis();
2627
Utils.ScheduleRunnable(FarmHelper.buyCookie, 1, TimeUnit.SECONDS);
2728
return null;
2829
});
2930
((Button) new Button("Buy God Potion").setChildOf(this)).setOnClick((component, uiClickEvent) -> {
3031
FarmHelper.openedGUI = false;
3132
mc.thePlayer.closeScreen();
32-
Utils.ExecuteRunnable(FarmHelper.checkFooter);
33+
FarmHelper.buying = true;
34+
FarmHelper.timeoutStart = System.currentTimeMillis();
3335
Utils.ScheduleRunnable(FarmHelper.buyGodPot, 1, TimeUnit.SECONDS);
3436
return null;
3537
});

src/main/java/com/jelly/FarmHelper/utils/AngleUtils.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ public static float antiClockwiseDifference(float initialYaw360, float targetYaw
3636
return get360RotationYaw(initialYaw360 - targetYaw360);
3737
}
3838

39-
public static void smoothRotateTo(float targetYaw360, float speed) {
39+
public static void smoothRotateTo(float targetYaw360, float speed) throws Exception {
4040
if (shouldRotateClockwise(get360RotationYaw(), targetYaw360)) {
4141
smoothRotateClockwise(clockwiseDifference(get360RotationYaw(), targetYaw360), speed);
4242
} else {
4343
smoothRotateAnticlockwise(antiClockwiseDifference(get360RotationYaw(), targetYaw360), speed);
4444
}
4545
}
4646

47-
public static void smoothRotateClockwise(float rotateAngle) {
47+
public static void smoothRotateClockwise(float rotateAngle) throws Exception {
4848
smoothRotateClockwise(rotateAngle, 1);
4949
}
5050

51-
public static void smoothRotateClockwise(float rotateAngle, float speed) {
51+
public static void smoothRotateClockwise(float rotateAngle, float speed) throws Exception {
5252
float targetYaw = (get360RotationYaw() + rotateAngle) % 360;
5353
while (get360RotationYaw() != targetYaw) {
54+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
5455
if (Math.abs(get360RotationYaw() - targetYaw) < speed) {
5556
mc.thePlayer.rotationYaw += Math.abs(get360RotationYaw() - targetYaw);
5657
LogUtils.debugLog("Done rotating");
@@ -65,9 +66,10 @@ public static void smoothRotateClockwise(float rotateAngle, float speed) {
6566
}
6667
}
6768

68-
public static void sineRotateCW(float rotateAngle, float speed) {
69+
public static void sineRotateCW(float rotateAngle, float speed) throws Exception {
6970
float targetYaw = (get360RotationYaw() + rotateAngle) % 360;
7071
while (get360RotationYaw() != targetYaw) {
72+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
7173
float difference = Math.abs(get360RotationYaw() - targetYaw);
7274
if (difference < 0.4f * speed) {
7375
mc.thePlayer.rotationYaw += difference;
@@ -82,13 +84,14 @@ public static void sineRotateCW(float rotateAngle, float speed) {
8284
}
8385
}
8486

85-
public static void smoothRotateAnticlockwise(float rotateAngle) {
87+
public static void smoothRotateAnticlockwise(float rotateAngle) throws Exception {
8688
smoothRotateAnticlockwise(rotateAngle, 1);
8789
}
8890

89-
public static void smoothRotateAnticlockwise(float rotateAngle, float speed) {
91+
public static void smoothRotateAnticlockwise(float rotateAngle, float speed) throws Exception {
9092
float targetYaw = get360RotationYaw(get360RotationYaw() - rotateAngle);
9193
while (get360RotationYaw() != targetYaw) {
94+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
9295
if (Math.abs(get360RotationYaw() - targetYaw) < speed) {
9396
mc.thePlayer.rotationYaw -= Math.abs(get360RotationYaw() - targetYaw);
9497
return;
@@ -102,9 +105,10 @@ public static void smoothRotateAnticlockwise(float rotateAngle, float speed) {
102105
}
103106
}
104107

105-
public static void sineRotateACW(float rotateAngle, float speed) {
108+
public static void sineRotateACW(float rotateAngle, float speed) throws Exception {
106109
float targetYaw = get360RotationYaw(get360RotationYaw() - rotateAngle);
107110
while (get360RotationYaw() != targetYaw) {
111+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
108112
float difference = Math.abs(get360RotationYaw() - targetYaw);
109113
if (difference < 0.4f * speed) {
110114
mc.thePlayer.rotationYaw -= difference;
@@ -129,8 +133,9 @@ public static float getActualRotationYaw(float yaw) { //f3
129133
(-yaw % 360 > 180 ? (180 - (-yaw % 360 - 180)) : -(-yaw % 360));
130134
}
131135

132-
public static void hardRotate(float yaw) {
136+
public static void hardRotate(float yaw) throws Exception {
133137
while (get360RotationYaw() != yaw) {
138+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
134139
if (Math.abs(get360RotationYaw() - yaw) < 0.2f) {
135140
mc.thePlayer.rotationYaw = yaw;
136141
return;

src/main/java/com/jelly/FarmHelper/utils/InventoryUtils.java

Lines changed: 91 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ public static int countSack(int slotID) {
104104
public static void clickWindow(int windowID, int slotID, int button, int clickType) {
105105
mc.playerController.windowClick(windowID, slotID, button, clickType, mc.thePlayer);
106106
}
107+
107108
public static void clickWindow(int windowID, int slotID, int button) {
108109
clickWindow(windowID, slotID, button, 0);
109110
}
111+
110112
public static void clickWindow(int windowID, int slotID) {
111113
clickWindow(windowID, slotID, 0);
112114
}
@@ -130,6 +132,9 @@ public static void waitForItemClick(int slotID, String displayName, int clickSlo
130132
ItemStack stack = mc.thePlayer.openContainer.getSlot(slotID).getStack();
131133
ItemStack clickStack;
132134
while (stack == null || (!stack.getDisplayName().contains(displayName))) {
135+
System.out.println("Waiting for item: " + displayName);
136+
System.out.println("waitForItemClick - status: " +Thread.currentThread().isInterrupted());
137+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
133138
clickStack = mc.thePlayer.openContainer.getSlot(clickSlotID).getStack();
134139
stack = mc.thePlayer.openContainer.getSlot(slotID).getStack();
135140
if (clickStack != null && (clickStack.getDisplayName().contains(clickDisplayName) && !clickStack.getDisplayName().contains(exclude))) {
@@ -147,6 +152,7 @@ public static void waitForItemClick(int slotID, String displayName, int clickSlo
147152
ItemStack stack = mc.thePlayer.openContainer.getSlot(slotID).getStack();
148153
ItemStack clickStack;
149154
while (stack == null || !stack.getDisplayName().contains(displayName)) {
155+
if (Thread.currentThread().isInterrupted()) throw new Exception("Detected interrupt - stopping");
150156
clickStack = mc.thePlayer.openContainer.getSlot(clickSlotID).getStack();
151157
stack = mc.thePlayer.openContainer.getSlot(slotID).getStack();
152158
if (checkItem(clickStack, item)) {
@@ -227,111 +233,109 @@ private static List<ItemStack> copyInventory(ItemStack[] inventory) {
227233
}
228234

229235
public static void getInventoryDifference(ItemStack[] currentInventory) {
230-
while (FarmHelper.enabled) {
231-
List<ItemStack> newInventory = copyInventory(currentInventory);
232-
Map<String, Pair<Integer, NBTTagCompound>> previousInventoryMap = new HashMap<>();
233-
Map<String, Pair<Integer, NBTTagCompound>> newInventoryMap = new HashMap<>();
234-
235-
if (previousInventory != null) {
236-
for (int i = 0; i < newInventory.size(); i++) {
237-
if (i == 8) { // Skip the SkyBlock Menu slot altogether (which includes the Quiver Arrow now)
238-
continue;
239-
}
236+
List<ItemStack> newInventory = copyInventory(currentInventory);
237+
Map<String, Pair<Integer, NBTTagCompound>> previousInventoryMap = new HashMap<>();
238+
Map<String, Pair<Integer, NBTTagCompound>> newInventoryMap = new HashMap<>();
239+
240+
if (previousInventory != null) {
241+
for (int i = 0; i < newInventory.size(); i++) {
242+
if (i == 8) { // Skip the SkyBlock Menu slot altogether (which includes the Quiver Arrow now)
243+
continue;
244+
}
240245

241-
ItemStack previousItem = null;
242-
ItemStack newItem = null;
246+
ItemStack previousItem = null;
247+
ItemStack newItem = null;
243248

244-
try {
245-
previousItem = previousInventory.get(i);
246-
newItem = newInventory.get(i);
249+
try {
250+
previousItem = previousInventory.get(i);
251+
newItem = newInventory.get(i);
247252

248-
if (previousItem != null) {
249-
int amount;
250-
if (previousInventoryMap.containsKey(previousItem.getDisplayName())) {
251-
amount = previousInventoryMap.get(previousItem.getDisplayName()).getKey() + previousItem.stackSize;
252-
} else {
253-
amount = previousItem.stackSize;
254-
}
255-
NBTTagCompound extraAttributes = getExtraAttributes(previousItem);
256-
if (extraAttributes != null) {
257-
extraAttributes = (NBTTagCompound) extraAttributes.copy();
258-
}
259-
previousInventoryMap.put(previousItem.getDisplayName(), new Pair<>(amount, extraAttributes));
253+
if (previousItem != null) {
254+
int amount;
255+
if (previousInventoryMap.containsKey(previousItem.getDisplayName())) {
256+
amount = previousInventoryMap.get(previousItem.getDisplayName()).getKey() + previousItem.stackSize;
257+
} else {
258+
amount = previousItem.stackSize;
259+
}
260+
NBTTagCompound extraAttributes = getExtraAttributes(previousItem);
261+
if (extraAttributes != null) {
262+
extraAttributes = (NBTTagCompound) extraAttributes.copy();
260263
}
264+
previousInventoryMap.put(previousItem.getDisplayName(), new Pair<>(amount, extraAttributes));
265+
}
261266

262-
if (newItem != null) {
263-
if (newItem.getDisplayName().contains(" " + EnumChatFormatting.DARK_GRAY + "x")) {
264-
String newName = newItem.getDisplayName().substring(0, newItem.getDisplayName().lastIndexOf(" "));
265-
newItem.setStackDisplayName(newName); // This is a workaround for merchants, it adds x64 or whatever to the end of the name.
266-
}
267-
int amount;
268-
if (newInventoryMap.containsKey(newItem.getDisplayName())) {
269-
amount = newInventoryMap.get(newItem.getDisplayName()).getKey() + newItem.stackSize;
270-
} else {
271-
amount = newItem.stackSize;
272-
}
273-
NBTTagCompound extraAttributes = getExtraAttributes(newItem);
274-
if (extraAttributes != null) {
275-
extraAttributes = (NBTTagCompound) extraAttributes.copy();
276-
}
277-
newInventoryMap.put(newItem.getDisplayName(), new Pair<>(amount, extraAttributes));
267+
if (newItem != null) {
268+
if (newItem.getDisplayName().contains(" " + EnumChatFormatting.DARK_GRAY + "x")) {
269+
String newName = newItem.getDisplayName().substring(0, newItem.getDisplayName().lastIndexOf(" "));
270+
newItem.setStackDisplayName(newName); // This is a workaround for merchants, it adds x64 or whatever to the end of the name.
278271
}
279-
} catch (Throwable e) {
280-
e.printStackTrace();
272+
int amount;
273+
if (newInventoryMap.containsKey(newItem.getDisplayName())) {
274+
amount = newInventoryMap.get(newItem.getDisplayName()).getKey() + newItem.stackSize;
275+
} else {
276+
amount = newItem.stackSize;
277+
}
278+
NBTTagCompound extraAttributes = getExtraAttributes(newItem);
279+
if (extraAttributes != null) {
280+
extraAttributes = (NBTTagCompound) extraAttributes.copy();
281+
}
282+
newInventoryMap.put(newItem.getDisplayName(), new Pair<>(amount, extraAttributes));
281283
}
284+
} catch (Throwable e) {
285+
e.printStackTrace();
282286
}
287+
}
283288

284-
List<ItemDiff> inventoryDifference = new LinkedList<>();
285-
Set<String> keySet = new HashSet<>(previousInventoryMap.keySet());
286-
keySet.addAll(newInventoryMap.keySet());
287-
288-
keySet.forEach(key -> {
289-
int previousAmount = 0;
290-
if (previousInventoryMap.containsKey(key)) {
291-
previousAmount = previousInventoryMap.get(key).getKey();
292-
}
289+
List<ItemDiff> inventoryDifference = new LinkedList<>();
290+
Set<String> keySet = new HashSet<>(previousInventoryMap.keySet());
291+
keySet.addAll(newInventoryMap.keySet());
293292

294-
int newAmount = 0;
295-
if (newInventoryMap.containsKey(key)) {
296-
newAmount = newInventoryMap.get(key).getKey();
297-
}
293+
keySet.forEach(key -> {
294+
int previousAmount = 0;
295+
if (previousInventoryMap.containsKey(key)) {
296+
previousAmount = previousInventoryMap.get(key).getKey();
297+
}
298298

299-
int diff = newAmount - previousAmount;
300-
if (diff != 0) { // Get the NBT tag from whichever map the name exists in
301-
inventoryDifference.add(new ItemDiff(key, diff, newInventoryMap.getOrDefault(key, previousInventoryMap.get(key)).getValue()));
302-
}
303-
});
304-
305-
// Add changes to already logged changes of the same item, so it will increase/decrease the amount
306-
// instead of displaying the same item twice
307-
if (true) {
308-
for (ItemDiff diff : inventoryDifference) {
309-
Collection<ItemDiff> itemDiffs = itemPickupLog.get(diff.getDisplayName());
310-
if (itemDiffs.size() <= 0) {
311-
itemPickupLog.put(diff.getDisplayName(), diff);
299+
int newAmount = 0;
300+
if (newInventoryMap.containsKey(key)) {
301+
newAmount = newInventoryMap.get(key).getKey();
302+
}
312303

313-
} else {
314-
boolean added = false;
315-
for (ItemDiff loopDiff : itemDiffs) {
316-
if ((diff.getAmount() < 0 && loopDiff.getAmount() < 0) || (diff.getAmount() > 0 && loopDiff.getAmount() > 0)) {
317-
loopDiff.add(diff.getAmount());
318-
added = true;
319-
}
320-
}
321-
if (!added) {
322-
itemPickupLog.put(diff.getDisplayName(), diff);
304+
int diff = newAmount - previousAmount;
305+
if (diff != 0) { // Get the NBT tag from whichever map the name exists in
306+
inventoryDifference.add(new ItemDiff(key, diff, newInventoryMap.getOrDefault(key, previousInventoryMap.get(key)).getValue()));
307+
}
308+
});
309+
310+
// Add changes to already logged changes of the same item, so it will increase/decrease the amount
311+
// instead of displaying the same item twice
312+
if (true) {
313+
for (ItemDiff diff : inventoryDifference) {
314+
Collection<ItemDiff> itemDiffs = itemPickupLog.get(diff.getDisplayName());
315+
if (itemDiffs.size() <= 0) {
316+
itemPickupLog.put(diff.getDisplayName(), diff);
317+
318+
} else {
319+
boolean added = false;
320+
for (ItemDiff loopDiff : itemDiffs) {
321+
if ((diff.getAmount() < 0 && loopDiff.getAmount() < 0) || (diff.getAmount() > 0 && loopDiff.getAmount() > 0)) {
322+
loopDiff.add(diff.getAmount());
323+
added = true;
323324
}
324325
}
326+
if (!added) {
327+
itemPickupLog.put(diff.getDisplayName(), diff);
328+
}
325329
}
326330
}
327331
}
332+
}
328333

329-
previousInventory = newInventory;
330-
try {
331-
Thread.sleep(5);
332-
} catch (InterruptedException e) {
333-
e.printStackTrace();
334-
}
334+
previousInventory = newInventory;
335+
try {
336+
Thread.sleep(5);
337+
} catch (InterruptedException e) {
338+
e.printStackTrace();
335339
}
336340
}
337341

0 commit comments

Comments
 (0)