Add Location_Order config for AutoDig

This commit is contained in:
BruceChen 2022-10-08 18:47:16 +08:00
parent c57ac183d5
commit 2f5914dd6f
5 changed files with 42 additions and 9 deletions

View file

@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
using MinecraftClient.Mapping.BlockPalettes;
using Tomlet.Attributes;
using static MinecraftClient.ChatBots.AutoCraft.Configs;
namespace MinecraftClient.ChatBots
{
@ -42,6 +36,9 @@ namespace MinecraftClient.ChatBots
[TomlInlineComment("$config.ChatBot.AutoDig.Locations$")]
public Coordination[] Locations = new Coordination[] { new(123.5, 64, 234.5), new(124.5, 63, 235.5) };
[TomlInlineComment("$config.ChatBot.AutoDig.Location_Order$")]
public OrderType Location_Order = OrderType.distance;
[TomlInlineComment("$config.ChatBot.AutoDig.Auto_Start_Delay$")]
public double Auto_Start_Delay = 3.0;
@ -76,6 +73,8 @@ namespace MinecraftClient.ChatBots
public enum ListType { blacklist, whitelist };
public enum OrderType { distance, index };
public struct Coordination
{
public double x, y, z;
@ -146,7 +145,6 @@ namespace MinecraftClient.ChatBots
else return GetHelp();
}
private void StartDigging()
{
if (Config.Auto_Start_Delay > 0)
@ -280,7 +278,7 @@ namespace MinecraftClient.ChatBots
return false;
}
}
else if (Config.Mode == Configs.ModeType.fixedpos)
else if (Config.Mode == Configs.ModeType.fixedpos && Config.Location_Order == Configs.OrderType.distance)
{
Location current = GetCurrentLocation();
@ -330,6 +328,39 @@ namespace MinecraftClient.ChatBots
return false;
}
}
else if (Config.Mode == Configs.ModeType.fixedpos && Config.Location_Order == Configs.OrderType.index)
{
for (int i = 0; i < Config._Locations.Length; ++i)
{
Location blockLoc = Config._Locations[i];
Block block = GetWorld().GetBlock(blockLoc);
if (block.Type != Material.Air &&
((Config.List_Type == Configs.ListType.whitelist && Config.Blocks.Contains(block.Type)) ||
(Config.List_Type == Configs.ListType.blacklist && !Config.Blocks.Contains(block.Type))))
{
if (DigBlock(blockLoc, lookAtBlock: true))
{
currentDig = blockLoc;
if (Config.Log_Block_Dig)
LogToConsole(Translations.Get("cmd.dig.dig", blockLoc.X, blockLoc.Y, blockLoc.Z, block.Type));
return true;
}
else
{
LogToConsole(Translations.Get("cmd.dig.fail"));
return false;
}
}
}
if (!AlreadyWaitting)
{
AlreadyWaitting = true;
if (Config.Log_Block_Dig)
LogToConsole(Translations.Get("cmd.dig.no_block"));
}
return false;
}
return false;
}