From fc444fcbd67e147c5146a37997d86612b517c4c8 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Tue, 13 Sep 2022 19:25:00 +0800 Subject: [PATCH] Supports setting thresholds --- MinecraftClient/ChatBots/AutoFishing.cs | 55 +++++++++++-------- .../Resources/config/MinecraftClient.ini | 12 ++-- MinecraftClient/Settings.cs | 20 ++++--- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/MinecraftClient/ChatBots/AutoFishing.cs b/MinecraftClient/ChatBots/AutoFishing.cs index 775f74a9..55637ec6 100644 --- a/MinecraftClient/ChatBots/AutoFishing.cs +++ b/MinecraftClient/ChatBots/AutoFishing.cs @@ -104,7 +104,7 @@ namespace MinecraftClient.ChatBots break; case FishingState.WaitingToCast: if (AutoEat.Eating) - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); + counter = (int)(Settings.AutoFishing_CastDelay * 10); else if (--counter < 0) state = FishingState.CastingRod; break; @@ -120,7 +120,7 @@ namespace MinecraftClient.ChatBots castTimeout *= 2; // Exponential backoff LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.cast_timeout", castTimeout / 10.0)); - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); + counter = (int)(Settings.AutoFishing_CastDelay * 10); state = FishingState.WaitingToCast; } break; @@ -129,7 +129,7 @@ namespace MinecraftClient.ChatBots { LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.fishing_timeout")); - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); + counter = (int)(Settings.AutoFishing_CastDelay * 10); state = FishingState.WaitingToCast; } break; @@ -152,7 +152,7 @@ namespace MinecraftClient.ChatBots } else { - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); + counter = (int)(Settings.AutoFishing_CastDelay * 10); state = FishingState.DurabilityCheck; goto case FishingState.DurabilityCheck; } @@ -171,7 +171,7 @@ namespace MinecraftClient.ChatBots case FishingState.DurabilityCheck: if (DurabilityCheck()) { - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); + counter = (int)(Settings.AutoFishing_CastDelay * 10); state = FishingState.WaitingToCast; } break; @@ -185,6 +185,9 @@ namespace MinecraftClient.ChatBots { if (entity.Type == EntityType.FishingBobber && entity.ObjectData == GetPlayerEntityID()) { + if (Settings.AutoFishing_LogFishingBobber) + LogToConsole(string.Format("FishingBobber spawn at {0}, distance = {1:0.00}", entity.Location, GetCurrentLocation().Distance(entity.Location))); + LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.throw")); lock (stateLock) { @@ -201,18 +204,24 @@ namespace MinecraftClient.ChatBots public override void OnEntityDespawn(Entity entity) { - if (isFishing && entity.Type == EntityType.FishingBobber && entity.ID == fishingBobber!.ID) + if (entity.Type == EntityType.FishingBobber && entity.ID == fishingBobber!.ID) { - isFishing = false; + if (Settings.AutoFishing_LogFishingBobber) + LogToConsole(string.Format("FishingBobber despawn at {0}", entity.Location)); - if (Settings.AutoFishing_Antidespawn) + if (isFishing) { - LogToConsoleTranslated("bot.autoFish.despawn"); + isFishing = false; - lock (stateLock) + if (Settings.AutoFishing_Antidespawn) { - counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); - state = FishingState.WaitingToCast; + LogToConsoleTranslated("bot.autoFish.despawn"); + + lock (stateLock) + { + counter = (int)(Settings.AutoFishing_CastDelay * 10); + state = FishingState.WaitingToCast; + } } } } @@ -228,19 +237,19 @@ namespace MinecraftClient.ChatBots double Dz = LastPos.Z - Pos.Z; LastPos = Pos; - // check if fishing hook is stationary - if (Dx == 0 && Dz == 0) + if (Settings.AutoFishing_LogFishingBobber) + LogToConsole(string.Format("FishingBobber {0} Dx={1:0.000000} Dy={2:0.000000} Dz={3:0.000000}", Pos, Dx, Math.Abs(Dy), Dz)); + + if (Math.Abs(Dx) < Math.Abs(Settings.AutoFishing_StationaryThreshold) && + Math.Abs(Dz) < Math.Abs(Settings.AutoFishing_StationaryThreshold) && + Math.Abs(Dy) > Math.Abs(Settings.AutoFishing_HookThreshold)) { - if (Math.Abs(Dy) > Settings.AutoFishing_FishingHookThreshold) + // prevent triggering multiple time + if ((DateTime.Now - CaughtTime).TotalSeconds > 1) { - // caught - // prevent triggering multiple time - if ((DateTime.Now - CaughtTime).TotalSeconds > 1) - { - isFishing = false; - CaughtTime = DateTime.Now; - OnCaughtFish(); - } + isFishing = false; + CaughtTime = DateTime.Now; + OnCaughtFish(); } } } diff --git a/MinecraftClient/Resources/config/MinecraftClient.ini b/MinecraftClient/Resources/config/MinecraftClient.ini index caa957b8..634004f8 100644 --- a/MinecraftClient/Resources/config/MinecraftClient.ini +++ b/MinecraftClient/Resources/config/MinecraftClient.ini @@ -209,17 +209,19 @@ enabled=false antidespawn=false main_hand=true # Use the main hand or the second hand to hold the rod. auto_start=true # Whether to start fishing automatically after entering a world. +cast_delay=0.4 # How soon to re-cast after successful fishing. fishing_delay=3.0 # How long after entering the game to start fishing (seconds). fishing_timeout=300.0 # Fishing timeout (seconds). Timeout will trigger a re-cast. -fishing_hook_threshold=0.2 # Fish hooks moving on the Y-axis above this threshold will be considered to have caught a fish. -fishing_cast_delay=0.4 # How soon to re-cast after successful fishing. durability_limit=2 # Will not use rods with less durability than this (full durability is 64). Set to zero to disable this feature. auto_rod_switch=true # Switch to a new rod from inventory after the current rod is unavailable. +stationary_threshold=0.001 # Hooks moving in the X and Z axes below this threshold will be considered stationary. +hook_threshold=0.2 # A stationary hook moving on the Y-axis above this threshold will be considered to have caught a fish. +log_fishing_bobber=false # For debugging purposes, you can use this log to adjust the two thresholds mentioned above. location= # Some plugins do not allow the player to fish in one place. This allows the player to change position/angle after each fish caught. # Floating point numbers can be used for both coordinates and angles. Leave blank to disable this function. - # Change the angle only (recommended): location=yaw_1,pitch_1;yaw_2,pitch_2;...;yaw_n,pitch_n - # Change position only: location=x1,y1,z1;x2,y2,z2;...;xn,yn,zn - # Change both angle and position: location=x1,y1,z1,yaw_1,pitch_1;x2,y2,z2,yaw_2,pitch_2;...;xn,yn,zn,yaw_n,pitch_n + # Change the angle only (recommended): location=yaw_1, pitch_1; yaw_2, pitch_2; ...; yaw_n, pitch_n + # Change position only: location=x1, y1, z1; x2, y2, z2; ...; xn, yn, zn + # Change both angle and position: location=x1, y1, z1, yaw_1, pitch_1; x2, y2, z2, yaw_2, pitch_2; ... ;xn, yn, zn, yaw_n, pitch_n [AutoEat] # Automatically eat food when your Hunger value is low diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index da17ce82..254f7c31 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -205,12 +205,14 @@ namespace MinecraftClient public static bool AutoFishing_Antidespawn = false; public static bool AutoFishing_Mainhand = true; public static bool AutoFishing_AutoStart = true; - public static double AutoFishing_FishingDelay = 3.0; - public static double AutoFishing_FishingTimeout = 600.0; - public static double AutoFishing_FishingHookThreshold = 0.2; - public static double AutoFishing_FishingCastDelay = 0.4; + public static double AutoFishing_CastDelay = 0.4; + public static double AutoFishing_FishingDelay = 3.0; + public static double AutoFishing_FishingTimeout = 300.0; public static double AutoFishing_DurabilityLimit = 2; public static bool AutoFishing_AutoRodSwitch = true; + public static double AutoFishing_StationaryThreshold = 0.001; + public static double AutoFishing_HookThreshold = 0.2; + public static bool AutoFishing_LogFishingBobber = false; public static double[,]? AutoFishing_Location = null; //Auto Eating @@ -722,14 +724,16 @@ namespace MinecraftClient case "antidespawn": AutoFishing_Antidespawn = str2bool(argValue); return true; case "main_hand": AutoFishing_Mainhand = str2bool(argValue); return true; case "auto_start": AutoFishing_AutoStart = str2bool(argValue); return true; + case "cast_delay": AutoFishing_CastDelay = str2double(argValue); return true; case "fishing_delay": AutoFishing_FishingDelay = str2double(argValue); return true; case "fishing_timeout": AutoFishing_FishingTimeout = str2double(argValue); return true; - case "fishing_hook_threshold": AutoFishing_FishingHookThreshold = str2double(argValue); return true; - case "fishing_cast_delay": AutoFishing_FishingCastDelay = str2double(argValue); return true; case "durability_limit": AutoFishing_DurabilityLimit = str2int(argValue); return true; - case "auto_rod_switch": AutoFishing_AutoRodSwitch = str2bool(argValue); return true; + case "auto_rod_switch": AutoFishing_AutoRodSwitch = str2bool(argValue); return true; + case "stationary_threshold": AutoFishing_StationaryThreshold = str2double(argValue); return true; + case "hook_threshold": AutoFishing_HookThreshold = str2double(argValue); return true; + case "log_fishing_bobber": AutoFishing_LogFishingBobber = str2bool(argValue); return true; case "location": AutoFishing_Location = str2locationList(argValue); return true; - } + } break; case Section.AutoEat: