Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 110f7f7

Browse files
authored
Merge pull request #312 from mqtze/feature/custom-failsafe-recordings
Added custom failsafe recordings support
2 parents 308b591 + da83e0a commit 110f7f7

File tree

3 files changed

+97
-8
lines changed

3 files changed

+97
-8
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
44
mcVersion=1.8.9
55
modid=farmhelperv2
66
modName=FarmHelper
7-
version=2.9.6-pre1
7+
version=2.9.7-pre1
88
shouldRelease=true

src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,69 @@ public class FarmHelperConfig extends Config {
526526
min = 5, max = 15)
527527
public static float minBpsThreshold = 10f;
528528

529+
// Custom Reactions
530+
@Info(
531+
text = "You need to place the .movement files in .minecraft/farmhelper/movrec",
532+
type = InfoType.WARNING,
533+
category = FAILSAFE,
534+
subcategory = "Custom Reactions",
535+
size = 2
536+
)
537+
public static boolean customReactionsWarning1;
538+
539+
@Info(
540+
text = "It will fall back to the default recordings if the folder is missing or there are no files in it.",
541+
type = InfoType.WARNING,
542+
category = FAILSAFE,
543+
subcategory = "Custom Reactions",
544+
size = 2
545+
)
546+
public static boolean customReactionsWarning2;
547+
548+
@Info(
549+
text = "You need to restart the game after changing the files.",
550+
type = InfoType.WARNING,
551+
category = FAILSAFE,
552+
subcategory = "Custom Reactions",
553+
size = 2
554+
)
555+
public static boolean customReactionsWarning3;
556+
557+
@Info(
558+
text = "You need to provide files for each check.",
559+
type = InfoType.WARNING,
560+
category = FAILSAFE,
561+
subcategory = "Custom Reactions",
562+
size = 2
563+
)
564+
public static boolean customReactionsWarning4;
565+
566+
@Info(
567+
text = "Default recordings at: https://github.com/JellyLabScripts/FarmHelper/tree/master/src/main/resources/farmhelper/movrec",
568+
type = InfoType.WARNING,
569+
category = FAILSAFE,
570+
subcategory = "Custom Reactions",
571+
size = 2
572+
)
573+
public static boolean customReactionsWarning5;
574+
575+
@Switch(name = "Enable Custom Reactions", category = FAILSAFE,
576+
subcategory = "Custom Reactions",
577+
description = "Enable custom failsafe reactions"
578+
)
579+
public static boolean enableCustomReactions = false;
580+
581+
/*
582+
@Info(
583+
text = "If you want to use your own WAV file, rename it to 'farmhelper_sound.wav' and put it in your Minecraft directory.",
584+
type = InfoType.WARNING,
585+
category = FAILSAFE,
586+
subcategory = "Failsafe Trigger Sound",
587+
size = 2
588+
)
589+
public static boolean customFailsafeSoundWarning;
590+
*/
591+
529592
// Failsafe Testing
530593
@Button(name = "Test Failsafe", category = FAILSAFE, subcategory = "Testing",
531594
description = "Simulate a failsafe trigger",

src/main/java/com/jelly/farmhelperv2/feature/impl/MovRecPlayer.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jelly.farmhelperv2.feature.impl;
22

33
import com.jelly.farmhelperv2.FarmHelper;
4+
import com.jelly.farmhelperv2.config.FarmHelperConfig;
45
import com.jelly.farmhelperv2.failsafe.FailsafeManager;
56
import com.jelly.farmhelperv2.feature.IFeature;
67
import com.jelly.farmhelperv2.handler.MacroHandler;
@@ -18,10 +19,7 @@
1819
import org.jetbrains.annotations.NotNull;
1920

2021
import java.awt.*;
21-
import java.io.BufferedReader;
22-
import java.io.IOException;
23-
import java.io.InputStream;
24-
import java.io.InputStreamReader;
22+
import java.io.*;
2523
import java.net.URI;
2624
import java.net.URISyntaxException;
2725
import java.net.URL;
@@ -63,9 +61,31 @@ public static MovRecPlayer getInstance() {
6361
}
6462

6563
public MovRecPlayer() {
66-
List<String> resourceFiles;
64+
List<String> resourceFiles = new ArrayList<>();
6765
try {
68-
resourceFiles = getResourceFiles("/farmhelper/movrec");
66+
if (FarmHelperConfig.enableCustomReactions) {
67+
File userFolder = new File(Minecraft.getMinecraft().mcDataDir + "/farmhelper/movrec");
68+
if (!userFolder.exists()) {
69+
userFolder.mkdirs();
70+
FailsafeUtils.getInstance().sendNotification("No user recordings found. Created folder at: " + userFolder.getAbsolutePath(), TrayIcon.MessageType.WARNING);
71+
LogUtils.sendWarning("No user recordings found. Created folder at: " + userFolder.getAbsolutePath());
72+
}
73+
74+
for (File file : Objects.requireNonNull(userFolder.listFiles())) {
75+
if (file.isFile() && file.getName().endsWith(".movement")) {
76+
resourceFiles.add(file.getAbsolutePath());
77+
}
78+
}
79+
80+
if (resourceFiles.isEmpty()) {
81+
FailsafeUtils.getInstance().sendNotification("No user recordings found. Falling back to default recordings.", TrayIcon.MessageType.WARNING);
82+
LogUtils.sendError("No user recordings found. Falling back to default recordings.");
83+
resourceFiles = getResourceFiles("/farmhelper/movrec");
84+
FarmHelperConfig.enableCustomReactions = false;
85+
}
86+
} else {
87+
resourceFiles = getResourceFiles("/farmhelper/movrec");
88+
}
6989
if (resourceFiles.isEmpty()) {
7090
FailsafeUtils.getInstance().sendNotification("Resource folder not found! Report this to #bug-reports!", TrayIcon.MessageType.WARNING);
7191
LogUtils.sendError("Resource folder not found! Report this to #bug-reports!");
@@ -78,7 +98,13 @@ public MovRecPlayer() {
7898
if (file.contains("/build/classes/")) {
7999
file = file.split("/build/classes/java/main")[1];
80100
}
81-
InputStream inputStream = FarmHelper.class.getResourceAsStream(file);
101+
InputStream inputStream;
102+
103+
if (FarmHelperConfig.enableCustomReactions) {
104+
inputStream = new FileInputStream(file);
105+
} else {
106+
inputStream = FarmHelper.class.getResourceAsStream(file);
107+
}
82108

83109
if (inputStream != null) {
84110
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

0 commit comments

Comments
 (0)