Supports setting thresholds

This commit is contained in:
BruceChen 2022-09-13 19:25:00 +08:00
parent dac60200e0
commit fc444fcbd6
3 changed files with 51 additions and 36 deletions

View file

@ -104,7 +104,7 @@ namespace MinecraftClient.ChatBots
break; break;
case FishingState.WaitingToCast: case FishingState.WaitingToCast:
if (AutoEat.Eating) if (AutoEat.Eating)
counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); counter = (int)(Settings.AutoFishing_CastDelay * 10);
else if (--counter < 0) else if (--counter < 0)
state = FishingState.CastingRod; state = FishingState.CastingRod;
break; break;
@ -120,7 +120,7 @@ namespace MinecraftClient.ChatBots
castTimeout *= 2; // Exponential backoff castTimeout *= 2; // Exponential backoff
LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.cast_timeout", castTimeout / 10.0)); 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; state = FishingState.WaitingToCast;
} }
break; break;
@ -129,7 +129,7 @@ namespace MinecraftClient.ChatBots
{ {
LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.fishing_timeout")); LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.fishing_timeout"));
counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); counter = (int)(Settings.AutoFishing_CastDelay * 10);
state = FishingState.WaitingToCast; state = FishingState.WaitingToCast;
} }
break; break;
@ -152,7 +152,7 @@ namespace MinecraftClient.ChatBots
} }
else else
{ {
counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); counter = (int)(Settings.AutoFishing_CastDelay * 10);
state = FishingState.DurabilityCheck; state = FishingState.DurabilityCheck;
goto case FishingState.DurabilityCheck; goto case FishingState.DurabilityCheck;
} }
@ -171,7 +171,7 @@ namespace MinecraftClient.ChatBots
case FishingState.DurabilityCheck: case FishingState.DurabilityCheck:
if (DurabilityCheck()) if (DurabilityCheck())
{ {
counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); counter = (int)(Settings.AutoFishing_CastDelay * 10);
state = FishingState.WaitingToCast; state = FishingState.WaitingToCast;
} }
break; break;
@ -185,6 +185,9 @@ namespace MinecraftClient.ChatBots
{ {
if (entity.Type == EntityType.FishingBobber && entity.ObjectData == GetPlayerEntityID()) 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")); LogToConsole(GetTimestamp() + ": " + Translations.Get("bot.autoFish.throw"));
lock (stateLock) lock (stateLock)
{ {
@ -201,7 +204,12 @@ namespace MinecraftClient.ChatBots
public override void OnEntityDespawn(Entity entity) 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)
{
if (Settings.AutoFishing_LogFishingBobber)
LogToConsole(string.Format("FishingBobber despawn at {0}", entity.Location));
if (isFishing)
{ {
isFishing = false; isFishing = false;
@ -211,12 +219,13 @@ namespace MinecraftClient.ChatBots
lock (stateLock) lock (stateLock)
{ {
counter = (int)(Settings.AutoFishing_FishingCastDelay * 10); counter = (int)(Settings.AutoFishing_CastDelay * 10);
state = FishingState.WaitingToCast; state = FishingState.WaitingToCast;
} }
} }
} }
} }
}
public override void OnEntityMove(Entity entity) public override void OnEntityMove(Entity entity)
{ {
@ -228,12 +237,13 @@ namespace MinecraftClient.ChatBots
double Dz = LastPos.Z - Pos.Z; double Dz = LastPos.Z - Pos.Z;
LastPos = Pos; LastPos = Pos;
// check if fishing hook is stationary if (Settings.AutoFishing_LogFishingBobber)
if (Dx == 0 && Dz == 0) 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)
{
// caught
// prevent triggering multiple time // prevent triggering multiple time
if ((DateTime.Now - CaughtTime).TotalSeconds > 1) if ((DateTime.Now - CaughtTime).TotalSeconds > 1)
{ {
@ -244,7 +254,6 @@ namespace MinecraftClient.ChatBots
} }
} }
} }
}
public override void AfterGameJoined() public override void AfterGameJoined()
{ {

View file

@ -209,17 +209,19 @@ enabled=false
antidespawn=false antidespawn=false
main_hand=true # Use the main hand or the second hand to hold the rod. 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. 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_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_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. 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. 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. 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. # 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 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 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 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] [AutoEat]
# Automatically eat food when your Hunger value is low # Automatically eat food when your Hunger value is low

View file

@ -205,12 +205,14 @@ namespace MinecraftClient
public static bool AutoFishing_Antidespawn = false; public static bool AutoFishing_Antidespawn = false;
public static bool AutoFishing_Mainhand = true; public static bool AutoFishing_Mainhand = true;
public static bool AutoFishing_AutoStart = true; public static bool AutoFishing_AutoStart = true;
public static double AutoFishing_CastDelay = 0.4;
public static double AutoFishing_FishingDelay = 3.0; public static double AutoFishing_FishingDelay = 3.0;
public static double AutoFishing_FishingTimeout = 600.0; public static double AutoFishing_FishingTimeout = 300.0;
public static double AutoFishing_FishingHookThreshold = 0.2;
public static double AutoFishing_FishingCastDelay = 0.4;
public static double AutoFishing_DurabilityLimit = 2; public static double AutoFishing_DurabilityLimit = 2;
public static bool AutoFishing_AutoRodSwitch = true; 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; public static double[,]? AutoFishing_Location = null;
//Auto Eating //Auto Eating
@ -722,12 +724,14 @@ namespace MinecraftClient
case "antidespawn": AutoFishing_Antidespawn = str2bool(argValue); return true; case "antidespawn": AutoFishing_Antidespawn = str2bool(argValue); return true;
case "main_hand": AutoFishing_Mainhand = str2bool(argValue); return true; case "main_hand": AutoFishing_Mainhand = str2bool(argValue); return true;
case "auto_start": AutoFishing_AutoStart = 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_delay": AutoFishing_FishingDelay = str2double(argValue); return true;
case "fishing_timeout": AutoFishing_FishingTimeout = 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 "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; case "location": AutoFishing_Location = str2locationList(argValue); return true;
} }
break; break;