Add Mode switching command for AutoDrop (#1293)

* Add new command for AutoDrop
* Minor imporvement for AutoDrop
* Fix inventory update event passed a non-exist inventory ID
* Minor improvement for AutoDrop
This commit is contained in:
ReinforceZwei 2020-10-26 00:43:05 +08:00 committed by GitHub
parent 9169036893
commit ec9f999857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 3 deletions

View file

@ -27,7 +27,7 @@ namespace MinecraftClient.ChatBots
{
if (!Enum.TryParse(mode, true, out dropMode))
{
LogToConsole("Cannot read drop mode from config. Using include mode.");
LogToConsoleTranslated("bot.autoDrop.no_mode");
}
if (dropMode != Mode.Everything)
this.itemList = ItemListParser(itemList).ToList();
@ -120,6 +120,31 @@ namespace MinecraftClient.ChatBots
{
return Translations.Get("bot.autoDrop.no_item");
}
case "mode":
if (args.Length >= 2)
{
switch (args[1].ToLower())
{
case "include":
dropMode = Mode.Include;
break;
case "exclude":
dropMode = Mode.Exclude;
break;
case "everything":
dropMode = Mode.Everything;
break;
default:
return Translations.Get("bot.autoDrop.unknown_mode"); // Unknwon mode. Available modes: Include, Exclude, Everything
}
inventoryUpdated = 0;
OnUpdateFinish();
return Translations.Get("bot.autoDrop.switched", dropMode.ToString()); // Switched to {0} mode.
}
else
{
return Translations.Get("bot.autoDrop.unknown_mode");
}
default:
return GetHelp();
}
@ -132,7 +157,7 @@ namespace MinecraftClient.ChatBots
private string GetHelp()
{
return Translations.Get("general.available_cmd", "on, off, add, remove, list");
return Translations.Get("general.available_cmd", "on, off, add, remove, list, mode");
}
public override void Initialize()
@ -165,7 +190,9 @@ namespace MinecraftClient.ChatBots
if (enable)
{
updateDebounce = updateDebounceValue;
inventoryUpdated = inventoryId;
// Always interact container if available (larger ID) because they included player inventory (ID 0)
if (inventoryId >= inventoryUpdated)
inventoryUpdated = inventoryId;
}
}
@ -179,6 +206,9 @@ namespace MinecraftClient.ChatBots
{
foreach (var item in items)
{
// Ingore crafting result slot
if (item.Key == 0)
continue;
if (itemList.Contains(item.Value.Type))
{
// Drop it !!
@ -190,6 +220,9 @@ namespace MinecraftClient.ChatBots
{
foreach (var item in items)
{
// Ingore crafting result slot
if (item.Key == 0)
continue;
if (!itemList.Contains(item.Value.Type))
{
// Drop it !!
@ -201,6 +234,9 @@ namespace MinecraftClient.ChatBots
{
foreach (var item in items)
{
// Ingore crafting result slot
if (item.Key == 0)
continue;
// Drop it !!
WindowAction(inventoryUpdated, item.Key, WindowActionType.DropItemStack);
}