2021-05-11 02:27:18 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2022-10-26 08:54:54 +08:00
|
|
|
|
using Brigadier.NET;
|
2021-05-11 02:27:18 +08:00
|
|
|
|
using MinecraftClient.Inventory;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
class DropItem : Command
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string CmdName { get { return "dropitem"; } }
|
|
|
|
|
|
public override string CmdUsage { get { return "/dropitem <itemtype>"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_dropItem_desc; } }
|
2021-05-11 02:27:18 +08:00
|
|
|
|
|
2022-10-26 08:54:54 +08:00
|
|
|
|
public override void RegisterCommand(McClient handler, CommandDispatcher<CommandSource> dispatcher)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
2021-05-11 02:27:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!handler.GetInventoryEnabled())
|
|
|
|
|
|
{
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return Translations.extra_inventory_required;
|
2021-05-11 02:27:18 +08:00
|
|
|
|
}
|
2022-10-02 18:31:08 +08:00
|
|
|
|
if (HasArg(command))
|
2021-05-11 02:27:18 +08:00
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
string arg = GetArg(command);
|
|
|
|
|
|
if (Enum.TryParse(arg, true, out ItemType itemType))
|
2021-05-11 02:27:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
int inventoryId;
|
|
|
|
|
|
var inventories = handler.GetInventories();
|
|
|
|
|
|
List<int> availableIds = inventories.Keys.ToList();
|
|
|
|
|
|
availableIds.Remove(0); // remove player inventory ID from list
|
|
|
|
|
|
if (availableIds.Count == 1)
|
|
|
|
|
|
inventoryId = availableIds[0]; // one container, use it
|
|
|
|
|
|
else
|
|
|
|
|
|
inventoryId = 0;
|
|
|
|
|
|
var p = inventories[inventoryId];
|
|
|
|
|
|
int[] targetItems = p.SearchItem(itemType);
|
|
|
|
|
|
foreach (int slot in targetItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
handler.DoWindowAction(inventoryId, slot, WindowActionType.DropItemStack);
|
|
|
|
|
|
}
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_dropItem_dropped, itemType.ToString(), inventoryId);
|
2021-05-11 02:27:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_dropItem_unknown_item, arg);
|
2021-05-11 02:27:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return CmdUsage;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|