From a31b4a792b7386cb8a202168de348911be91a374 Mon Sep 17 00:00:00 2001 From: Milutinke Date: Mon, 17 Oct 2022 15:14:55 +0200 Subject: [PATCH] Improvements to the Bed, Blockinfo and Enchant commands. --- MinecraftClient/Commands/Bed.cs | 3 +++ MinecraftClient/Commands/BlockInfo.cs | 19 +++++++------ MinecraftClient/Commands/Enchant.cs | 19 +++++++++++++ MinecraftClient/Inventory/EnchantmentData.cs | 22 +++++++++++++++ MinecraftClient/McClient.cs | 28 ++++++++++++++++++++ MinecraftClient/Resources/lang/en.ini | 4 +++ MinecraftClient/Scripting/ChatBot.cs | 8 ++++++ 7 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 MinecraftClient/Inventory/EnchantmentData.cs diff --git a/MinecraftClient/Commands/Bed.cs b/MinecraftClient/Commands/Bed.cs index 4cedce82..ea2b4b1b 100644 --- a/MinecraftClient/Commands/Bed.cs +++ b/MinecraftClient/Commands/Bed.cs @@ -29,6 +29,9 @@ namespace MinecraftClient.Commands if (subcommand.Equals("sleep") || subcommand.Equals("s")) { + if (!handler.GetTerrainEnabled()) + return Translations.TryGet("error.terrain_not_enabled"); + if (args.Length == 2) { if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int radius)) diff --git a/MinecraftClient/Commands/BlockInfo.cs b/MinecraftClient/Commands/BlockInfo.cs index b4458d2b..36e2d723 100644 --- a/MinecraftClient/Commands/BlockInfo.cs +++ b/MinecraftClient/Commands/BlockInfo.cs @@ -10,8 +10,11 @@ namespace MinecraftClient.Commands public override string CmdUsage { get { return "blockinfo [-s]"; } } public override string CmdDesc { get { return "cmd.blockinfo.desc"; } } - public override string Run(McClient handler, string command, Dictionary? localVars) + public override string Run(McClient handler, string command, Dictionary localVars) { + if (!handler.GetTerrainEnabled()) + return Translations.TryGet("error.terrain_not_enabled"); + string[] args = GetArgs(command); if (args.Length < 3) @@ -24,7 +27,7 @@ namespace MinecraftClient.Commands Block block = handler.GetWorld().GetBlock(targetBlockLocation); - handler.Log.Info(Translations.TryGet("cmd.blockinfo.BlockType") + ": " + block.GetTypeString()); + handler.Log.Info(Translations.TryGet("cmd.blockinfo.BlockType") + ": " + block.Type); if (reportSurrounding) { @@ -38,14 +41,14 @@ namespace MinecraftClient.Commands Block blockZPositive = handler.GetWorld().GetBlock(new Location(targetBlockLocation.X, targetBlockLocation.Y, targetBlockLocation.Z + 1)); Block blockZNegative = handler.GetWorld().GetBlock(new Location(targetBlockLocation.X, targetBlockLocation.Y, targetBlockLocation.Z - 1)); - sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXPositive.GetTypeString()); - sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXNegative.GetTypeString()); + sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXPositive.Type); + sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXNegative.Type); sb.AppendLine(" "); - sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYPositive.GetTypeString()); - sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYNegative.GetTypeString()); + sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYPositive.Type); + sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYNegative.Type); sb.AppendLine(" "); - sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZPositive.GetTypeString()); - sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZNegative.GetTypeString()); + sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZPositive.Type); + sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZNegative.Type); handler.Log.Info(sb.ToString()); } diff --git a/MinecraftClient/Commands/Enchant.cs b/MinecraftClient/Commands/Enchant.cs index ab8200b2..a75317e2 100644 --- a/MinecraftClient/Commands/Enchant.cs +++ b/MinecraftClient/Commands/Enchant.cs @@ -12,6 +12,9 @@ namespace MinecraftClient.Commands public override string Run(McClient handler, string command, Dictionary? localVars) { + if (!handler.GetInventoryEnabled()) + return Translations.TryGet("error.inventoryhandling_not_enabled"); + if (HasArg(command)) { string slot = GetArg(command).ToLower().Trim(); @@ -57,6 +60,22 @@ namespace MinecraftClient.Commands if (lapisSlot.Count < 3) return Translations.TryGet("cmd.enchant.enchanting_no_lapis"); + EnchantmentData? enchantment = handler.GetLastEnchantments(); + + if (enchantment == null) + return Translations.TryGet("cmd.enchant.no_enchantments"); + + short requiredLevel = slotId switch + { + 0 => enchantment.TopEnchantmentLevelRequirement, + 1 => enchantment.MiddleEnchantmentLevelRequirement, + 2 => enchantment.BottomEnchantmentLevelRequirement, + _ => 9999 + }; + + if (handler.GetLevel() < requiredLevel) + return Translations.TryGet("cmd.enchant.no_levels", handler.GetLevel(), requiredLevel); + return handler.ClickContainerButton(enchantingTable.ID, slotId) ? Translations.TryGet("cmd.enchant.clicked") : Translations.TryGet("cmd.enchant.not_clicked"); } diff --git a/MinecraftClient/Inventory/EnchantmentData.cs b/MinecraftClient/Inventory/EnchantmentData.cs new file mode 100644 index 00000000..c42dd920 --- /dev/null +++ b/MinecraftClient/Inventory/EnchantmentData.cs @@ -0,0 +1,22 @@ +namespace MinecraftClient.Inventory +{ + public class EnchantmentData + { + public Enchantment TopEnchantment { get; set; } + public Enchantment MiddleEnchantment { get; set; } + public Enchantment BottomEnchantment { get; set; } + + // Seed for rendering Standard Galactic Language (symbols in the enchanting table) (Useful for poeple who use MCC for the protocol) + public short Seed { get; set; } + + /// Enchantment levels are the levels of enchantment (eg. I, II, III, IV, V) (eg. Smite IV, Power III, Knockback II ..) + public short TopEnchantmentLevel { get; set; } + public short MiddleEnchantmentLevel { get; set; } + public short BottomEnchantmentLevel { get; set; } + + /// Enchantment level requirements are the levels that player needs to have in order to enchant the item + public short TopEnchantmentLevelRequirement { get; set; } + public short MiddleEnchantmentLevelRequirement { get; set; } + public short BottomEnchantmentLevelRequirement { get; set; } + } +} diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index af7001ff..677cad72 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -77,6 +77,7 @@ namespace MinecraftClient private int respawnTicks = 0; private int gamemode = 0; private bool isSupportPreviewsChat; + private EnchantmentData? lastEnchantment = null; private int playerEntityID; @@ -1021,6 +1022,15 @@ namespace MinecraftClient return inventories; } + /// + /// Get all Entities + /// + /// Ladt Enchantments + public EnchantmentData? GetLastEnchantments() + { + return lastEnchantment; + } + /// /// Get all Entities /// @@ -2719,6 +2729,22 @@ namespace MinecraftClient Log.Info(sb.ToString()); + lastEnchantment = new(); + lastEnchantment.TopEnchantment = topEnchantment; + lastEnchantment.MiddleEnchantment = middleEnchantment; + lastEnchantment.BottomEnchantment = bottomEnchantment; + + lastEnchantment.Seed = inventory.Properties[3]; + + lastEnchantment.TopEnchantmentLevel = topEnchantmentLevel; + lastEnchantment.MiddleEnchantmentLevel = middleEnchantmentLevel; + lastEnchantment.BottomEnchantmentLevel = bottomEnchantmentLevel; + + lastEnchantment.TopEnchantmentLevelRequirement = topEnchantmentLevelRequirement; + lastEnchantment.MiddleEnchantmentLevelRequirement = middleEnchantmentLevelRequirement; + lastEnchantment.BottomEnchantmentLevelRequirement = bottomEnchantmentLevelRequirement; + + DispatchBotEvent(bot => bot.OnEnchantments( // Enchantments topEnchantment, @@ -2734,6 +2760,8 @@ namespace MinecraftClient topEnchantmentLevelRequirement, middleEnchantmentLevelRequirement, bottomEnchantmentLevelRequirement)); + + DispatchBotEvent(bot => bot.OnEnchantments(lastEnchantment)); } } } diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index ccb5297d..3543b494 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -105,6 +105,8 @@ error.usage=Usage: error.generator.invalid=Invalid usage of the generator command! error.generator.path=Invalid data path provided! (The path either does not exists or you have made a typo) error.generator.json=The provided path must be a path to a file that is in .json format! +error.terrain_not_enabled=This feature requires Terrain And Movements to be enabled in order to work! +error.inventoryhandling_not_enabled=This feature requires Inventory Handling to be enabled in order to work! [internal command] # MCC internal help command @@ -278,6 +280,8 @@ cmd.enchant.clicked=Sent a click to the server, if you have enough levels and if cmd.enchant.not_clicked=Could not click! cmd.enchant.enchanting_no_item=You must put an item inside the enchanting table in slot 0! cmd.enchant.enchanting_no_lapis=You must put at least 3 lapis lazuli inside the enchanting table in slot 1! +cmd.enchant.no_enchantments=You must first put an item to enchant to the enchanting table in order to get enchantments from the server, then you can execute this command! +cmd.enchant.no_levels=You do not have enouhg levels to enchant! (Your current level is {0}, you need to be level {1}). # Entitycmd cmd.entityCmd.attacked=Entity attacked diff --git a/MinecraftClient/Scripting/ChatBot.cs b/MinecraftClient/Scripting/ChatBot.cs index bd171234..14fefcde 100644 --- a/MinecraftClient/Scripting/ChatBot.cs +++ b/MinecraftClient/Scripting/ChatBot.cs @@ -394,6 +394,14 @@ namespace MinecraftClient short bottomEnchantmentLevelRequirement) { } + /// + /// When received enchantments from the server this method is called + /// Enchantment levels are the levels of enchantment (eg. I, II, III, IV, V) (eg. Smite IV, Power III, Knockback II ..) + /// Enchantment level requirements are the levels that player needs to have in order to enchant the item + /// + /// Enchantment data/info + public virtual void OnEnchantments(EnchantmentData enchantment) { } + /// /// Called when a player joined the game ///