Add command for dropping items from inventory (#1581)

* Add command for dropping items from inventory
* Allow other container to be used
This commit is contained in:
ReinforceZwei 2021-05-11 02:27:18 +08:00 committed by GitHub
parent f7e74c76c2
commit 1cd7c098c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MinecraftClient.Inventory;
namespace MinecraftClient.Commands
{
class DropItem : Command
{
public override string CmdName { get { return "dropitem"; } }
public override string CmdDesc { get { return "cmd.dropItem.desc"; } }
public override string CmdUsage { get { return "/dropitem <itemtype>"; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{
if (!handler.GetInventoryEnabled())
{
return Translations.Get("extra.inventory_required");
}
if (hasArg(command))
{
string arg = getArg(command);
ItemType itemType;
if (Enum.TryParse(arg, true, out itemType))
{
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);
}
return Translations.Get("cmd.dropItem.dropped", itemType.ToString(), inventoryId);
}
else
{
return Translations.Get("cmd.dropItem.unknown_item", arg);
}
}
else
{
return CmdUsage;
}
}
}
}

View file

@ -76,6 +76,7 @@
<Compile Include="ChatBots\AutoDrop.cs" />
<Compile Include="ChatBots\Mailer.cs" />
<Compile Include="ChatBots\ReplayCapture.cs" />
<Compile Include="Commands\DropItem.cs" />
<Compile Include="Commands\Entitycmd.cs" />
<Compile Include="ChatBots\Alerts.cs" />
<Compile Include="ChatBots\AntiAFK.cs" />

View file

@ -326,6 +326,11 @@ cmd.sneak.desc=Toggles sneaking
cmd.sneak.on=You are sneaking now
cmd.sneak.off=You aren't sneaking anymore
# DropItem
cmd.dropItem.desc=Drop specified type of items from player inventory or opened container
cmd.dropItem.dropped=Dropped all {0} from inventory #{1}
cmd.dropItem.unknown_item=Unknown item {0}
# Tps
cmd.tps.desc=Display server current tps (tick per second). May not be accurate
cmd.tps.current=Current tps