mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added slab handling for 1.20/.1
Added Farm bot crops handling for 1.20/.1 Added utilities for Containers/Inventories Added bot movement lock to prevent multiple bots that use movements from running at the same time. General code improvements.
This commit is contained in:
parent
497a1174de
commit
272900d52e
11 changed files with 941 additions and 797 deletions
|
|
@ -8,7 +8,6 @@ namespace MinecraftClient.ChatBots
|
|||
/// <summary>
|
||||
/// This bot sends a command every 60 seconds in order to stay non-afk.
|
||||
/// </summary>
|
||||
|
||||
public class AntiAFK : ChatBot
|
||||
{
|
||||
public static Configs Config = new();
|
||||
|
|
@ -16,8 +15,7 @@ namespace MinecraftClient.ChatBots
|
|||
[TomlDoNotInlineObject]
|
||||
public class Configs
|
||||
{
|
||||
[NonSerialized]
|
||||
private const string BotName = "AntiAFK";
|
||||
[NonSerialized] private const string BotName = "AntiAFK";
|
||||
|
||||
public bool Enabled = false;
|
||||
|
||||
|
|
@ -99,6 +97,13 @@ namespace MinecraftClient.ChatBots
|
|||
{
|
||||
LogToConsole(Translations.bot_antiafk_not_using_terrain_handling);
|
||||
}
|
||||
else
|
||||
{
|
||||
var movementLock = BotMovementLock.Instance;
|
||||
if (movementLock is { IsLocked: true })
|
||||
LogToConsole(
|
||||
$"§§6§1§0{string.Format(Translations.bot_antiafk_may_not_move, movementLock.LockedBy)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,25 +111,22 @@ namespace MinecraftClient.ChatBots
|
|||
{
|
||||
count++;
|
||||
|
||||
if (count >= nextrun)
|
||||
{
|
||||
DoAntiAfkStuff();
|
||||
count = 0;
|
||||
nextrun = random.Next(Settings.DoubleToTick(Config.Delay.min), Settings.DoubleToTick(Config.Delay.max));
|
||||
}
|
||||
|
||||
if (count < nextrun) return;
|
||||
DoAntiAfkStuff();
|
||||
count = 0;
|
||||
nextrun = random.Next(Settings.DoubleToTick(Config.Delay.min), Settings.DoubleToTick(Config.Delay.max));
|
||||
}
|
||||
|
||||
private void DoAntiAfkStuff()
|
||||
{
|
||||
if (Config.Use_Terrain_Handling && GetTerrainEnabled())
|
||||
var isMovementLocked = BotMovementLock.Instance;
|
||||
if (Config.Use_Terrain_Handling && GetTerrainEnabled() && isMovementLocked is {IsLocked: false})
|
||||
{
|
||||
Location currentLocation = GetCurrentLocation();
|
||||
Location goal;
|
||||
var currentLocation = GetCurrentLocation();
|
||||
|
||||
bool moved = false;
|
||||
bool useAlternativeMethod = false;
|
||||
int triesCounter = 0;
|
||||
var moved = false;
|
||||
var useAlternativeMethod = false;
|
||||
var triesCounter = 0;
|
||||
|
||||
while (!moved)
|
||||
{
|
||||
|
|
@ -134,10 +136,11 @@ namespace MinecraftClient.ChatBots
|
|||
break;
|
||||
}
|
||||
|
||||
goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
|
||||
var goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
|
||||
|
||||
// Prevent getting the same location
|
||||
while ((currentLocation.X == goal.X) && (currentLocation.Y == goal.Y) && (currentLocation.Z == goal.Z))
|
||||
while ((currentLocation.X == goal.X) && (currentLocation.Y == goal.Y) &&
|
||||
(currentLocation.Z == goal.Z))
|
||||
{
|
||||
LogToConsole("Same location!, generating new one");
|
||||
goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
|
||||
|
|
@ -148,10 +151,8 @@ namespace MinecraftClient.ChatBots
|
|||
useAlternativeMethod = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
|
||||
}
|
||||
|
||||
moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
|
||||
}
|
||||
|
||||
if (!useAlternativeMethod && Config.Use_Sneak)
|
||||
|
|
@ -169,12 +170,14 @@ namespace MinecraftClient.ChatBots
|
|||
Sneak(previousSneakState);
|
||||
previousSneakState = !previousSneakState;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
}
|
||||
|
||||
private Location GetRandomLocationWithinRangeXZ(Location currentLocation, int range)
|
||||
{
|
||||
return new Location(currentLocation.X + random.Next(range * -1, range), currentLocation.Y, currentLocation.Z + random.Next(range * -1, range));
|
||||
return new Location(currentLocation.X + random.Next(range * -1, range), currentLocation.Y,
|
||||
currentLocation.Z + random.Next(range * -1, range));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -19,8 +19,7 @@ namespace MinecraftClient.ChatBots
|
|||
[TomlDoNotInlineObject]
|
||||
public class Configs
|
||||
{
|
||||
[NonSerialized]
|
||||
private const string BotName = "FollowPlayer";
|
||||
[NonSerialized] private const string BotName = "FollowPlayer";
|
||||
|
||||
public bool Enabled = false;
|
||||
|
||||
|
|
@ -73,7 +72,8 @@ namespace MinecraftClient.ChatBots
|
|||
.Then(l => l.Argument("PlayerName", MccArguments.PlayerName())
|
||||
.Executes(r => OnCommandStart(r.Source, Arguments.GetString(r, "PlayerName"), takeRisk: false))
|
||||
.Then(l => l.Literal("-f")
|
||||
.Executes(r => OnCommandStart(r.Source, Arguments.GetString(r, "PlayerName"), takeRisk: true)))))
|
||||
.Executes(r =>
|
||||
OnCommandStart(r.Source, Arguments.GetString(r, "PlayerName"), takeRisk: true)))))
|
||||
.Then(l => l.Literal("stop")
|
||||
.Executes(r => OnCommandStop(r.Source)))
|
||||
.Then(l => l.Literal("_help")
|
||||
|
|
@ -84,6 +84,7 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
public override void OnUnload()
|
||||
{
|
||||
BotMovementLock.Instance?.UnLock("Follow Player");
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.GetRoot().GetChild("help").RemoveChild(CommandName);
|
||||
}
|
||||
|
|
@ -104,7 +105,7 @@ namespace MinecraftClient.ChatBots
|
|||
if (!IsValidName(name))
|
||||
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_follow_invalid_name);
|
||||
|
||||
Entity? player = GetEntities().Values.ToList().Find(entity =>
|
||||
var player = GetEntities().Values.ToList().Find(entity =>
|
||||
entity.Type == EntityType.Player
|
||||
&& !string.IsNullOrEmpty(entity.Name)
|
||||
&& entity.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
|
|
@ -116,22 +117,37 @@ namespace MinecraftClient.ChatBots
|
|||
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_follow_cant_reach_player);
|
||||
|
||||
if (_playerToFollow != null && _playerToFollow.Equals(name, StringComparison.OrdinalIgnoreCase))
|
||||
return r.SetAndReturn(CmdResult.Status.Fail, string.Format(Translations.cmd_follow_already_following, _playerToFollow));
|
||||
return r.SetAndReturn(CmdResult.Status.Fail,
|
||||
string.Format(Translations.cmd_follow_already_following, _playerToFollow));
|
||||
|
||||
string result;
|
||||
if (_playerToFollow != null)
|
||||
result = string.Format(Translations.cmd_follow_switched, player.Name!);
|
||||
else
|
||||
result = string.Format(Translations.cmd_follow_started, player.Name!);
|
||||
var movementLock = BotMovementLock.Instance;
|
||||
if (movementLock is { IsLocked: true })
|
||||
return r.SetAndReturn(CmdResult.Status.Fail,
|
||||
string.Format(Translations.bot_common_movement_lock_held, "Follow Player", movementLock.LockedBy));
|
||||
|
||||
var result =
|
||||
string.Format(
|
||||
_playerToFollow != null ? Translations.cmd_follow_switched : Translations.cmd_follow_started,
|
||||
player.Name!);
|
||||
_playerToFollow = name.ToLower();
|
||||
|
||||
if (takeRisk)
|
||||
switch (movementLock)
|
||||
{
|
||||
_unsafeEnabled = true;
|
||||
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_follow_note + '\n' + Translations.cmd_follow_unsafe_enabled);
|
||||
case { IsLocked: false }:
|
||||
if (!movementLock.Lock("Follow Player"))
|
||||
{
|
||||
LogToConsole($"§§6§1§0Follow Player bot failed to obtain the movement lock for some reason!");
|
||||
LogToConsole($"§§6§1§0Disable other bots who have movement mechanics, and try again!");
|
||||
return r.SetAndReturn(CmdResult.Status.Fail);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_follow_note);
|
||||
|
||||
if (!takeRisk) return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_follow_note);
|
||||
_unsafeEnabled = true;
|
||||
return r.SetAndReturn(CmdResult.Status.Done,
|
||||
Translations.cmd_follow_note + '\n' + Translations.cmd_follow_unsafe_enabled);
|
||||
}
|
||||
|
||||
private int OnCommandStop(CmdResult r)
|
||||
|
|
@ -139,6 +155,8 @@ namespace MinecraftClient.ChatBots
|
|||
if (_playerToFollow == null)
|
||||
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_follow_already_stopped);
|
||||
|
||||
var movementLock = BotMovementLock.Instance;
|
||||
movementLock?.UnLock("Follow Player");
|
||||
_playerToFollow = null;
|
||||
|
||||
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_follow_stopping);
|
||||
|
|
@ -168,8 +186,8 @@ namespace MinecraftClient.ChatBots
|
|||
if (!CanMoveThere(entity.Location))
|
||||
return;
|
||||
|
||||
// Stop at specified distance from plater (prevents pushing player around)
|
||||
double distance = entity.Location.Distance(GetCurrentLocation());
|
||||
// Stop at specified distance from player (prevents pushing player around)
|
||||
var distance = entity.Location.Distance(GetCurrentLocation());
|
||||
|
||||
if (distance < Config.Stop_At_Distance)
|
||||
return;
|
||||
|
|
@ -182,7 +200,8 @@ namespace MinecraftClient.ChatBots
|
|||
if (entity.Type != EntityType.Player)
|
||||
return;
|
||||
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(entity.Name) && _playerToFollow.Equals(entity.Name, StringComparison.OrdinalIgnoreCase))
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(entity.Name) &&
|
||||
_playerToFollow.Equals(entity.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogToConsole(string.Format(Translations.cmd_follow_player_came_to_the_range, _playerToFollow));
|
||||
LogToConsole(Translations.cmd_follow_resuming);
|
||||
|
|
@ -194,7 +213,8 @@ namespace MinecraftClient.ChatBots
|
|||
if (entity.Type != EntityType.Player)
|
||||
return;
|
||||
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(entity.Name) && _playerToFollow.Equals(entity.Name, StringComparison.OrdinalIgnoreCase))
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(entity.Name) &&
|
||||
_playerToFollow.Equals(entity.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogToConsole(string.Format(Translations.cmd_follow_player_left_the_range, _playerToFollow));
|
||||
LogToConsole(Translations.cmd_follow_pausing);
|
||||
|
|
@ -203,7 +223,8 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
public override void OnPlayerLeave(Guid uuid, string? name)
|
||||
{
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(name) && _playerToFollow.Equals(name, StringComparison.OrdinalIgnoreCase))
|
||||
if (_playerToFollow != null && !string.IsNullOrEmpty(name) &&
|
||||
_playerToFollow.Equals(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogToConsole(string.Format(Translations.cmd_follow_player_left, _playerToFollow));
|
||||
LogToConsole(Translations.cmd_follow_stopping);
|
||||
|
|
@ -213,12 +234,8 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
private bool CanMoveThere(Location location)
|
||||
{
|
||||
ChunkColumn? chunkColumn = GetWorld().GetChunkColumn(location);
|
||||
|
||||
if (chunkColumn == null || chunkColumn.FullyLoaded == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
var chunkColumn = GetWorld().GetChunkColumn(location);
|
||||
return chunkColumn != null && chunkColumn.FullyLoaded != false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,6 +89,7 @@ public class ItemsCollector : ChatBot
|
|||
|
||||
public override void OnUnload()
|
||||
{
|
||||
StopTheMainProcess();
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.GetRoot().GetChild("help").RemoveChild(CommandName);
|
||||
}
|
||||
|
|
@ -109,6 +110,18 @@ public class ItemsCollector : ChatBot
|
|||
if (running)
|
||||
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_items_collector_already_collecting);
|
||||
|
||||
var movementLock = BotMovementLock.Instance;
|
||||
if (movementLock is { IsLocked: true })
|
||||
return r.SetAndReturn(CmdResult.Status.Fail,
|
||||
string.Format(Translations.bot_common_movement_lock_held, "Items Collector", movementLock.LockedBy));
|
||||
|
||||
if (!movementLock!.Lock("Items Collector"))
|
||||
{
|
||||
LogToConsole($"§§6§1§0Items Collector bot failed to obtain the movement lock for some reason!");
|
||||
LogToConsole($"§§6§1§0Disable other bots who have movement mechanics, and try again!");
|
||||
return r.SetAndReturn(CmdResult.Status.Fail);
|
||||
}
|
||||
|
||||
StartTheMainProcess();
|
||||
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_items_collector_started);
|
||||
}
|
||||
|
|
@ -132,6 +145,7 @@ public class ItemsCollector : ChatBot
|
|||
private void StopTheMainProcess()
|
||||
{
|
||||
running = false;
|
||||
BotMovementLock.Instance?.UnLock("Items Collector");
|
||||
}
|
||||
|
||||
private void MainProcess()
|
||||
|
|
@ -163,13 +177,8 @@ public class ItemsCollector : ChatBot
|
|||
|
||||
if (items.Any())
|
||||
{
|
||||
foreach (var entity in items)
|
||||
{
|
||||
if (!running)
|
||||
break;
|
||||
|
||||
foreach (var entity in items.TakeWhile(entity => running))
|
||||
WaitForMoveToLocation(entity.Location);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ public class WebSocketBot : ChatBot
|
|||
public int Port = 8043;
|
||||
|
||||
[TomlInlineComment("$ChatBot.WebSocketBot.Password$")]
|
||||
public string? Password = "wspass12345";
|
||||
public string? Password = Guid.NewGuid().ToString().Replace("-", "").Trim().ToLower();
|
||||
|
||||
[TomlInlineComment("$ChatBot.WebSocketBot.DebugMode$")]
|
||||
public bool DebugMode = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue