Skip to content

Commit

Permalink
Another try
Browse files Browse the repository at this point in the history
BPS Tracker/Lower Average BPS failsafe:
= Bug fixes
  • Loading branch information
onixiya1337 committed Jul 10, 2024
1 parent 03076b3 commit cd2f953
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 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.4-pre1
version=2.8.4-pre2
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.jelly.farmhelperv2.event.ReceivePacketEvent;
import com.jelly.farmhelperv2.failsafe.impl.*;
import com.jelly.farmhelperv2.feature.FeatureManager;
import com.jelly.farmhelperv2.feature.impl.BPSTracker;
import com.jelly.farmhelperv2.feature.impl.BanInfoWS;
import com.jelly.farmhelperv2.feature.impl.Scheduler;
import com.jelly.farmhelperv2.handler.MacroHandler;
Expand Down Expand Up @@ -277,6 +278,7 @@ public void onTickChooseEmergency(TickEvent.ClientTickEvent event) {
LogUtils.sendDebug("[Failsafe] Emergency chosen: " + StringUtils.stripControlCodes(triggeredFailsafe.get().getType().name()));
FeatureManager.getInstance().disableCurrentlyRunning(Scheduler.getInstance());
Scheduler.getInstance().pause();
BPSTracker.getInstance().pause();
if (FarmHelperConfig.captureClipAfterFailsafe && !FarmHelperConfig.captureClipKeybind.getKeyBinds().isEmpty()) {
if (FarmHelperConfig.clipCapturingType) {
FailsafeUtils.captureClip();
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/BPSTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import cc.polyfrost.oneconfig.utils.Multithreading;
import com.jelly.farmhelperv2.event.PlayerDestroyBlockEvent;
import com.jelly.farmhelperv2.feature.FeatureManager;
import com.jelly.farmhelperv2.feature.IFeature;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.macro.AbstractMacro;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockNetherWart;
import net.minecraft.block.BlockReed;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.Tuple;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand Down Expand Up @@ -86,21 +89,32 @@ public void start() {
IFeature.super.start();
}

private boolean checkForBPS(AbstractMacro.State currentState) {
return currentState != AbstractMacro.State.NONE &&
currentState != AbstractMacro.State.DROPPING &&
currentState != AbstractMacro.State.SWITCHING_SIDE &&
currentState != AbstractMacro.State.SWITCHING_LANE &&
Minecraft.getMinecraft().currentScreen == null;
}

@SubscribeEvent
public void onTickCheckBPS(TickEvent.ClientTickEvent event) {
if (!MacroHandler.getInstance().isMacroToggled()) return;
if (!MacroHandler.getInstance().isCurrentMacroEnabled()) return;
if (event.phase != TickEvent.Phase.START) return;
if (MacroHandler.getInstance().getMacro().checkForBPS())
resume();
else
if (dontCheckForBPS())
pause();
else
resume();
if (isPaused) return;

long currentTime = System.currentTimeMillis();
bpsQueue.add(new Tuple<>(blocksBroken, currentTime));
blocksBroken = 0;

while (!bpsQueue.isEmpty() && bpsQueue.getFirst() == null) {
bpsQueue.removeFirst();
}

if (bpsQueue.size() > 1) {
float elapsedTime = (currentTime - bpsQueue.getFirst().getSecond()) / 1000f;
while (elapsedTime > 10f && bpsQueue.size() > 1) {
Expand All @@ -125,10 +139,12 @@ public String getBPS() {
public boolean dontCheckForBPS() {
return !MacroHandler.getInstance().getMacroingTimer().isScheduled()
|| MacroHandler.getInstance().isCurrentMacroPaused()
|| !MacroHandler.getInstance().getMacro().checkForBPS()
|| !MacroHandler.getInstance().isCurrentMacroEnabled()
|| MacroHandler.getInstance().isTeleporting()
|| MacroHandler.getInstance().isRewarpTeleport()
|| MacroHandler.getInstance().isStartingUp();
|| MacroHandler.getInstance().isStartingUp()
|| !checkForBPS(MacroHandler.getInstance().getMacro().getCurrentState())
|| FeatureManager.getInstance().shouldPauseMacroExecution();
}

public float getBPSFloat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ public void pauseMacro(boolean scheduler) {
beforeTeleportationPos = Optional.empty();
macroingTimer.pause();
analyticsTimer.pause();
LowerAvgBpsFailsafe.getInstance().endOfFailsafeTrigger();
if (scheduler && Freelook.getInstance().isRunning()) {
Freelook.getInstance().stop();
}
if (Scheduler.getInstance().isFarming())
Scheduler.getInstance().pause();
if (!BPSTracker.getInstance().isPaused)
BPSTracker.getInstance().pause();
});
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ public void changeState(State state) {

public abstract void actionAfterTeleport();

public boolean checkForBPS() {
return currentState != State.NONE && currentState != State.DROPPING && currentState != State.SWITCHING_SIDE && currentState != State.SWITCHING_LANE && mc.currentScreen == null;
}

public State calculateDirection() {
if (BlockUtils.getRelativeBlock(-1, 0, 0).equals(Blocks.air) && BlockUtils.getRelativeBlock(-1, -1, 0).equals(Blocks.air)) {
return State.RIGHT;
Expand Down

0 comments on commit cd2f953

Please sign in to comment.