mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement command completion suggestions.
This commit is contained in:
parent
5d2589b10f
commit
84cf749344
115 changed files with 4684 additions and 2695 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Brigadier.NET;
|
||||
using Brigadier.NET.Builder;
|
||||
using MinecraftClient.CommandHandler;
|
||||
using MinecraftClient.Mapping;
|
||||
using static MinecraftClient.CommandHandler.CmdResult;
|
||||
|
||||
namespace MinecraftClient.Commands
|
||||
{
|
||||
|
|
@ -11,53 +13,68 @@ namespace MinecraftClient.Commands
|
|||
public override string CmdUsage { get { return "dig <x> <y> <z>"; } }
|
||||
public override string CmdDesc { get { return Translations.cmd_dig_desc; } }
|
||||
|
||||
public override void RegisterCommand(McClient handler, CommandDispatcher<CommandSource> dispatcher)
|
||||
public override void RegisterCommand(McClient handler, CommandDispatcher<CmdResult> dispatcher)
|
||||
{
|
||||
dispatcher.Register(l => l.Literal("help")
|
||||
.Then(l => l.Literal(CmdName)
|
||||
.Executes(r => GetUsage(r.Source, string.Empty))
|
||||
)
|
||||
);
|
||||
|
||||
dispatcher.Register(l => l.Literal(CmdName)
|
||||
.Executes(r => DigLookAt(r.Source, handler))
|
||||
.Then(l => l.Argument("Location", MccArguments.Location())
|
||||
.Executes(r => DigAt(r.Source, handler, MccArguments.GetLocation(r, "Location"))))
|
||||
.Then(l => l.Literal("_help")
|
||||
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
||||
);
|
||||
}
|
||||
|
||||
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
||||
private int GetUsage(CmdResult r, string? cmd)
|
||||
{
|
||||
return r.SetAndReturn(cmd switch
|
||||
{
|
||||
#pragma warning disable format // @formatter:off
|
||||
_ => GetCmdDescTranslated(),
|
||||
#pragma warning restore format // @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
private int DigAt(CmdResult r, McClient handler, Location blockToBreak)
|
||||
{
|
||||
if (!handler.GetTerrainEnabled())
|
||||
return Translations.extra_terrainandmovement_required;
|
||||
return r.SetAndReturn(Status.FailNeedTerrain);
|
||||
|
||||
string[] args = GetArgs(command);
|
||||
if (args.Length == 0)
|
||||
Location current = handler.GetCurrentLocation();
|
||||
blockToBreak = blockToBreak.ToAbsolute(current);
|
||||
if (blockToBreak.DistanceSquared(current.EyesLocation()) > 25)
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_too_far);
|
||||
Block block = handler.GetWorld().GetBlock(blockToBreak);
|
||||
if (block.Type == Material.Air)
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_no_block);
|
||||
else if (handler.DigBlock(blockToBreak))
|
||||
{
|
||||
(bool hasBlock, Location blockLoc, Block block) = RaycastHelper.RaycastBlock(handler, 4.5, false);
|
||||
if (!hasBlock)
|
||||
return Translations.cmd_dig_too_far;
|
||||
else if (block.Type == Material.Air)
|
||||
return Translations.cmd_dig_no_block;
|
||||
else if (handler.DigBlock(blockLoc, lookAtBlock: false))
|
||||
return string.Format(Translations.cmd_dig_dig, blockLoc.X, blockLoc.Y, blockLoc.Z, block.GetTypeString());
|
||||
else
|
||||
return Translations.cmd_dig_fail;
|
||||
}
|
||||
else if (args.Length == 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
Location current = handler.GetCurrentLocation();
|
||||
Location blockToBreak = Location.Parse(current.ToFloor(), args[0], args[1], args[2]);
|
||||
if (blockToBreak.DistanceSquared(current.EyesLocation()) > 25)
|
||||
return Translations.cmd_dig_too_far;
|
||||
Block block = handler.GetWorld().GetBlock(blockToBreak);
|
||||
if (block.Type == Material.Air)
|
||||
return Translations.cmd_dig_no_block;
|
||||
else if (handler.DigBlock(blockToBreak))
|
||||
{
|
||||
blockToBreak = blockToBreak.ToCenter();
|
||||
return string.Format(Translations.cmd_dig_dig, blockToBreak.X, blockToBreak.Y, blockToBreak.Z, block.GetTypeString());
|
||||
}
|
||||
else
|
||||
return Translations.cmd_dig_fail;
|
||||
}
|
||||
catch (FormatException) { return GetCmdDescTranslated(); }
|
||||
blockToBreak = blockToBreak.ToCenter();
|
||||
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_dig_dig, blockToBreak.X, blockToBreak.Y, blockToBreak.Z, block.GetTypeString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetCmdDescTranslated();
|
||||
}
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_fail);
|
||||
}
|
||||
|
||||
private int DigLookAt(CmdResult r, McClient handler)
|
||||
{
|
||||
if (!handler.GetTerrainEnabled())
|
||||
return r.SetAndReturn(Status.FailNeedTerrain);
|
||||
|
||||
(bool hasBlock, Location blockLoc, Block block) = RaycastHelper.RaycastBlock(handler, 4.5, false);
|
||||
if (!hasBlock)
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_too_far);
|
||||
else if (block.Type == Material.Air)
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_no_block);
|
||||
else if (handler.DigBlock(blockLoc, lookAtBlock: false))
|
||||
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_dig_dig, blockLoc.X, blockLoc.Y, blockLoc.Z, block.GetTypeString()));
|
||||
else
|
||||
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_fail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue