Skip to content

Commit

Permalink
feature: Random Recast Delay
Browse files Browse the repository at this point in the history
Close #8 .
  • Loading branch information
Wudji committed Mar 20, 2024
1 parent e7e9e8b commit b9d7313
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version = 0.10.2-SNAPSHOT
mod_version = 1.0.0-fabric-1.20.4
maven_group = troy.autofish
archives_base_name = autofish
archives_base_name = xplus-autofish

# Fabric Properties
# check these on https://modmuss50.me/fabric.html or https://fabricmc.net/use
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/troy/autofish/Autofish.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void catchFish() {
}

public void queueRecast() {
modAutofish.getScheduler().scheduleAction(ActionType.RECAST, modAutofish.getConfig().getRecastDelay(), () -> {
modAutofish.getScheduler().scheduleAction(ActionType.RECAST, getRandomDelay(), () -> {
//State checks to ensure we can still fish once this runs
if(hookExists) return;
if(!isHoldingFishingRod()) return;
Expand All @@ -157,7 +157,7 @@ public void queueRecast() {
}

private void queueRodSwitch(){
modAutofish.getScheduler().scheduleAction(ActionType.ROD_SWITCH, modAutofish.getConfig().getRecastDelay() - 250, () -> {
modAutofish.getScheduler().scheduleAction(ActionType.ROD_SWITCH, (long) (getRandomDelay() * 0.83), () -> {
if(!modAutofish.getConfig().isMultiRod()) return;

switchToFirstRod(client.player);
Expand Down Expand Up @@ -287,4 +287,11 @@ private boolean shouldUseMPDetection(){
if(modAutofish.getConfig().isForceMPDetection()) return true;
return !client.isInSingleplayer();
}

private long getRandomDelay(){
return Math.random() >=0.5 ?
(long) (modAutofish.getConfig().getRecastDelay() * (1 - (Math.random() * modAutofish.getConfig().getRandomDelay() * 0.01))) :
(long) (modAutofish.getConfig().getRecastDelay() * (1 + (Math.random() * modAutofish.getConfig().getRandomDelay() * 0.01)));

}
}
8 changes: 8 additions & 0 deletions src/main/java/troy/autofish/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Config {
@Expose boolean useSoundDetection = false;
@Expose boolean forceMPDetection = false;
@Expose long recastDelay = 1500;
@Expose long randomPercent = 50;
@Expose String clearLagRegex = "\\[ClearLag\\] Removed [0-9]+ Entities!";

public boolean isAutofishEnabled() {
Expand Down Expand Up @@ -41,6 +42,10 @@ public long getRecastDelay() {
return recastDelay;
}

public long getRandomDelay(){
return randomPercent;
}

public String getClearLagRegex() {
return clearLagRegex;
}
Expand All @@ -66,6 +71,9 @@ public void setUseSoundDetection(boolean useSoundDetection) {
public void setRecastDelay(long recastDelay) {
this.recastDelay = recastDelay;
}
public void setRandomDelay(long randomPercent){
this.randomPercent = randomPercent;
}

public void setClearLagRegex(String clearLagRegex) {
this.clearLagRegex = clearLagRegex;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/troy/autofish/gui/AutofishScreenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ public static Screen buildScreen(FabricModAutofish modAutofish, Screen parentScr
modAutofish.getConfig().setRecastDelay(newValue);
})
.build();
AbstractConfigListEntry randomDelaySlider = entryBuilder.startLongSlider(Text.translatable("options.autofish.random_delay.title"), config.getRandomDelay(), 0, 75)
.setDefaultValue(defaults.getRecastDelay())
.setTooltip(
Text.translatable("options.autofish.random_delay.tooltip_0"),
Text.translatable("options.autofish.random_delay.tooltip_1"),
Text.translatable("options.autofish.random_delay.tooltip_2"),
Text.translatable("options.autofish.random_delay.tooltip_3")
)
.setTextGetter(value -> Text.translatable("options.autofish.random_delay.value", value))
.setSaveConsumer(newValue -> {
modAutofish.getConfig().setRandomDelay(newValue);
})
.build();

//ClearLag Regex
AbstractConfigListEntry clearLagRegexField = entryBuilder.startTextField(Text.translatable("options.autofish.clear_regex.title"), config.getClearLagRegex())
Expand Down Expand Up @@ -181,6 +194,7 @@ public static Screen buildScreen(FabricModAutofish modAutofish, Screen parentScr
subCatBuilderAdvanced.add(toggleSoundDetection);
subCatBuilderAdvanced.add(toggleForceMPDetection);
subCatBuilderAdvanced.add(recastDelaySlider);
subCatBuilderAdvanced.add(randomDelaySlider);
subCatBuilderAdvanced.add(clearLagRegexField);
subCatBuilderAdvanced.setExpanded(true);

Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/assets/autofish/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"key.autofish.open_gui": "Open Autofish GUI",
"options.autofish.title": "Autofish Settings",
"key.autofish.open_gui": "Open XPlus Autofish GUI",
"options.autofish.title": "XPlus Autofish Settings",

"options.autofish.toggle.on": "\u00A7aOn",
"options.autofish.toggle.off": "\u00A7eOff",
Expand Down Expand Up @@ -53,6 +53,13 @@
"options.autofish.recast_delay.tooltip_0": "Adjusts the delay between catching",
"options.autofish.recast_delay.tooltip_1": "a fish and recasting the rod.",

"options.autofish.random_delay.title": "Random Recast Delay Field",
"options.autofish.random_delay.value": "%d percent",
"options.autofish.random_delay.tooltip_0": "Add ±% randomness to the Recast Delay",
"options.autofish.random_delay.tooltip_1": "For example: Set this to 20% will make.",
"options.autofish.random_delay.tooltip_2": "a 1500ms delay fall in 1200-1800ms (1500ms ±20%).",
"options.autofish.random_delay.tooltip_3": "Set this to 0 to disable this function.",

"options.autofish.clear_regex.title": "ClearLag Chat Pattern",
"options.autofish.clear_regex.tooltip_0": "Recast the fishing rod when",
"options.autofish.clear_regex.tooltip_1": "this pattern is matched in chat.",
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/autofish/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
"options.autofish.recast_delay.tooltip_0": "调整收杆和重新投掷钓鱼竿之间的延迟",
"options.autofish.recast_delay.tooltip_1": "以毫秒 (ms) 为单位.",

"options.autofish.random_delay.title": "随机重新投掷延迟",
"options.autofish.random_delay.value": "百分之 %d",
"options.autofish.random_delay.tooltip_0": "为投掷钓鱼竿的延迟添加 ±% 的变化量",
"options.autofish.random_delay.tooltip_1": "例如: 当默认延迟为1500ms时将该选项设置为20%,",
"options.autofish.random_delay.tooltip_2": "会使重新投掷延迟落在1200-1800ms区间内 (1500ms ±20%).",
"options.autofish.random_delay.tooltip_3": "将该选项设置为0以禁用此功能",

"options.autofish.clear_regex.title": "启用持续模式",
"options.autofish.clear_regex.tooltip_0": "使用聊天栏正则表达式",
"options.autofish.clear_regex.tooltip_1": "来触发重新投掷钓鱼竿.",
Expand Down

0 comments on commit b9d7313

Please sign in to comment.