Skip to content

Commit

Permalink
Important bug fixes
Browse files Browse the repository at this point in the history
Vertical/S-Shape macro:
= Fixed a rare bug causing the macro to get stuck at the spawn

Dirt failsafe:
= Fixed false positives when the player is lagging and breaking the block at the same time

AutoBazaar:
= Fixed the macro getting stuck at the new warning menu

Pests Destroyer:
= Fixed the macro getting stuck when the player is at the edge of the plot by flying to the center so it can find the pest

Visitors Macro:
= Fixed a rare bug causing the next visitor to get accepted after the ignored one
  • Loading branch information
onixiya1337 committed Jul 16, 2024
1 parent 8c281e5 commit d925d1c
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 44 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.8.7-pre1
version=2.8.7-pre2
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.jelly.farmhelperv2.event.BlockChangeEvent;
import com.jelly.farmhelperv2.failsafe.Failsafe;
import com.jelly.farmhelperv2.failsafe.FailsafeManager;
import com.jelly.farmhelperv2.feature.impl.LagDetector;
import com.jelly.farmhelperv2.feature.impl.MovRecPlayer;
import com.jelly.farmhelperv2.handler.BaritoneHandler;
import com.jelly.farmhelperv2.handler.GameStateHandler;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void onBlockChange(BlockChangeEvent event) {
LogUtils.sendDebug("[Failsafe] Block destroyed: " + event.pos);
blocksDestroyedByPlayer.add(new Tuple<>(event.pos, System.currentTimeMillis()));
}
blocksDestroyedByPlayer.removeIf(tuple -> System.currentTimeMillis() - tuple.getSecond() > 2000);
blocksDestroyedByPlayer.removeIf(tuple -> System.currentTimeMillis() - tuple.getSecond() > 10000);
if ((event.old.getBlock().equals(Blocks.air) || CropUtils.isCrop(event.old.getBlock()) || event.old.getBlock().equals(Blocks.water) || event.old.getBlock().equals(Blocks.flowing_water)) &&
event.update.getBlock() != null && !event.update.getBlock().equals(Blocks.air) &&
!CropUtils.isCrop(event.update.getBlock()) && event.update.getBlock().isCollidable() &&
Expand All @@ -79,6 +80,10 @@ public void onBlockChange(BlockChangeEvent event) {
LogUtils.sendDebug("[Failsafe] Block destroyed by player and resynced by hypixel: " + event.pos);
return;
}
if (LagDetector.getInstance().wasJustLagging()) {
LogUtils.sendDebug("[Failsafe] Lag detected, ignoring block change: " + event.pos);
return;
}
LogUtils.sendWarning("[Failsafe] Someone put a block on your garden! Block: " + event.update.getBlock() + " Pos: " + event.pos);
dirtBlocks.add(new Tuple<>(event.pos, System.currentTimeMillis()));
}
Expand Down Expand Up @@ -258,6 +263,10 @@ public boolean isTouchingDirtBlock() {
private boolean blocksRemoved() {
dirtBlocks.removeIf(tuple -> {
if (System.currentTimeMillis() - tuple.getSecond() > 120_000 || !mc.theWorld.getBlockState(tuple.getFirst()).getBlock().isCollidable() || BlockUtils.canWalkThrough(tuple.getFirst()) || mc.theWorld.getBlockState(tuple.getFirst()).getBlock().equals(Blocks.air) || CropUtils.isCrop(mc.theWorld.getBlockState(tuple.getFirst()).getBlock()) || mc.theWorld.getBlockState(tuple.getFirst()).getBlock().equals(Blocks.water) || mc.theWorld.getBlockState(tuple.getFirst()).getBlock().equals(Blocks.flowing_water)) {
if (blocksDestroyedByPlayer.stream().anyMatch(block -> block.getFirst().equals(tuple.getFirst()))) {
LogUtils.sendDebug("[Failsafe] Dirt block removed by player: " + tuple.getFirst());
return false;
}
LogUtils.sendDebug("[Failsafe] Dirt block removed: " + tuple.getFirst());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean shouldAltTab() {
@Override
public void onTickDetection(TickEvent.ClientTickEvent event) {
tabListCheckDelay.schedule(5000L);
if (FarmHelperConfig.pauseOnGuestArrival && wasGuestOnGarden && GameStateHandler.getInstance().isGuestOnGarden()) {
if (FarmHelperConfig.pauseOnGuestArrival && wasGuestInGarden && GameStateHandler.getInstance().isGuestInGarden()) {
if (!MacroHandler.getInstance().isCurrentMacroPaused()) {
LogUtils.sendFailsafeMessage("[Failsafe] Paused the macro because of guest visit!", false);
MacroHandler.getInstance().pauseMacro();
Expand All @@ -68,9 +68,9 @@ public void onTickDetection(TickEvent.ClientTickEvent event) {
@Override
public void duringFailsafeTrigger() {
if (tabListCheckDelay.isScheduled() && !tabListCheckDelay.passed()) return;
if (!GameStateHandler.getInstance().isGuestOnGarden()
if (!GameStateHandler.getInstance().isGuestInGarden()
&& GameStateHandler.getInstance().getLocation() == GameStateHandler.Location.GARDEN
&& wasGuestOnGarden
&& wasGuestInGarden
&& MacroHandler.getInstance().isMacroToggled()
&& MacroHandler.getInstance().isCurrentMacroPaused()) {
LogUtils.sendFailsafeMessage("[Failsafe] Resuming the macro because guest visit is over!", false);
Expand All @@ -88,17 +88,17 @@ public void endOfFailsafeTrigger() {
@Override
public void resetStates() {
tabListCheckDelay.reset();
wasGuestOnGarden = false;
wasGuestInGarden = false;
lastGuestName = "";
}

@Override
public void onChatDetection(ClientChatReceivedEvent event) {
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (message.contains(":")) return;
if (message.contains("is visiting Your Garden") && (!GameStateHandler.getInstance().isGuestOnGarden()) && !wasGuestOnGarden) {
if (message.contains("is visiting Your Garden") && (!GameStateHandler.getInstance().isGuestInGarden()) && !wasGuestInGarden) {
lastGuestName = message.replace("[SkyBlock] ", "").replace(" is visiting Your Garden!", "");
wasGuestOnGarden = true;
wasGuestInGarden = true;
tabListCheckDelay.schedule(5000L);
FailsafeManager.getInstance().possibleDetection(this);
if (!FarmHelperConfig.pauseOnGuestArrival)
Expand All @@ -112,6 +112,6 @@ public void onChatDetection(ClientChatReceivedEvent event) {
}

private final Clock tabListCheckDelay = new Clock();
public boolean wasGuestOnGarden = false;
public boolean wasGuestInGarden = false;
public String lastGuestName = "";
}
30 changes: 27 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 @@ -282,7 +282,7 @@ private void handleBuyFromBz() {
if (customAmount != null && customAmount.getHasStack()) {
this.buyState = BuyState.OPEN_SIGN;
this.buyNowButtonSlot = -1;
LogUtils.sendDebug("[Auto Bazaar] Buying custom amount");
log("Buying custom amount");
return;
}
}
Expand Down Expand Up @@ -372,7 +372,7 @@ private void handleBuyFromBz() {
System.out.println("Max spend limit: " + this.maxSpendLimit);
foundPrice = true;
if (this.maxSpendLimit > 0 && amount > this.maxSpendLimit) {
LogUtils.sendError("[Auto Bazaar] Declining to buy due to exceeding the price limit. Item price: " + amount + ", limit: " + this.maxSpendLimit);
LogUtils.sendError("[AutoBazaar] Declining to buy due to exceeding the price limit. Item price: " + amount + ", limit: " + this.maxSpendLimit);
log("Attempting to spend more than allowed. Price: " + amount + ", limit: " + this.maxSpendLimit);
log("Disabling.");
this.wasManipulated = true;
Expand All @@ -393,11 +393,35 @@ private void handleBuyFromBz() {
this.timer.schedule(2000);
break;
case BUY_VERIFY:
if (!InventoryUtils.isInventoryLoaded()) return;
if (this.openedChestGuiNameContains("Confirm") && !this.openedChestGuiNameContains("Instant Buy")) {
log("Opened warning page");
this.timer.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
this.buyState = BuyState.WARNING_PAGE;
break;
}
if (this.hasTimerEnded()) {
this.disable("Could not buy item. Disabling");
}
// Verifying
break;
case WARNING_PAGE:
if (!InventoryUtils.isInventoryLoaded()) return;
if (this.openedChestGuiNameContains("Confirm") && !this.openedChestGuiNameContains("Instant Buy")) {
if (InventoryUtils.getSlotIdOfItemInContainer("WARNING") != -1) {
this.timer.schedule(1000);
} else if (InventoryUtils.getSlotIdOfItemInContainer("Confirm") != -1) {
this.buyState = BuyState.BUY_VERIFY;
InventoryUtils.clickContainerSlot(InventoryUtils.getSlotIdOfItemInContainer("Confirm"), InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
this.timer.schedule(2000);
}
break;
}
if (this.hasTimerEnded()) {
this.disable("Could not open confirm page.");
}
// Verifying
break;
case DISABLE:
if (!this.hasTimerEnded()) return;

Expand Down Expand Up @@ -561,7 +585,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, CONFIRM_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, WARNING_PAGE, BUY_VERIFY, DISABLE
}

// Insta Sell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public void onMessage(String message) {
+ (macroEnabled ? " while " + (fastBreak ? "§c§nfastbreaking§r§e " : "farming ") + crop + "." : ".")
+ "\n§ePossible reason: §c" + reason + "§e."
+ "\n§eLongest session in the last 7 days: §c" + LogUtils.formatTime(longestSession7D)
+ (!lastFailsafe.isEmpty() ? "\nLast failsafe: §c" + lastFailsafe : ""));
+ (!lastFailsafe.isEmpty() ? "\n§eLast failsafe: §c" + lastFailsafe : ""));
// LogUtils.sendNotification("Farm Helper", "User " + username + " got banned for " + days + " days");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,25 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
}

if (getLocationTries > 2) {
PlotUtils.Plot currentPlot = getClosestPlot();

if (!isNearPlotCenter()) {
if (currentPlot != null) {
BlockPos plotCenter2 = PlotUtils.getPlotCenter(currentPlot.number);
FlyPathFinderExecutor.getInstance().setSprinting(FarmHelperConfig.sprintWhileFlying);
FlyPathFinderExecutor.getInstance().setDontRotate(false);
FlyPathFinderExecutor.getInstance().setUseAOTV(InventoryUtils.hasItemInHotbar("Aspect of the Void", "Aspect of the End"));
FlyPathFinderExecutor.getInstance().findPath(new Vec3(plotCenter2.getX(), 80, plotCenter2.getZ()), true, true);
LogUtils.sendDebug("[Pests Destroyer] Flying to plot center");
} else {
LogUtils.sendWarning("[Pests Destroyer] Couldn't find closest plot!");
state = States.GO_BACK;
}
break;
}
}

resetFireworkInfo();
lastFireworkTime = System.currentTimeMillis();
MovingObjectPosition mop = mc.objectMouseOver;
Expand Down Expand Up @@ -1347,6 +1366,13 @@ private PlotUtils.Plot getClosestPlot() {
return closestPlot;
}

private boolean isNearPlotCenter() {
if (!closestPlot.isPresent()) return false;
BlockPos plotCenter = PlotUtils.getPlotCenter(closestPlot.get().number);
double distance = mc.thePlayer.getDistance(plotCenter.getX(), mc.thePlayer.posY, plotCenter.getZ());
return distance < 15;
}

public enum States {
IDLE,
OPEN_DESK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,13 @@ private void onVisitorsState() {
return;
}
LogUtils.sendDebug("Position of visitor: " + result.entityCharacter.getPositionEyes(1));

currentRewards.clear();
profitNpc = false;
rejectVisitor = false;
haveItemsInSack = false;
LogUtils.sendDebug("Clearing states before serving a new visitor");

currentVisitor = Optional.of(result.nameArmorStand);
currentCharacter = Optional.of(result.entityCharacter);
setVisitorsState(VisitorsState.GET_CLOSE_TO_VISITOR);
Expand Down Expand Up @@ -1066,8 +1073,6 @@ private void onVisitorsState() {
LogUtils.webhookLog("[Visitors Macro]\\nVisitors Macro accepted visitor: " + StringUtils.stripControlCodes(currentVisitor.get().getCustomNameTag()), FarmHelperConfig.pingEveryoneOnVisitorsMacroLogs, currentRewards.toArray(new Tuple[0]));
}
currentVisitor.ifPresent(servedCustomers::add);
currentRewards.clear();
profitNpc = false;
setVisitorsState(VisitorsState.SELECT_NEW_VISITOR);
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
break;
Expand Down Expand Up @@ -1234,29 +1239,21 @@ private void checkIfCurrentVisitorIsProfitable() {
}

private void rejectCurrentVisitor() {
if (rejectVisitor()) return;
assert currentVisitor.isPresent();
if (FarmHelperConfig.sendVisitorsMacroLogs)
LogUtils.webhookLog("[Visitors Macro]\\nVisitors Macro rejected visitor: " + StringUtils.stripControlCodes(currentVisitor.get().getCustomNameTag()), FarmHelperConfig.pingEveryoneOnVisitorsMacroLogs, currentRewards.toArray(new Tuple[0]));
currentVisitor.ifPresent(servedCustomers::add);
currentRewards.clear();
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
setVisitorsState(VisitorsState.SELECT_NEW_VISITOR);
profitNpc = false;
}

private boolean rejectVisitor() {
if (!InventoryUtils.isInventoryLoaded()) return true;
if (!InventoryUtils.isInventoryLoaded()) return;
LogUtils.sendDebug("[Visitors Macro] Rejecting the visitor");
Slot rejectOfferSlot = InventoryUtils.getSlotOfItemInContainer("Refuse Offer");
if (rejectOfferSlot == null || rejectOfferSlot.getStack() == null) {
LogUtils.sendError("[Visitors Macro] Couldn't find the \"Reject Offer\" slot!");
delayClock.schedule(getRandomDelay());
return true;
return;
}
InventoryUtils.clickContainerSlot(rejectOfferSlot.slotNumber, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
rejectVisitor = false;
return false;
assert currentVisitor.isPresent();
if (FarmHelperConfig.sendVisitorsMacroLogs)
LogUtils.webhookLog("[Visitors Macro]\\nVisitors Macro rejected visitor: " + StringUtils.stripControlCodes(currentVisitor.get().getCustomNameTag()), FarmHelperConfig.pingEveryoneOnVisitorsMacroLogs, currentRewards.toArray(new Tuple[0]));
currentVisitor.ifPresent(servedCustomers::add);
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
setVisitorsState(VisitorsState.SELECT_NEW_VISITOR);
}

private void onBuyState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GameStateHandler {
private Location location = Location.TELEPORTING;

private boolean isInJacobContest = false;
private boolean isGuestOnGarden = false;
private boolean isGuestInGarden = false;
@Getter
private boolean frontWalkable;
@Getter
Expand Down Expand Up @@ -176,7 +176,7 @@ public void onTablistUpdate(UpdateTablistEvent event) {
}
}
if (!hasGuestsOnTabList) {
if (checkGuestOnGardenTabList(cleanedLine)) {
if (checkGuestInGardenTabList(cleanedLine)) {
hasGuestsOnTabList = true;
}
}
Expand Down Expand Up @@ -458,13 +458,13 @@ private void checkInfestedPlotsTabList(String cleanedLine) {
}
}

private boolean checkGuestOnGardenTabList(String cleanedLine) {
private boolean checkGuestInGardenTabList(String cleanedLine) {
if (cleanedLine.contains("Guests (0)")) {
isGuestOnGarden = false;
isGuestInGarden = false;
return true;
}
if (cleanedLine.contains("Guests ")) {
isGuestOnGarden = true;
isGuestInGarden = true;
return true;
}
return false;
Expand Down Expand Up @@ -697,8 +697,8 @@ public boolean inJacobContest() {
return isInJacobContest;
}

public boolean isGuestOnGarden() {
return isGuestOnGarden;
public boolean isGuestInGarden() {
return isGuestInGarden;
}

public int getPestsFromVacuum() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jelly/farmhelperv2/hud/DebugHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void getLines(List<String> lines, boolean example) {
if (!FarmHelperConfig.debugMode) return;
if (Minecraft.getMinecraft().thePlayer == null || Minecraft.getMinecraft().theWorld == null) return;
lines.add("§lFarmHelper v" + FarmHelper.VERSION + " Debug HUD");
lines.add("wasGuestOnGarden: " + GuestVisitFailsafe.getInstance().wasGuestOnGarden);
lines.add("wasGuestInGarden: " + GuestVisitFailsafe.getInstance().wasGuestInGarden);
lines.add("Jacob's Contest Collected: " + GameStateHandler.getInstance().getJacobsContestCropNumber());
if (MovRecPlayer.getInstance().isRunning()) {
lines.add("Yaw Difference: " + MovRecPlayer.getYawDifference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void updateState() {
}
break;
}
default:
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public void updateState() {
changeState(calculateDirection());
break;
}
default: {
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ public void updateState() {
}
break;
}
case NONE:
case NONE: {
changeState(calculateDirection());
break;
}
default: {
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ public void updateState() {
}
break;
}
case NONE:
case NONE: {
changeState(calculateDirection());
break;
}
default: {
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public void updateState() {
break;
}
break;
default: {
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public void updateState() {
changeState(calculateDirection());
break;
}
default:
default: {
LogUtils.sendDebug("This shouldn't happen, but it did...");
changeState(State.NONE);
}
}
}

Expand Down
Loading

0 comments on commit d925d1c

Please sign in to comment.