Skip to content

Commit

Permalink
# CRITICAL FAILSAFE UPDATE
Browse files Browse the repository at this point in the history
= Dirt Check - Fixed single line mistake
= Leave Timer - won't cancel every failsafe for some reason lol
= Possible fix for Visitors Macro
  • Loading branch information
May2Beez committed Jan 12, 2024
1 parent 67abd7b commit 9a4b600
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 29 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.1-pre8
version=2.4.1-pre9
shouldRelease=true
30 changes: 24 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/failsafe/Failsafe.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jelly.farmhelperv2.failsafe;

import com.jelly.farmhelperv2.event.BlockChangeEvent;
import com.jelly.farmhelperv2.event.ReceivePacketEvent;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
Expand All @@ -9,28 +10,45 @@

public abstract class Failsafe {
public final Minecraft mc = Minecraft.getMinecraft();

public abstract int getPriority();

public abstract FailsafeManager.EmergencyType getType();

public abstract boolean shouldSendNotification();

public abstract boolean shouldPlaySound();

public abstract boolean shouldTagEveryone();

public abstract boolean shouldAltTab();

public void onReceivedPacketDetection(ReceivePacketEvent event) {}
public void onBlockChange(BlockChangeEvent event) {
}

public void onReceivedPacketDetection(ReceivePacketEvent event) {
}

public void onTickDetection(TickEvent.ClientTickEvent event) {}
public void onTickDetection(TickEvent.ClientTickEvent event) {
}

public void onChatDetection(ClientChatReceivedEvent event) {}
public void onChatDetection(ClientChatReceivedEvent event) {
}

public void onWorldUnloadDetection(WorldEvent.Unload event) {}
public void onWorldUnloadDetection(WorldEvent.Unload event) {
}

public void onDisconnectDetection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {}
public void onDisconnectDetection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
}

public abstract void duringFailsafeTrigger();

public abstract void endOfFailsafeTrigger();

private void possibleDetectionOfCheck() {
FailsafeManager.getInstance().possibleDetection(this);
}
public void resetStates() {}

public void resetStates() {
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/failsafe/FailsafeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cc.polyfrost.oneconfig.utils.Multithreading;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.event.BlockChangeEvent;
import com.jelly.farmhelperv2.event.ReceivePacketEvent;
import com.jelly.farmhelperv2.failsafe.impl.*;
import com.jelly.farmhelperv2.feature.FeatureManager;
Expand Down Expand Up @@ -130,6 +131,16 @@ public void resetAfterMacroDisable() {
restartMacroAfterFailsafeDelay.reset();
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockChange(BlockChangeEvent event) {
if (mc.thePlayer == null || mc.theWorld == null) return;
if (!MacroHandler.getInstance().isMacroToggled()) return;
if (triggeredFailsafe.isPresent()) return;
if (FeatureManager.getInstance().shouldIgnoreFalseCheck()) return;

failsafes.forEach(failsafe -> failsafe.onBlockChange(event));
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onReceivedPacketDetection(ReceivePacketEvent event) {
if (mc.thePlayer == null || mc.theWorld == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@
import com.jelly.farmhelperv2.feature.impl.MovRecPlayer;
import com.jelly.farmhelperv2.handler.BaritoneHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.util.AngleUtils;
import com.jelly.farmhelperv2.util.BlockUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.PlayerUtils;
import com.jelly.farmhelperv2.util.*;
import com.jelly.farmhelperv2.util.helper.FlyPathfinder;
import com.jelly.farmhelperv2.util.helper.Rotation;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.ArrayList;

public class DirtFailsafe extends Failsafe {
private static DirtFailsafe instance;

public static DirtFailsafe getInstance() {
if (instance == null) {
instance = new DirtFailsafe();
Expand Down Expand Up @@ -63,11 +60,11 @@ public boolean shouldAltTab() {
return FailsafeNotificationsPage.autoAltTabOnDirtFailsafe;
}

@SubscribeEvent
@Override
public void onBlockChange(BlockChangeEvent event) {
if (FailsafeManager.getInstance().firstCheckReturn()) return;
if (event.update.getBlock() == null) return;
if (!event.update.getBlock().equals(Blocks.dirt)) return;
if (event.update.getBlock() == null || event.update.getBlock().equals(Blocks.air) || CropUtils.isCrop(event.update.getBlock()))
return;

LogUtils.sendWarning("[Failsafe] Someone put a block on your garden! Block pos: " + event.pos);
dirtBlocks.add(event.pos);
Expand Down Expand Up @@ -250,6 +247,7 @@ public boolean hasDirtBlocks() {
private int maxReactions = 3;
private DirtCheckState dirtCheckState = DirtCheckState.NONE;
String randomMessage;

enum DirtCheckState {
NONE,
WAIT_BEFORE_START,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -71,8 +70,13 @@ public void onTickDetection(TickEvent.ClientTickEvent event) {
}
}

@SubscribeEvent
public void onChatMessageCheckLimbo(ClientChatReceivedEvent event) {
@Override
public void onChatDetection(ClientChatReceivedEvent event) {
chatOne(event);
chatTwo(event);
}

public void chatOne(ClientChatReceivedEvent event) {
if (FailsafeManager.getInstance().firstCheckReturn()) return;
if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()
&& FailsafeManager.getInstance().triggeredFailsafe.get().getType() != FailsafeManager.EmergencyType.WORLD_CHANGE_CHECK)
Expand All @@ -86,8 +90,7 @@ public void onChatMessageCheckLimbo(ClientChatReceivedEvent event) {
}
}

@Override
public void onChatDetection(ClientChatReceivedEvent event) {
public void chatTwo(ClientChatReceivedEvent event) {
if (event.type != 0) return;
if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()
&& FailsafeManager.getInstance().triggeredFailsafe.get().getType() != FailsafeManager.EmergencyType.WORLD_CHANGE_CHECK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public boolean shouldIgnoreFalseCheck() {
if (AutoReconnect.getInstance().isRunning() && !AutoReconnect.getInstance().shouldCheckForFailsafes()) {
return true;
}
if (LeaveTimer.getInstance().isRunning() && !LeaveTimer.getInstance().shouldCheckForFailsafes()) {
return true;
}
if (PestsDestroyer.getInstance().isRunning() && !PestsDestroyer.getInstance().shouldCheckForFailsafes()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.message.BasicHeader;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.enums.ReadyState;
Expand Down Expand Up @@ -108,8 +107,7 @@ public BanInfoWS() {
.setConnectionRequestTimeout(5000)
.setSocketTimeout(5000)
.build();
StandardHttpRequestRetryHandler retryHandler = new StandardHttpRequestRetryHandler(3, true);
this.httpClient = HttpClientBuilder.create().setRetryHandler(retryHandler).setDefaultRequestConfig(requestConfig).build();
this.httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
}

public static BanInfoWS getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public void start() {
rejectVisitor = false;
if (manuallyStarted || forceStart) {
setMainState(MainState.TRAVEL);
setTravelState(TravelState.ROTATE_TO_CLOSEST);
if (isInBarn())
setTravelState(TravelState.ROTATE_TO_CLOSEST);
else
setTravelState(TravelState.NONE);
}
if (forceStart) {
tries++;
Expand Down Expand Up @@ -401,7 +404,7 @@ private void onTravelState() {
delayClock.schedule((long) (1_000 + Math.random() * 500));
break;
case WAIT_FOR_TP:
if (mc.thePlayer.getPosition().equals(positionBeforeTp) || PlayerUtils.isPlayerSuffocating()) {
if (mc.thePlayer.getDistanceSqToCenter(positionBeforeTp) < 3 || PlayerUtils.isPlayerSuffocating()) {
LogUtils.sendDebug("[Visitors Macro] Waiting for teleportation...");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public abstract class MixinFMLHandshakeMessage {
@Inject(method = "<init>(Ljava/util/List;)V", at = @At("RETURN"), remap = false)
private void init(List<ModContainer> modList, CallbackInfo ci) {
if (Minecraft.getMinecraft().isIntegratedServerRunning()) return;
modTags.keySet().removeIf(c -> !c.matches("FML|Forge|mcp"));
modTags.keySet().removeIf(s -> s.contains("farmhelper"));
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/util/CropUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ public static void updateCocoaBeansHitbox(IBlockState blockState) {
}
}
}

public static boolean isCrop(Block block) {
return block instanceof BlockCrops || block instanceof BlockPotato || block instanceof BlockCarrot || block instanceof BlockNetherWart || block instanceof BlockCocoa || block instanceof BlockCactus || block instanceof BlockReed;
}
}

0 comments on commit 9a4b600

Please sign in to comment.