using Brigadier.NET; using Brigadier.NET.Builder; using MinecraftClient.CommandHandler; using static MinecraftClient.CommandHandler.CmdResult; namespace MinecraftClient.Commands { class UseItem : Command { public override string CmdName { get { return "useitem"; } } public override string CmdUsage { get { return "useitem"; } } public override string CmdDesc { get { return Translations.cmd_useitem_desc; } } public override void RegisterCommand(McClient handler, CommandDispatcher 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 => DoUseItem(r.Source, handler)) .Then(l => l.Literal("_help") .Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName))) ); } 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 DoUseItem(CmdResult r, McClient handler) { if (!handler.GetInventoryEnabled()) return r.SetAndReturn(Status.FailNeedInventory); handler.UseItemOnHand(); return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use); } } }