Skip to content

Commit

Permalink
v2.4.5-pre6 - Performance Update
Browse files Browse the repository at this point in the history
= Pests Destroyer - bug fixes, may get stuck less (or more idk)
= Profit Calculator - reset won't trigger bps failsafe anymore
= Performance - further improvements
  • Loading branch information
onixiya1337 committed Feb 15, 2024
1 parent 0f81a68 commit 1935880
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 16 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.4.5-pre5
version=2.4.5-pre6
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class PestsDestroyer implements IFeature {
private Optional<Vec3> lastFireworkLocation = Optional.empty();
private long lastFireworkTime = 0;
private int getLocationTries = 0;
private int flyPathfinderTries = 0;
private RotationState rotationState = RotationState.NONE;

public static PestsDestroyer getInstance() {
Expand Down Expand Up @@ -161,6 +162,7 @@ public void stop() {
enabled = false;
lastFireworkTime = 0;
getLocationTries = 0;
flyPathfinderTries = 0;
finishTries = 0;
FlyPathfinder.getInstance().stuckCounterWithMotion = 0;
FlyPathfinder.getInstance().stuckCounterWithoutMotion = 0;
Expand Down Expand Up @@ -527,6 +529,11 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
break;
}

if ((mc.thePlayer.onGround || !flyDelay.passed()) && mc.thePlayer.capabilities.allowFlying && !mc.thePlayer.capabilities.isFlying) {
fly();
break;
}

if (mc.thePlayer.getDistance(plotCenter.getX(), mc.thePlayer.posY, plotCenter.getZ()) < 15) {
state = States.GET_LOCATION;
KeyBindUtils.stopMovement();
Expand Down Expand Up @@ -734,6 +741,21 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
LogUtils.sendDebug("Should pathfind to: " + entity.posX + " " + (entity.posY + 2.75) + " " + entity.posZ);
FlyPathFinderExecutor.getInstance().findPath(entity, true, true, 2.75f, true);
}
if (FlyPathFinderExecutor.getInstance().getState() == FlyPathFinderExecutor.State.FAILED
&& mc.thePlayer.motionX == 0 && mc.thePlayer.motionZ == 0) {
flyPathfinderTries++;
} else {
flyPathfinderTries = 0;
}
if (flyPathfinderTries > 5) {
LogUtils.sendWarning("[Pests Destroyer] Couldn't pathfind to the pest. Flying from the spawnpoint.");
flyPathfinderTries = 0;
KeyBindUtils.stopMovement();
delayClock.schedule(1_000 + Math.random() * 500);
MacroHandler.getInstance().triggerWarpGarden(true, false);
state = States.CHECKING_SPAWN;
return;
}
if (!RotationHandler.getInstance().isRotating()) {
RotationHandler.getInstance().easeTo(new RotationConfiguration(
new Target(entity).additionalY(0.8f),
Expand Down Expand Up @@ -1052,11 +1074,12 @@ public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase != TickEvent.Phase.START) return;
if (!GameStateHandler.getInstance().inGarden()) return;

List<String> scoreBoard = ScoreboardUtils.getCleanScoreboardLines();
List<String> scoreBoard = ScoreboardUtils.getScoreboardLines(false);
List<String> cleanScoreBoard = ScoreboardUtils.getScoreboardLines(true);

for (String line : scoreBoard) {
String withoutColors = StringUtils.stripControlCodes(line);
String clean = ScoreboardUtils.cleanSB(withoutColors);
for (int i = 0; i < scoreBoard.size(); i++) {
String line = scoreBoard.get(i);
String clean = cleanScoreBoard.get(i);
if (line.contains("ൠ")) {
String[] split = clean.split(" ");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onTick(TickEvent.ClientTickEvent event) {
return;
}

if (ScoreboardUtils.getCleanScoreboardLines().stream().noneMatch(line -> line.contains("Cleanup"))) {
if (ScoreboardUtils.getScoreboardLines(true).stream().noneMatch(line -> line.contains("Cleanup"))) {
scytheBlockPos.clear();
treeCapitatorBlockPos.clear();
pickaxeBlockPos.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.google.gson.JsonObject;
import com.jelly.farmhelperv2.event.ClickedBlockEvent;
import com.jelly.farmhelperv2.event.ReceivePacketEvent;
import com.jelly.farmhelperv2.failsafe.Failsafe;
import com.jelly.farmhelperv2.failsafe.FailsafeManager;
import com.jelly.farmhelperv2.failsafe.impl.LowerAvgBpsFailsafe;
import com.jelly.farmhelperv2.feature.IFeature;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
Expand Down Expand Up @@ -280,6 +283,7 @@ public void resetProfits() {
itemsDropped.clear();
cropsToCount.forEach(crop -> crop.currentAmount = 0);
rngDropToCount.forEach(drop -> drop.currentAmount = 0);
LowerAvgBpsFailsafe.getInstance().resetStates();
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onTickCheckScoreboard(TickEvent.PlayerTickEvent event) {
}
if (event.phase != TickEvent.Phase.START) return;

List<String> cleanScoreboardLines = ScoreboardUtils.getCleanScoreboardLines();
List<String> cleanScoreboardLines = ScoreboardUtils.getScoreboardLines(true);
List<String> tabList = TablistUtils.getTabList();

onTickCheckCoins(cleanScoreboardLines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
}
}

mc.thePlayer.setSprinting(FarmHelperConfig.sprintWhileFlying && neededKeys.contains(mc.gameSettings.keyBindForward) && current.distanceTo(new Vec3(next.xCoord, current.yCoord, next.zCoord)) > 6);
mc.thePlayer.setSprinting(FarmHelperConfig.sprintWhileFlying && neededKeys.contains(mc.gameSettings.keyBindForward) && !neededKeys.contains(mc.gameSettings.keyBindSneak) && current.distanceTo(new Vec3(next.xCoord, current.yCoord, next.zCoord)) > 6);

// System.out.println("Buttons: " + keyBindings.stream().map(keyBinding -> keyBinding == null ? "null" : keyBinding.getKeyDescription()).collect(Collectors.joining(", ")));
if (neededYaw != Integer.MIN_VALUE)
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/jelly/farmhelperv2/util/ScoreboardUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class ScoreboardUtils {
private static final Minecraft mc = Minecraft.getMinecraft();
private static List<String> cachedScoreboardLines = new ArrayList<>();
private static List<String> cachedCleanScoreboardLines = new ArrayList<>();
private static long lastUpdateTimestamp = 0;

public static List<String> getCleanScoreboardLines() {
public static List<String> getScoreboardLines(boolean clean) {
long currentTime = System.currentTimeMillis();
if (!cachedScoreboardLines.isEmpty() && currentTime - lastUpdateTimestamp < 50) {
return cachedScoreboardLines;
return (clean ? cachedCleanScoreboardLines : cachedScoreboardLines);
}
cachedScoreboardLines.clear();
if (mc.theWorld == null) return cachedScoreboardLines;
cachedCleanScoreboardLines.clear();
if (mc.theWorld == null) return (clean ? cachedCleanScoreboardLines : cachedScoreboardLines);
Scoreboard scoreboard = mc.theWorld.getScoreboard();
if (scoreboard == null) return cachedScoreboardLines;
if (scoreboard == null) return (clean ? cachedCleanScoreboardLines : cachedScoreboardLines);

ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1);
if (objective == null) return cachedScoreboardLines;
if (objective == null) return (clean ? cachedCleanScoreboardLines : cachedScoreboardLines);

Collection<Score> scores = scoreboard.getSortedScores(objective);
List<Score> list = scores.stream()
Expand All @@ -47,11 +48,12 @@ public static List<String> getCleanScoreboardLines() {

for (Score score : scores) {
ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName());
cachedScoreboardLines.add(cleanSB(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())));
cachedScoreboardLines.add(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName()));
cachedCleanScoreboardLines.add(cleanSB(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())));
}

lastUpdateTimestamp = currentTime;
return cachedScoreboardLines;
return (clean ? cachedCleanScoreboardLines : cachedScoreboardLines);
}

public static String getScoreboardTitle() {
Expand Down

0 comments on commit 1935880

Please sign in to comment.