Skip to content

Commit

Permalink
= Status HUD - Again changes
Browse files Browse the repository at this point in the history
= Fixed not holding left click while dropping in vertical farms
= Fixed 'bouncing' of the wall while holding W in water
= Some Keybindings tweaks
  • Loading branch information
May2Beez committed Jan 6, 2024
1 parent dcafa38 commit b0e8eca
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 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.0-pre7
version=2.4.0-pre8
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

Expand Down Expand Up @@ -96,8 +97,8 @@ public boolean isFarming() {

public String getStatusString() {
if (FarmHelperConfig.enableScheduler) {
return (schedulerState == SchedulerState.FARMING ? "Farming" : "Break") + " for "
+ LogUtils.formatTime(Math.max(schedulerClock.getRemainingTime(), 0)) + (schedulerClock.isPaused() ? " (Paused)" : "");
return EnumChatFormatting.BOLD + (schedulerState == SchedulerState.FARMING ? (EnumChatFormatting.GREEN + "Farming") : (EnumChatFormatting.DARK_AQUA + "Break")) + EnumChatFormatting.RESET + " for " +
EnumChatFormatting.BOLD + EnumChatFormatting.GOLD + LogUtils.formatTime(Math.max(schedulerClock.getRemainingTime(), 0)) + EnumChatFormatting.RESET + (schedulerClock.isPaused() ? " (Paused)" : "");
} else {
return "Farming";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public boolean holdingKeybindIsWalkable() {
KeyBinding[] holdingKeybinds = KeyBindUtils.getHoldingKeybinds();
for (KeyBinding key : holdingKeybinds) {
if (key != null && key.isKeyDown()) {
if (key == mc.gameSettings.keyBindForward && !frontWalkable) {
if (key == mc.gameSettings.keyBindForward && !frontWalkable && !FarmHelperConfig.alwaysHoldW) {
return false;
} else if (key == mc.gameSettings.keyBindBack && !backWalkable) {
return false;
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/com/jelly/farmhelperv2/hud/StatusHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.jelly.farmhelperv2.remote.DiscordBotHandler;
import com.jelly.farmhelperv2.util.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.common.Loader;

import java.util.ArrayList;
Expand Down Expand Up @@ -43,9 +45,9 @@ protected void getLines(List<String> lines, boolean example) {
}

if (BanInfoWS.getInstance().isRunning() && FarmHelperConfig.banwaveCheckerEnabled && BanInfoWS.getInstance().isConnected()) {
tempLines.add("Staff bans in the last " + BanInfoWS.getInstance().getMinutes() + " minutes: " + BanInfoWS.getInstance().getStaffBans());
tempLines.add("Bans in the last 15 minutes");
tempLines.add("detected by FarmHelper: " + BanInfoWS.getInstance().getBansByMod());
tempLines.add("Ban stats from the last " + BanInfoWS.getInstance().getMinutes() + " minutes");
tempLines.add("Staff bans: " + BanInfoWS.getInstance().getStaffBans());
tempLines.add("Detected by FarmHelper: " + BanInfoWS.getInstance().getBansByMod());
} else if (!BanInfoWS.getInstance().isConnected() && FarmHelperConfig.banwaveCheckerEnabled) {
tempLines.add("Connecting to the analytics server...");
}
Expand All @@ -71,17 +73,21 @@ private String centerText(String text, float scale) {

private String centerText(String text, float scale, List<String> lines) {
if (lines == null || lines.isEmpty()) return text;
float maxTextLength = getLineWidth(text, scale);
float maxLongestLine = getWidth(scale, false, lines);
int difference = (int) (((maxLongestLine - maxTextLength) / 3.5f) / (2 * scale)) - 1;
return (difference > 0) ? new String(new char[difference]).replace("\0", " ") + text : text;
float width = getWidth(scale, lines);
float lineWidth = getLineWidth(text, scale);
int spaces = (int) ((width - lineWidth) / (scale * 4));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < spaces / 2; i++) {
builder.append(" ");
}
return builder + text;
}

protected float getWidth(float scale, boolean example, List<String> lines) {
protected float getWidth(float scale, List<String> lines) {
if (lines == null) return 0;
float width = 0;
for (String line : lines) {
width = Math.max(width, getLineWidth(line, scale));
width = Math.max(width, getLineWidth(StringUtils.stripControlCodes(line), scale));
}
return width;
}
Expand All @@ -92,7 +98,7 @@ public String getStatusString() {
} else if (FailsafeManager.getInstance().getRestartMacroAfterFailsafeDelay().isScheduled()) {
return "§l§6Restarting after failsafe in " + LogUtils.formatTime(FailsafeManager.getInstance().getRestartMacroAfterFailsafeDelay().getRemainingTime()) + "§r";
} else if (!MacroHandler.getInstance().isMacroToggled()) {
return "Idling";
return (EnumChatFormatting.AQUA + "Idling");
} else if (Scheduler.getInstance().isRunning()) {
return Scheduler.getInstance().getStatusString();
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void onTick() {
if (rotated && !LagDetector.getInstance().isLagging() && mc.thePlayer.onGround) {
LogUtils.sendDebug("Rotated after warping.");
rewarpState = RewarpState.POST_REWARP;
Multithreading.schedule(() -> rewarpState = RewarpState.NONE, 1000, TimeUnit.MILLISECONDS);
Multithreading.schedule(() -> rewarpState = RewarpState.NONE, 600, TimeUnit.MILLISECONDS);
rewarpDelay.schedule(FarmHelperConfig.getRandomTimeBetweenChangingRows());
return;
} else if (rotated && (LagDetector.getInstance().isLagging() || !mc.thePlayer.onGround)) {
Expand Down Expand Up @@ -304,9 +304,9 @@ private void checkForTeleport() {
if (!mc.thePlayer.capabilities.isFlying && !mc.thePlayer.onGround) {
return;
} else if (mc.thePlayer.capabilities.isFlying && !mc.thePlayer.onGround) {
if (!mc.thePlayer.onGround && !mc.gameSettings.keyBindSneak.isKeyDown()) {
if (!mc.gameSettings.keyBindSneak.isKeyDown()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindSneak);
Multithreading.schedule(() -> KeyBindUtils.stopMovement(), (long) (450 + Math.random() * 600), TimeUnit.MILLISECONDS);
Multithreading.schedule(() -> KeyBindUtils.stopMovement(), (long) (350 + Math.random() * 300), TimeUnit.MILLISECONDS);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void updateState() {
).easeOutBack(true)
);
}
KeyBindUtils.stopMovement();
KeyBindUtils.releaseAllExcept(FarmHelperConfig.holdLeftClickWhenChangingRow ? mc.gameSettings.keyBindAttack : null);
setLayerY(mc.thePlayer.getPosition().getY());
changeState(State.NONE);
} else {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/util/KeyBindUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ private static void realSetKeyBindState(KeyBinding key, boolean pressed) {
if (pressed) {
if (!key.isKeyDown()) {
KeyBinding.onTick(key.getKeyCode());
KeyBinding.setKeyBindState(key.getKeyCode(), true);
}
KeyBinding.setKeyBindState(key.getKeyCode(), true);

} else {
KeyBinding.setKeyBindState(key.getKeyCode(), false);
if (key.isKeyDown()) {
KeyBinding.setKeyBindState(key.getKeyCode(), false);
}
}

}

public static void stopMovement() {
Expand Down Expand Up @@ -108,14 +108,15 @@ public static void holdThese(KeyBinding... keyBinding) {

public static void releaseAllExcept(KeyBinding... keyBinding) {
for (KeyBinding key : allKeys) {
if (key != null && !contains(keyBinding, key))
if (key != null && !contains(keyBinding, key) && key.isKeyDown()) {
realSetKeyBindState(key, false);
}
}
}

public static boolean contains(KeyBinding[] keyBinding, KeyBinding key) {
for (KeyBinding keyBind : keyBinding) {
if (keyBind == key)
if (keyBind != null && keyBind.getKeyCode() == key.getKeyCode())
return true;
}
return false;
Expand Down

0 comments on commit b0e8eca

Please sign in to comment.