Improvements to the Bed, Blockinfo and Enchant commands.

This commit is contained in:
Milutinke 2022-10-17 15:14:55 +02:00
parent 735dc49d92
commit a31b4a792b
7 changed files with 95 additions and 8 deletions

View file

@ -29,6 +29,9 @@ namespace MinecraftClient.Commands
if (subcommand.Equals("sleep") || subcommand.Equals("s")) if (subcommand.Equals("sleep") || subcommand.Equals("s"))
{ {
if (!handler.GetTerrainEnabled())
return Translations.TryGet("error.terrain_not_enabled");
if (args.Length == 2) if (args.Length == 2)
{ {
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int radius)) if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int radius))

View file

@ -10,8 +10,11 @@ namespace MinecraftClient.Commands
public override string CmdUsage { get { return "blockinfo <x> <y> <z> [-s]"; } } public override string CmdUsage { get { return "blockinfo <x> <y> <z> [-s]"; } }
public override string CmdDesc { get { return "cmd.blockinfo.desc"; } } public override string CmdDesc { get { return "cmd.blockinfo.desc"; } }
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars) public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{ {
if (!handler.GetTerrainEnabled())
return Translations.TryGet("error.terrain_not_enabled");
string[] args = GetArgs(command); string[] args = GetArgs(command);
if (args.Length < 3) if (args.Length < 3)
@ -24,7 +27,7 @@ namespace MinecraftClient.Commands
Block block = handler.GetWorld().GetBlock(targetBlockLocation); 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) if (reportSurrounding)
{ {
@ -38,14 +41,14 @@ namespace MinecraftClient.Commands
Block blockZPositive = handler.GetWorld().GetBlock(new Location(targetBlockLocation.X, targetBlockLocation.Y, targetBlockLocation.Z + 1)); 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)); 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.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXPositive.Type);
sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXNegative.GetTypeString()); sb.AppendLine("[X " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockXNegative.Type);
sb.AppendLine(" "); sb.AppendLine(" ");
sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYPositive.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.GetTypeString()); sb.AppendLine("[Y " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockYNegative.Type);
sb.AppendLine(" "); sb.AppendLine(" ");
sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Positive") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZPositive.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.GetTypeString()); sb.AppendLine("[Z " + Translations.TryGet("cmd.blockinfo.Negative") + "] " + Translations.TryGet("cmd.blockinfo.BlockType") + ": " + blockZNegative.Type);
handler.Log.Info(sb.ToString()); handler.Log.Info(sb.ToString());
} }

View file

@ -12,6 +12,9 @@ namespace MinecraftClient.Commands
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars) public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
{ {
if (!handler.GetInventoryEnabled())
return Translations.TryGet("error.inventoryhandling_not_enabled");
if (HasArg(command)) if (HasArg(command))
{ {
string slot = GetArg(command).ToLower().Trim(); string slot = GetArg(command).ToLower().Trim();
@ -57,6 +60,22 @@ namespace MinecraftClient.Commands
if (lapisSlot.Count < 3) if (lapisSlot.Count < 3)
return Translations.TryGet("cmd.enchant.enchanting_no_lapis"); 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"); return handler.ClickContainerButton(enchantingTable.ID, slotId) ? Translations.TryGet("cmd.enchant.clicked") : Translations.TryGet("cmd.enchant.not_clicked");
} }

View file

@ -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; }
}
}

View file

@ -77,6 +77,7 @@ namespace MinecraftClient
private int respawnTicks = 0; private int respawnTicks = 0;
private int gamemode = 0; private int gamemode = 0;
private bool isSupportPreviewsChat; private bool isSupportPreviewsChat;
private EnchantmentData? lastEnchantment = null;
private int playerEntityID; private int playerEntityID;
@ -1021,6 +1022,15 @@ namespace MinecraftClient
return inventories; return inventories;
} }
/// <summary>
/// Get all Entities
/// </summary>
/// <returns>Ladt Enchantments</returns>
public EnchantmentData? GetLastEnchantments()
{
return lastEnchantment;
}
/// <summary> /// <summary>
/// Get all Entities /// Get all Entities
/// </summary> /// </summary>
@ -2719,6 +2729,22 @@ namespace MinecraftClient
Log.Info(sb.ToString()); 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( DispatchBotEvent(bot => bot.OnEnchantments(
// Enchantments // Enchantments
topEnchantment, topEnchantment,
@ -2734,6 +2760,8 @@ namespace MinecraftClient
topEnchantmentLevelRequirement, topEnchantmentLevelRequirement,
middleEnchantmentLevelRequirement, middleEnchantmentLevelRequirement,
bottomEnchantmentLevelRequirement)); bottomEnchantmentLevelRequirement));
DispatchBotEvent(bot => bot.OnEnchantments(lastEnchantment));
} }
} }
} }

View file

@ -105,6 +105,8 @@ error.usage=Usage:
error.generator.invalid=Invalid usage of the generator command! 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.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.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] [internal command]
# MCC internal help 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.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_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.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 # Entitycmd
cmd.entityCmd.attacked=Entity attacked cmd.entityCmd.attacked=Entity attacked

View file

@ -394,6 +394,14 @@ namespace MinecraftClient
short bottomEnchantmentLevelRequirement) short bottomEnchantmentLevelRequirement)
{ } { }
/// <summary>
/// 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
/// </summary>
/// <param name="enchantment">Enchantment data/info</param>
public virtual void OnEnchantments(EnchantmentData enchantment) { }
/// <summary> /// <summary>
/// Called when a player joined the game /// Called when a player joined the game
/// </summary> /// </summary>