Adjust dig block API

Attempt to automate dig start and dig complete (#1077)
This commit is contained in:
ORelio 2020-06-20 21:30:23 +02:00
parent 6df5076d19
commit 4cc29a6ee6
11 changed files with 113 additions and 48 deletions

View file

@ -12,7 +12,9 @@ namespace MinecraftClient.Commands
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{
if (!handler.GetInventoryEnabled()) return "Please enable InventoryHandling in the config file first.";
if (!handler.GetTerrainEnabled())
return "Please enable InventoryHandling in the config file first.";
if (hasArg(command))
{
short slot;

View file

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MinecraftClient.Mapping;
namespace MinecraftClient.Commands
{
public class Dig : Command
{
public override string CMDName { get { return "dig"; } }
public override string CMDDesc { get { return "dig <x> <y> <z>: attempt to break a block"; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{
if (!handler.GetTerrainEnabled())
return "Please enable Terrain and Movements to use this command.";
if (hasArg(command))
{
string[] args = getArgs(command);
if (args.Length == 3)
{
try
{
int x = int.Parse(args[0]);
int y = int.Parse(args[1]);
int z = int.Parse(args[2]);
Location blockToBreak = new Location(x, y, z);
if (blockToBreak.DistanceSquared(handler.GetCurrentLocation()) >= 16)
return "You are too far away from this block.";
if (handler.GetWorld().GetBlock(blockToBreak).Type == Material.Air)
return "No block at this location (Air)";
if (handler.DigBlock(blockToBreak))
return String.Format("Attempting to dig block at {0} {1} {2}", x, y, z);
else return "Failed to start digging block.";
}
catch (FormatException) { return CMDDesc; }
}
else return CMDDesc;
}
else return CMDDesc;
}
}
}