Skip to content

Commit

Permalink
AutoBazaar (Visitors Macro):
Browse files Browse the repository at this point in the history
 = Highly possible fix for macro rarely ignoring buy limit, that was caused by lags or really low gui delays
 = Other tweaks

AutoSell:
 + Macro won't try to sell Cactus Knife

Freelook:
 = Reversed scrolling
 + Scrolling won't work in guis

Macros:
 = Macro won't readjust to new random values every pause

Ungrab Mouse:
 + Possible fix for rare crash during auto reconnect

Rotations:
 = Fixed issue of not fully rotating after pd ott and others
  • Loading branch information
May2Beez committed Mar 29, 2024
1 parent c42665c commit fe5edf2
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 112 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.5.9
version=2.5.10
shouldRelease=true
4 changes: 1 addition & 3 deletions src/main/java/com/jelly/farmhelperv2/FarmHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.opengl.Display;

import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand All @@ -58,7 +56,7 @@ public void init(FMLInitializationEvent event) {
mc.gameSettings.pauseOnLostFocus = false;
mc.gameSettings.gammaSetting = 1000;
isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().contains("-agentlib:jdwp");
if (!FarmHelperConfig.streamerMode)
if (!FarmHelperConfig.streamerMode && FarmHelperConfig.changeWindowTitle)
Display.setTitle("Farm Helper 〔v" + VERSION + "〕 " + (!isDebug ? "Bing Chilling" : "wazzup dev?") + " ☛ " + Minecraft.getMinecraft().getSession().getUsername());
FailsafeUtils.getInstance();
PlotUtils.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ public class FarmHelperConfig extends Config {
description = "Mutes the game while farming"
)
public static boolean muteTheGame = false;

@Switch(
name = "Change window's title", category = MISCELLANEOUS, subcategory = "Miscellaneous",
description = "Changes the window's title"
)
public static boolean changeWindowTitle = true;

@Switch(
name = "Auto Cookie", category = MISCELLANEOUS, subcategory = "Miscellaneous",
description = "Automatically purchases and consumes a booster cookie"
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AutoBazaar.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ private void handleBuyFromBz() {
if (!this.hasTimerEnded()) return;

SignUtils.setTextToWriteOnString(String.valueOf(this.buyAmount));
this.timer.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
this.buyState = BuyState.CONFIRM_SIGN;
break;
case CONFIRM_SIGN:
if (!this.hasTimerEnded()) return;
SignUtils.confirmSign();
this.timer.schedule(2000);
this.buyState = BuyState.VERIFY_CONFIRM_PAGE;
break;
Expand All @@ -328,15 +334,21 @@ private void handleBuyFromBz() {
return;
}

Slot slot = InventoryUtils.getSlotOfId(instaBuySlot);
if (slot == null || !slot.getHasStack()) return;

boolean foundPrice = false;

if (this.maxSpendLimit != 0) {
String lore = String.join(" ", InventoryUtils.getLoreOfItemInContainer(instaBuySlot)).replace(",", "");
String lore = String.join(" ", InventoryUtils.getItemLore(slot.getStack())).replace(",", "");
Matcher matcher = this.totalCostPattern.matcher(lore);
System.out.println(lore);

if (matcher.find()) {
float amount = Float.parseFloat(matcher.group(1));
System.out.println("Amount: " + amount);
System.out.println("Max spend limit: " + this.maxSpendLimit);
foundPrice = true;
if (amount > this.maxSpendLimit) {
log("Attempting to spend more than allowed. Price: " + amount + ", limit: " + this.maxSpendLimit);
log("Disabling.");
Expand All @@ -347,10 +359,17 @@ private void handleBuyFromBz() {
}
// For high pong gamers - Might get stuck in an inf loop here if internet is bad
if (lore.contains("Loading...")) return;
} else {
foundPrice = true;
}

if (!foundPrice) {
this.disable("Could not find price.");
return;
}

InventoryUtils.clickContainerSlot(instaBuySlot, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
this.buyState = BuyState.BUY_VERIFY;
InventoryUtils.clickContainerSlot(instaBuySlot, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
this.timer.schedule(2000);
break;
case BUY_VERIFY:
Expand Down Expand Up @@ -522,7 +541,7 @@ enum MainState {

// Insta Buy
enum BuyState {
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_ON_PRODUCT, PRODUCT_VERIFY, CLICK_BUY_INSTANTLY, BUY_INSTANTLY_VERIFY, OPEN_SIGN, OPEN_SIGN_VERIFY, EDIT_SIGN, VERIFY_CONFIRM_PAGE, CLICK_BUY, BUY_VERIFY, DISABLE
STARTING, OPEN_BZ, BZ_VERIFY, CLICK_ON_PRODUCT, PRODUCT_VERIFY, CLICK_BUY_INSTANTLY, BUY_INSTANTLY_VERIFY, OPEN_SIGN, OPEN_SIGN_VERIFY, EDIT_SIGN, CONFIRM_SIGN, VERIFY_CONFIRM_PAGE, CLICK_BUY, BUY_VERIFY, DISABLE
}

// Insta Sell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ private void onAhState(boolean rightClick) {
InventoryUtils.clickContainerSlot(searchItem.slotNumber, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
setAhState(AhState.SORT_ITEMS);
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
Multithreading.schedule(() -> SignUtils.setTextToWriteOnString("God Potion"), (long) (400 + Math.random() * 400), TimeUnit.MILLISECONDS);
Multithreading.schedule(() -> {
SignUtils.setTextToWriteOnString("God Potion");
Multithreading.schedule(SignUtils::confirmSign, 500, TimeUnit.MILLISECONDS);
}, (long) (400 + Math.random() * 400), TimeUnit.MILLISECONDS);
break;
case SORT_ITEMS:
if (mc.currentScreen == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ public void stop() {
MacroHandler.getInstance().resumeMacro();
macroWasToggled = false;
if (UngrabMouse.getInstance().isToggled()) {
UngrabMouse.getInstance().regrabMouse(true);
UngrabMouse.getInstance().ungrabMouse();
try {
UngrabMouse.getInstance().regrabMouse(true);
UngrabMouse.getInstance().ungrabMouse();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ private boolean hasShitItemsInInventory() {
private boolean shouldSell(String name) {
if (name.contains("Sack")) return false;
if (name.contains("Pouch")) return false;
if (name.contains("Knife")) return false;
if (shouldSellCustomItem(name)) return true;
return crops.stream().anyMatch(crop -> StringUtils.stripControlCodes(name).startsWith(crop));
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/UngrabMouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,20 @@ public boolean shouldStartAtMacroStart() {

@Override
public void start() {
ungrabMouse();
try {
ungrabMouse();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void stop() {
regrabMouse();
try {
regrabMouse();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ private void onVisitorsState() {
}
LogUtils.sendDebug("Position of visitor: " + result.entityCharacter.getPositionEyes(1));
if (mc.thePlayer.getDistanceToEntity(result.entityCharacter) > 3) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(result.entityCharacter, 1.5, 45, 45);
Vec3 closestVec = PlayerUtils.getClosestVecAround(result.entityCharacter, 1.35, 90, 45);
if (closestVec == null) {
LogUtils.sendError("[Visitors Macro] Couldn't find a position to get closer");
stop();
Expand Down Expand Up @@ -748,7 +748,14 @@ private void onVisitorsState() {
case GET_TO_CLOSEST_VISITOR:
LogUtils.sendDebug("[Visitors Macro] Getting the closest visitor");
assert currentVisitor.isPresent();
if (rotation.isRotating()) return;
if (!rotation.isRotating())
rotation.easeTo(
new RotationConfiguration(
new Target(closestVec.get().addVector(0, 1.6, 0)),
FarmHelperConfig.getRandomRotationTime(),
null
).easeOutBack(Math.random() > 0.5)
);
if (getCloserToEntity()) break;
KeyBindUtils.stopMovement();

Expand All @@ -762,9 +769,7 @@ private void onVisitorsState() {
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
break;
}
if (rotation.isRotating()) return;
assert currentVisitor.isPresent();
if (moveAwayIfPlayerTooClose()) return;
if (mc.objectMouseOver != null && mc.objectMouseOver.entityHit != null) {
Entity entity = mc.objectMouseOver.entityHit;
VisitorEntities result2 = getVisitorEntities(entity);
Expand All @@ -782,6 +787,8 @@ private void onVisitorsState() {
}
break;
}
if (rotation.isRotating()) return;
if (moveAwayIfPlayerTooClose()) return;
LogUtils.sendDebug("[Visitors Macro] Looking at nothing");
LogUtils.sendDebug("[Visitors Macro] Distance: " + mc.thePlayer.getDistanceToEntity(currentCharacter.get()));
setVisitorsState(VisitorsState.ROTATE_TO_VISITOR);
Expand Down Expand Up @@ -1025,13 +1032,14 @@ private void onVisitorsState() {
}
LogUtils.sendDebug("Position of visitor: " + currentCharacter.get().getPositionEyes(1));
if (mc.thePlayer.getDistanceToEntity(currentCharacter.get()) > 3) {
Vec3 closestVec = PlayerUtils.getClosestVecAround(currentCharacter.get(), 1.5, 45, 45);
Vec3 closestVec = PlayerUtils.getClosestVecAround(currentCharacter.get(), 1.35, 90, 45);
if (closestVec == null) {
LogUtils.sendError("[Visitors Macro] Couldn't find a position to get closer");
stop();
FarmHelperConfig.visitorsMacro = false;
return;
}
this.closestVec = Optional.of(closestVec);
if (FarmHelperConfig.visitorsMacroUsePathFinder) {
// BaritoneHandler.walkCloserToBlockPos(currentCharacter.get().getPosition(), 1);
FlyPathFinderExecutor.getInstance().setSprinting(false);
Expand Down Expand Up @@ -1068,7 +1076,14 @@ private void onVisitorsState() {
case GET_TO_CLOSEST_VISITOR_2:
LogUtils.sendDebug("[Visitors Macro] Getting the closest visitor");
assert currentVisitor.isPresent();
if (rotation.isRotating()) return;
if (!rotation.isRotating())
rotation.easeTo(
new RotationConfiguration(
new Target(closestVec.get().addVector(0, 1.6, 0)),
FarmHelperConfig.getRandomRotationTime(),
null
).easeOutBack(Math.random() > 0.5)
);
if (getCloserToEntity()) break;
KeyBindUtils.stopMovement();

Expand All @@ -1082,11 +1097,9 @@ private void onVisitorsState() {
delayClock.schedule(getRandomDelay());
break;
}
if (BaritoneHandler.isWalkingToGoalBlock()) return;
if (rotation.isRotating()) return;
// if (BaritoneHandler.isWalkingToGoalBlock()) return;
assert currentVisitor.isPresent();
assert currentCharacter.isPresent();
if (moveAwayIfPlayerTooClose()) return;
if (mc.objectMouseOver != null && mc.objectMouseOver.entityHit != null) {
Entity entity = mc.objectMouseOver.entityHit;
VisitorEntities result2 = getVisitorEntities(entity);
Expand All @@ -1103,11 +1116,12 @@ private void onVisitorsState() {
moveSideways();
}
break;
} else {
LogUtils.sendDebug("[Visitors Macro] Looking at nothing");
LogUtils.sendDebug("[Visitors Macro] Distance: " + mc.thePlayer.getDistanceToEntity(currentCharacter.get()));
setVisitorsState(VisitorsState.ROTATE_TO_VISITOR_2);
}
if (rotation.isRotating()) return;
if (moveAwayIfPlayerTooClose()) return;
LogUtils.sendDebug("[Visitors Macro] Looking at nothing");
LogUtils.sendDebug("[Visitors Macro] Distance: " + mc.thePlayer.getDistanceToEntity(currentCharacter.get()));
setVisitorsState(VisitorsState.ROTATE_TO_VISITOR_2);
break;
case FINISH_VISITOR:
if (mc.currentScreen == null) {
Expand Down Expand Up @@ -1187,8 +1201,8 @@ private void onVisitorsState() {
}

private boolean getCloserToEntity() {
if (closestVec.isPresent() && currentCharacter.isPresent() && mc.thePlayer.getDistance(closestVec.get().xCoord, closestVec.get().yCoord, closestVec.get().zCoord) > 0.3) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
if (closestVec.isPresent() && currentCharacter.isPresent() && mc.thePlayer.getDistance(closestVec.get().xCoord, closestVec.get().yCoord, closestVec.get().zCoord) > 0.6) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 250 && (mc.thePlayer.motionX > 0.1 || mc.thePlayer.motionZ > 0.1) ? mc.gameSettings.keyBindSneak : null);
stuckClock.schedule(STUCK_DELAY);
return true;
}
Expand Down Expand Up @@ -1268,6 +1282,7 @@ private Entity getClosestVisitor() {
private Stream<Entity> getVisitors() {
return mc.theWorld.getLoadedEntityList().stream()
.filter(e -> e instanceof EntityArmorStand)
.filter(e -> e.getDistanceToEntity(mc.thePlayer) < 12)
.filter(e -> !servedCustomers.contains(e))
.filter(entity2 -> entity2.hasCustomName() && visitors.stream().anyMatch(v -> equalsWithoutFormatting(v, entity2.getCustomNameTag())))
.filter(entity2 -> !ignoredNPCs.contains(entity2));
Expand All @@ -1282,7 +1297,7 @@ private boolean moveAwayIfPlayerTooClose() {
assert currentCharacter.isPresent();
if (mc.thePlayer.getDistanceToEntity(currentCharacter.get()) < 0.25) {
if (GameStateHandler.getInstance().isBackWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindBack, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindBack, GameStateHandler.getInstance().getSpeed() > 250 && (mc.thePlayer.motionX > 0.1 || mc.thePlayer.motionZ > 0.1) ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
Expand All @@ -1295,12 +1310,12 @@ private boolean moveAwayIfPlayerTooClose() {

private boolean moveSideways() {
if (GameStateHandler.getInstance().isLeftWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindLeft, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindLeft, GameStateHandler.getInstance().getSpeed() > 250 && (mc.thePlayer.motionX > 0.1 || mc.thePlayer.motionZ > 0.1) ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
if (GameStateHandler.getInstance().isRightWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindRight, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindRight, GameStateHandler.getInstance().getSpeed() > 250 && (mc.thePlayer.motionX > 0.1 || mc.thePlayer.motionZ > 0.1) ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,8 @@ public void onRender(RenderWorldLastEvent event) {
if (configuration.callback().isPresent()) {
configuration.callback().get().run();
} else { // No callback, just reset
if (Math.abs(mc.thePlayer.rotationYaw - targetRotation.getYaw()) < 0.1) {
mc.thePlayer.rotationYaw = targetRotation.getYaw();
}
if (Math.abs(mc.thePlayer.rotationPitch - targetRotation.getPitch()) < 0.1) {
mc.thePlayer.rotationPitch = targetRotation.getPitch();
}
mc.thePlayer.rotationYaw = targetRotation.getYaw();
mc.thePlayer.rotationPitch = targetRotation.getPitch();
reset();
return;
}
Expand Down
Loading

0 comments on commit fe5edf2

Please sign in to comment.