From b949db57cf7cd749350bcdb693d564eebeb91cd0 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Mon, 17 Oct 2022 13:50:56 +0800 Subject: [PATCH] Support control by command (/fish) --- MinecraftClient/ChatBots/AutoFishing.cs | 57 +++++++++++++++++++++ MinecraftClient/Program.cs | 4 +- MinecraftClient/Resources/lang/en.ini | 9 +++- MinecraftClient/Resources/lang/zh-Hans.ini | Bin 74534 -> 75130 bytes MinecraftClient/Resources/lang/zh-Hant.ini | Bin 74614 -> 75210 bytes 5 files changed, 67 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/ChatBots/AutoFishing.cs b/MinecraftClient/ChatBots/AutoFishing.cs index 609ced3b..d6015d5f 100644 --- a/MinecraftClient/ChatBots/AutoFishing.cs +++ b/MinecraftClient/ChatBots/AutoFishing.cs @@ -173,6 +173,43 @@ namespace MinecraftClient.ChatBots inventoryEnabled = GetInventoryEnabled(); if (!inventoryEnabled) LogToConsoleTranslated("bot.autoFish.no_inv_handle"); + + RegisterChatBotCommand("fish", Translations.Get("bot.autoFish.cmd"), GetHelp(), CommandHandler); + } + + public string CommandHandler(string cmd, string[] args) + { + if (args.Length > 0) + { + switch (args[0]) + { + case "start": + isFishing = false; + lock (stateLock) + { + isFishing = false; + counter = 0; + state = FishingState.StartMove; + } + return Translations.Get("bot.autoFish.start"); + case "stop": + isFishing = false; + lock (stateLock) + { + isFishing = false; + if (state == FishingState.WaitingFishToBite) + UseFishRod(); + state = FishingState.Stopping; + } + StopFishing(); + return Translations.Get("bot.autoFish.stop"); + case "help": + return GetCommandHelp(args.Length >= 2 ? args[1] : ""); + default: + return GetHelp(); + } + } + else return GetHelp(); } private void StartFishing() @@ -184,6 +221,7 @@ namespace MinecraftClient.ChatBots LogToConsole(Translations.Get("bot.autoFish.start", delay)); lock (stateLock) { + isFishing = false; counter = Settings.DoubleToTick(delay); state = FishingState.StartMove; } @@ -202,6 +240,7 @@ namespace MinecraftClient.ChatBots isFishing = false; lock (stateLock) { + isFishing = false; state = FishingState.Stopping; } } @@ -512,5 +551,23 @@ namespace MinecraftClient.ChatBots return false; } } + + private static string GetHelp() + { + return Translations.Get("bot.autoFish.available_cmd", "start, stop, help"); + } + + private string GetCommandHelp(string cmd) + { + return cmd.ToLower() switch + { +#pragma warning disable format // @formatter:off + "start" => Translations.Get("bot.autoFish.help.start"), + "stop" => Translations.Get("bot.autoFish.help.stop"), + "help" => Translations.Get("bot.autoFish.help.help"), + _ => GetHelp(), +#pragma warning restore format // @formatter:on + }; + } } } diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 4c8c280e..0eabdae0 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -197,7 +197,7 @@ namespace MinecraftClient if (Settings.CheckUpdate(Config.Head.CurrentVersion, Config.Head.LatestVersion)) { needPromptUpdate = false; - ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.has_update", Settings.GithubLatestReleaseUrl)); + ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.has_update", Settings.GithubReleaseUrl)); } //Other command-line arguments @@ -328,7 +328,7 @@ namespace MinecraftClient string latestVersion = string.Format("GitHub build {0}, built on {1}-{2}-{3}", run, year, month, day); if (needPromptUpdate) if (Settings.CheckUpdate(Config.Head.CurrentVersion, Config.Head.LatestVersion)) - ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.has_update", Settings.GithubLatestReleaseUrl)); + ConsoleIO.WriteLineFormatted(Translations.TryGet("mcc.has_update", Settings.GithubReleaseUrl)); if (latestVersion != Config.Head.LatestVersion) { Config.Head.LatestVersion = latestVersion; diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index 1ed90b50..63a7bb82 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -597,6 +597,13 @@ bot.autoFish.fishing_timeout=Fishing timeout, will soon re-cast. bot.autoFish.cast_timeout=Casting timeout and will soon retry. (Timeout increased to {0:0.0} sec). bot.autoFish.update_lookat=Update yaw = {0:0.00}, pitch = {1:0.00}. bot.autoFish.switch=Switch to the rod in slot {0}, durability {1}/64. +bot.autoFish.cmd=Auto-Fishing ChatBot command +bot.autoFish.available_cmd=Available commands: {0}. Use /fish help for more information. +bot.autoFish.start=Start auto-fishing. +bot.autoFish.stop=Stop auto-fishing. +bot.autoFish.help.start=Start auto-fishing. +bot.autoFish.help.stop=Stop auto-fishing. +bot.autoFish.help.help=Get the command description. Usage: /fish help # AutoRelog bot.autoRelog.launch=Launching with {0} reconnection attempts @@ -900,7 +907,7 @@ config.ChatBot.AutoDrop.Mode="include", "exclude" or "everything". Include: drop config.ChatBot.AutoEat=Automatically eat food when your Hunger value is low\n# You need to enable Inventory Handling to use this bot # ChatBot.AutoFishing -config.ChatBot.AutoFishing=Automatically catch fish using a fishing rod\n# Guide: https://mccteam.github.io/guide/chat-bots.html#auto-fishing\n# /!\ Make sure server rules allow automated farming before using this bot +config.ChatBot.AutoFishing=Automatically catch fish using a fishing rod\n# Guide: https://mccteam.github.io/guide/chat-bots.html#auto-fishing\n# You can use "/fish" to control the bot manually.\n# /!\ Make sure server rules allow automated farming before using this bot config.ChatBot.AutoFishing.Antidespawn=Keep it as false if you have not changed it before. config.ChatBot.AutoFishing.Mainhand=Use the mainhand or the offhand to hold the rod. config.ChatBot.AutoFishing.Auto_Start=Whether to start fishing automatically after entering a world. diff --git a/MinecraftClient/Resources/lang/zh-Hans.ini b/MinecraftClient/Resources/lang/zh-Hans.ini index 201ba051c3b01de6d647cb3a46403ef27ee9acc9..76f8c972652e237902e3db48ea2de21b6e788d01 100644 GIT binary patch delta 206 zcmZ2>jOEuUmJM?zO%|Id!3!L+%K?1=k z>C}Q7__0oW@_|l~&1)w8D>98?$YW4uP+&;#e;@qRuijsyREa^K0ctmc5<_js6Tj4S a@1zw$xBGoMmM5D9F&V^cU&+c?D+>T8(@|3Z delta 24 icmV+z0O$Yu$^@py1hAZvlf;P-v&xkIa<~2m0el^-nGD_l diff --git a/MinecraftClient/Resources/lang/zh-Hant.ini b/MinecraftClient/Resources/lang/zh-Hant.ini index ae5216d1f9c8204ce2f6014336b997fe3f450e35..b015b011a8cffe72bcd30fd87ad5f9a63ad3b451 100644 GIT binary patch delta 255 zcmex%jOEm6mJKH+O*U%~m|QT4OCXscmm!70mf=<7)u6`{qh?S3(XIuOn7k!UXtJHN z)Z~A4JnU%L~T1-Gv zHrzyrB-i9s4N~YjxF*XrN^oGPT+pe7WT*J#1C1<`KXeLgzA;In*ffSAk3pG1fg!>F xeehGidVh^lB?f&4s1q5K7-~bF__g_aCtVFPn&8v1JlQOW$slI?dsfDFSpZqqWAFd~ delta 32 ocmX?gn&sOumJKH+vGX!;F(@-AOm`Gy6y7wIuXwu)2V