Skip to content

Commit

Permalink
feature: Reel in delay, close #14 and #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Wudji committed Jul 6, 2024
1 parent 09b30ef commit cc048c1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/main/java/troy/autofish/Autofish.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,20 @@ public void handleChat(GameMessageS2CPacket packet) {
}

public void catchFish() {
if(!modAutofish.getScheduler().isRecastQueued()) { //prevents double reels
if (client.player != null) {
detectOpenWater(client.player.fishHook);
if(!modAutofish.getScheduler().isRecastQueued()) { //prevents double reels
if (client.player != null) {
detectOpenWater(client.player.fishHook);
}
//queue actions
queueRodSwitch();
queueRecast();
modAutofish.getScheduler().scheduleAction(ActionType.REEL_IN, modAutofish.getConfig().getReelInDelay(), this::useRod);
}
//queue actions
queueRodSwitch();
queueRecast();

//reel in
useRod();
}
}

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

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

switchToFirstRod(client.player);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/troy/autofish/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Config {
@Expose boolean forceMPDetection = false;
@Expose long recastDelay = 1500;
@Expose long randomPercent = 50;
@Expose long reelInDelay = 1;
@Expose String clearLagRegex = "\\[ClearLag\\] Removed [0-9]+ Entities!";

public boolean isAutofishEnabled() {
Expand Down Expand Up @@ -83,6 +84,22 @@ public void setOpenWaterDetectEnabled(boolean openWaterDetectEnabled) {
isOpenWaterDetectEnabled = openWaterDetectEnabled;
}

public long getRandomPercent() {
return randomPercent;
}

public void setRandomPercent(long randomPercent) {
this.randomPercent = randomPercent;
}

public long getReelInDelay() {
return reelInDelay;
}

public void setReelInDelay(long reelInDelay) {
this.reelInDelay = reelInDelay;
}

/**
* @return true if anything was changed
*/
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/troy/autofish/gui/AutofishScreenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static Screen buildScreen(FabricModAutofish modAutofish, Screen parentScr
})
.build();
AbstractConfigListEntry randomDelaySlider = entryBuilder.startLongSlider(Text.translatable("options.autofish.random_delay.title"), config.getRandomDelay(), 0, 75)
.setDefaultValue(defaults.getRecastDelay())
.setDefaultValue(defaults.getRandomPercent())
.setTooltip(
Text.translatable("options.autofish.random_delay.tooltip_0"),
Text.translatable("options.autofish.random_delay.tooltip_1"),
Expand All @@ -167,6 +167,17 @@ public static Screen buildScreen(FabricModAutofish modAutofish, Screen parentScr
modAutofish.getConfig().setRandomDelay(newValue);
})
.build();
AbstractConfigListEntry reelInDelay = entryBuilder.startLongSlider(Text.translatable("options.autofish.reel_in_delay.title"), config.getReelInDelay(), 1, 2000)
.setDefaultValue(defaults.getReelInDelay())
.setTooltip(
Text.translatable("options.autofish.reel_in_delay.tooltip_0"),
Text.translatable("options.autofish.reel_in_delay.tooltip_1")
)
.setTextGetter(value -> Text.translatable("options.autofish.reel_in_delay.value", value))
.setSaveConsumer(newValue -> {
modAutofish.getConfig().setReelInDelay(newValue);
})
.build();

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

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/troy/autofish/scheduler/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum ActionType {
RECAST,
ROD_SWITCH,
REPEATING_ACTION
REPEATING_ACTION,
REEL_IN
}
7 changes: 6 additions & 1 deletion src/main/resources/assets/autofish/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"options.autofish.persistent.tooltip_3": "if needed.",
"options.autofish.persistent.tooltip_4": "This is useful for lag issues or when",
"options.autofish.persistent.tooltip_5": "fishing for long periods of time.",

"options.autofish.sound.title": "Use Sound Detection",
"options.autofish.sound.tooltip_0": "\u00A76Newer, more accurate detection based",
"options.autofish.sound.tooltip_1": "\u00A76on bobber sounds rather than the",
Expand Down Expand Up @@ -60,6 +60,11 @@
"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.reel_in_delay.title": "Reel in delay",
"options.autofish.reel_in_delay.value": "%d milliseconds",
"options.autofish.reel_in_delay.tooltip_0": "Add a delay for the reel-in when a fish bites the float.",
"options.autofish.reel_in_delay.tooltip_1": "Set this option to 1 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
9 changes: 7 additions & 2 deletions src/main/resources/assets/autofish/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"options.autofish.persistent.tooltip_3": "并在需要时重新投掷",
"options.autofish.persistent.tooltip_4": "这对于滞后问题或",
"options.autofish.persistent.tooltip_5": "长时间钓鱼非常有用",

"options.autofish.sound.title": "使用声音检测",
"options.autofish.sound.tooltip_0": "\u00A76基于浮标声音的更新",
"options.autofish.sound.tooltip_1": "\u00A76他将更准确的检测收杆时机",
Expand Down Expand Up @@ -68,6 +68,11 @@
"options.autofish.advanced.title": "高级选项",

"info.autofish.open_water_detection.fail": "§c[自动钓鱼] 您当前钓鱼的区域不是开放水域,无法获得宝藏!§0",
"info.autofish.open_water_detection.success": "§2[自动钓鱼] 您当前钓鱼的区域是开放水域!§0"
"info.autofish.open_water_detection.success": "§2[自动钓鱼] 您当前钓鱼的区域是开放水域!§0",

"options.autofish.reel_in_delay.title": "收杆延迟",
"options.autofish.reel_in_delay.value": "%d 毫秒",
"options.autofish.reel_in_delay.tooltip_0": "当鱼咬钩时,延迟一段时间收杆.",
"options.autofish.reel_in_delay.tooltip_1": "将此项设置为1以禁用此功能."

}

0 comments on commit cc048c1

Please sign in to comment.