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 (!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))

View file

@ -10,8 +10,11 @@ namespace MinecraftClient.Commands
public override string CmdUsage { get { return "blockinfo <x> <y> <z> [-s]"; } }
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);
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());
}

View file

@ -12,6 +12,9 @@ namespace MinecraftClient.Commands
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))
{
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");
}