Skip to content

Commit cc34bd3

Browse files
author
Ahmed Mahmud
committed
ungrab, smooth rotate on rotation check
1 parent 5628abf commit cc34bd3

File tree

7 files changed

+177
-98
lines changed

7 files changed

+177
-98
lines changed

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

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ static void initialize() {
190190
beforeX = mc.thePlayer.posX;
191191
beforeY = mc.thePlayer.posY;
192192
beforeZ = mc.thePlayer.posZ;
193+
angleEnum = Math.round(AngleUtils.get360RotationYaw() / 90) < 4 ? AngleEnum.values()[Math.round(AngleUtils.get360RotationYaw() / 90)] : AngleEnum.A0;
194+
playerYaw = AngleUtils.angleToValue(angleEnum);
195+
196+
try {
197+
AngleUtils.smoothRotateTo(AngleUtils.get360RotationYaw(playerYaw), 1);
198+
} catch (Exception e) {
199+
e.printStackTrace();
200+
}
193201

194202
Utils.resetExecutor();
195203
mc.thePlayer.closeScreen();
@@ -300,17 +308,30 @@ public void OnKeyPress(InputEvent.KeyInputEvent event) {
300308
mc.displayGuiScreen(new MenuGUI());
301309
}
302310
if (customKeyBinds[1].isPressed()) {
311+
mc.thePlayer.closeScreen();
312+
openedGUI = false;
313+
303314
if (!enabled) {
304315
LogUtils.scriptLog("Starting script", EnumChatFormatting.GREEN);
305316
LogUtils.configLog();
317+
if (MiscConfig.ungrab) Utils.ungrabMouse();
306318
if (MiscConfig.dropStone) {
307319
LogUtils.scriptLog("Make sure slot 7 has nothing important or it may be dropped", EnumChatFormatting.RED);
308320
}
309321
if (MiscConfig.dropStone || AutoSellConfig.autoSell || MiscConfig.autoCookie || MiscConfig.autoGodPot) {
310322
LogUtils.scriptLog("Make sure important slots are locked with SBA", EnumChatFormatting.DARK_BLUE);
311323
}
324+
enabled = true;
325+
initialize();
326+
} else {
327+
enabled = false;
328+
Utils.regrabMouse();
329+
LogUtils.scriptLog("Stopped script");
330+
LogUtils.webhookLog("Stopped script");
331+
updateKeys(false, false, false, false, false, false);
332+
Utils.resetExecutor();
333+
mc.thePlayer.closeScreen();
312334
}
313-
toggle();
314335
}
315336
}
316337

@@ -581,25 +602,46 @@ else if (!fixTpStuckFlag && blockIn == Blocks.end_portal_frame && (mc.thePlayer.
581602
}
582603
// In trenches walking along the layer
583604
else if (inTrenches) {
584-
angleEnum = Math.round(AngleUtils.get360RotationYaw() / 90) < 4 ? AngleEnum.values()[Math.round(AngleUtils.get360RotationYaw() / 90)] : AngleEnum.A0;
585-
playerYaw = AngleUtils.angleToValue(angleEnum);
586605
if (FarmConfig.cropType.equals(CropEnum.NETHERWART)) {
587606
mc.thePlayer.rotationPitch = 0;
588607
} else {
589608
mc.thePlayer.rotationPitch = (float) 2.8;
590609
}
610+
if (!rotating && AngleUtils.smallestAngleDifference(AngleUtils.get360RotationYaw(playerYaw), AngleUtils.get360RotationYaw()) > 179) {
611+
LogUtils.debugLog("180 pad yaw change detected, ignoring");
612+
angleEnum = Math.round(AngleUtils.get360RotationYaw() / 90) < 4 ? AngleEnum.values()[Math.round(AngleUtils.get360RotationYaw() / 90)] : AngleEnum.A0;
613+
playerYaw = AngleUtils.angleToValue(angleEnum);
614+
} else if (!rotating && AngleUtils.smallestAngleDifference(AngleUtils.get360RotationYaw(playerYaw), AngleUtils.get360RotationYaw()) > 10) {
615+
LogUtils.scriptLog("Possible staff rotation check", EnumChatFormatting.RED);
616+
LogUtils.webhookLog("Possible staff rotation check");
617+
new Thread(() -> {
618+
try {
619+
Thread.sleep(800);
620+
updateKeys(false, false, false, false, false, false);
621+
Thread.sleep(800);
622+
AngleUtils.smoothRotateTo(AngleUtils.get360RotationYaw(playerYaw), 1);
623+
rotating = false;
624+
} catch (Exception e) {
625+
e.printStackTrace();
626+
}
627+
}).start();
628+
rotating = true;
629+
}
630+
if (rotating) {
631+
return;
632+
}
591633
// Not falling
592634
if (FarmConfig.farmType == FarmEnum.LAYERED) {
593635
if (dy == 0) {
594636
// If on solid block
595637
if ((mc.thePlayer.posY % 1) == 0) {
596-
if (!stuck && !dropping) {
597-
try {
598-
AngleUtils.hardRotate(playerYaw);
599-
} catch (Exception e) {
600-
e.printStackTrace();
601-
}
602-
}
638+
// if (!stuck && !dropping) {
639+
// try {
640+
// AngleUtils.hardRotate(playerYaw);
641+
// } catch (Exception e) {
642+
// e.printStackTrace();
643+
// }
644+
// }
603645
// Cannot move forwards or backwards
604646
if (!isWalkable(BlockUtils.getFrontBlock()) && !isWalkable(BlockUtils.getBackBlock())) {
605647
if (!checkFull && !selling && mc.thePlayer.inventory.getFirstEmptyStack() == -1) {
@@ -965,7 +1007,6 @@ public void run() {
9651007
angleEnum = angleEnum.ordinal() < 2 ? AngleEnum.values()[angleEnum.ordinal() + 2] : AngleEnum.values()[angleEnum.ordinal() - 2];
9661008
playerYaw = AngleUtils.angleToValue(angleEnum);
9671009
AngleUtils.smoothRotateClockwise(180, 1.2f);
968-
System.out.println("-------EXPECTED: " + AngleUtils.get360RotationYaw() + "ACTUAL--------" + playerYaw);
9691010
Thread.sleep(100);
9701011
KeyBinding.setKeyBindState(PlayerUtils.keybindW, true);
9711012
Thread.sleep(200);
@@ -1617,18 +1658,6 @@ public static void setStuckCooldown(int seconds) {
16171658
}
16181659

16191660
public static void toggle() {
1620-
mc.thePlayer.closeScreen();
1621-
if (enabled) {
1622-
enabled = false;
1623-
LogUtils.scriptLog("Stopped script");
1624-
LogUtils.webhookLog("Stopped script");
1625-
updateKeys(false, false, false, false, false, false);
1626-
Utils.resetExecutor();
1627-
mc.thePlayer.closeScreen();
1628-
} else {
1629-
enabled = true;
1630-
initialize();
1631-
}
1632-
openedGUI = false;
1661+
16331662
}
16341663
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static JSONObject getDefaultConfig() {
3030
config.put("autoGodPot", false);
3131
config.put("autoCookie", false);
3232
config.put("dropStone", true);
33+
config.put("ungrab", true);
3334
config.put("debugMode", false);
3435
config.put("cropType", 1);
3536
config.put("farmType", 0);

src/main/java/com/jelly/FarmHelper/config/interfaces/MiscConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class MiscConfig {
99
public static boolean autoCookie;
1010
public static boolean dropStone;
1111
public static boolean debugMode;
12+
public static boolean ungrab;
1213

1314
public static void update() {
1415
resync = (boolean) FarmHelperConfig.get("resync");
1516
fastbreak = (boolean) FarmHelperConfig.get("fastbreak");
1617
autoGodPot = (boolean) FarmHelperConfig.get("autoGodPot");
1718
autoCookie = (boolean) FarmHelperConfig.get("autoCookie");
1819
dropStone = (boolean) FarmHelperConfig.get("dropStone");
20+
ungrab = (boolean) FarmHelperConfig.get("ungrab");
1921
debugMode = (boolean) FarmHelperConfig.get("debugMode");
2022
}
2123
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public MenuGUI() {
2121
new List(new PixelConstraint(10), new PixelConstraint(10), "Farm Helper", new FarmMenu()).setChildOf(getWindow());
2222
new List(new PixelConstraint(170), new PixelConstraint(10), "Webhooks", new WebhookMenu()).setChildOf(getWindow());
2323
new List(new PixelConstraint(330), new PixelConstraint(10), "Jacob", new JacobMenu()).setChildOf(getWindow());
24-
new List(new PixelConstraint(490), new PixelConstraint(10), "Auto Sell", new AutoSellMenu()).setChildOf(getWindow());
24+
new List(new PixelConstraint(490), new PixelConstraint(10), "Miscellaneous", new MiscMenu()).setChildOf(getWindow());
2525
new List(new PixelConstraint(650), new PixelConstraint(10), "Profit Calculator", new ProfitCalculatorMenu()).setChildOf(getWindow());
26-
new List(new PixelConstraint(170), new PixelConstraint(201), "Miscellaneous", new MiscMenu()).setChildOf(getWindow());
27-
26+
new List(new PixelConstraint(170), new PixelConstraint(201), "Auto Sell", new AutoSellMenu()).setChildOf(getWindow());
2827
}
2928
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public MiscMenu() {
1818
new Toggle("Auto GodPot", "autoGodPot").setChildOf(this);
1919
new Toggle("Auto Cookie", "autoCookie").setChildOf(this);
2020
new Toggle("Drop Stone", "dropStone").setChildOf(this);
21+
new Toggle("Ungrab Mouse", "ungrab").setChildOf(this);
2122
new Toggle("Debug Mode", "debugMode").setChildOf(this);
2223
new Toggle("Fastbreak", "fastbreak").setChildOf(this);
2324
((Button) new Button("Buy Cookie").setChildOf(this)).setOnClick((component, uiClickEvent) -> {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.jelly.FarmHelper.config.enums.AngleEnum;
44
import net.minecraft.client.Minecraft;
55

6+
import java.util.Map;
7+
68
public class AngleUtils {
79
private static Minecraft mc = Minecraft.getMinecraft();
810

@@ -36,6 +38,10 @@ public static float antiClockwiseDifference(float initialYaw360, float targetYaw
3638
return get360RotationYaw(initialYaw360 - targetYaw360);
3739
}
3840

41+
public static float smallestAngleDifference(float initialYaw360, float targetYaw360) {
42+
return Math.min(clockwiseDifference(initialYaw360, targetYaw360), antiClockwiseDifference(initialYaw360, targetYaw360));
43+
}
44+
3945
public static void smoothRotateTo(float targetYaw360, float speed) throws Exception {
4046
if (shouldRotateClockwise(get360RotationYaw(), targetYaw360)) {
4147
smoothRotateClockwise(clockwiseDifference(get360RotationYaw(), targetYaw360), speed);

0 commit comments

Comments
 (0)