2022-12-06 20:32:46 +08:00
|
|
|
|
using Brigadier.NET;
|
2022-12-06 15:50:17 +08:00
|
|
|
|
using Brigadier.NET.Builder;
|
|
|
|
|
|
using MinecraftClient.CommandHandler;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
using MinecraftClient.Mapping;
|
2022-12-06 15:50:17 +08:00
|
|
|
|
using static MinecraftClient.CommandHandler.CmdResult;
|
2020-06-20 17:57:07 +05:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
class Useblock : Command
|
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
|
public override string CmdName { get { return "useblock"; } }
|
|
|
|
|
|
public override string CmdUsage { get { return "useblock <x> <y> <z>"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_useblock_desc; } }
|
2020-06-20 17:57:07 +05:00
|
|
|
|
|
2022-12-06 15:50:17 +08:00
|
|
|
|
public override void RegisterCommand(McClient handler, CommandDispatcher<CmdResult> dispatcher)
|
2022-10-26 08:54:54 +08:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
dispatcher.Register(l => l.Literal("help")
|
|
|
|
|
|
.Then(l => l.Literal(CmdName)
|
|
|
|
|
|
.Executes(r => GetUsage(r.Source, string.Empty))
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
dispatcher.Register(l => l.Literal(CmdName)
|
|
|
|
|
|
.Then(l => l.Argument("Location", MccArguments.Location())
|
|
|
|
|
|
.Executes(r => UseBlockAtLocation(r.Source, handler, MccArguments.GetLocation(r, "Location"))))
|
|
|
|
|
|
.Then(l => l.Literal("_help")
|
|
|
|
|
|
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
|
|
|
|
|
);
|
2022-10-26 08:54:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-06 15:50:17 +08:00
|
|
|
|
private int GetUsage(CmdResult r, string? cmd)
|
2020-06-20 17:57:07 +05:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
return r.SetAndReturn(cmd switch
|
2020-06-20 17:57:07 +05:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
#pragma warning disable format // @formatter:off
|
|
|
|
|
|
_ => GetCmdDescTranslated(),
|
|
|
|
|
|
#pragma warning restore format // @formatter:on
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int UseBlockAtLocation(CmdResult r, McClient handler, Location block)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!handler.GetTerrainEnabled())
|
|
|
|
|
|
return r.SetAndReturn(Status.FailNeedTerrain);
|
|
|
|
|
|
|
|
|
|
|
|
Location current = handler.GetCurrentLocation();
|
|
|
|
|
|
block = block.ToAbsolute(current).ToFloor();
|
|
|
|
|
|
Location blockCenter = block.ToCenter();
|
|
|
|
|
|
bool res = handler.PlaceBlock(block, Direction.Down);
|
|
|
|
|
|
return r.SetAndReturn(string.Format(Translations.cmd_useblock_use, blockCenter.X, blockCenter.Y, blockCenter.Z, res ? "succeeded" : "failed"), res);
|
2020-06-20 17:57:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|