Skip to content

Commit

Permalink
Slab handling 1.20/.1 and Farmer bot improvements
Browse files Browse the repository at this point in the history
Slab handling 1.20/.1 and Farmer bot improvements
  • Loading branch information
milutinke authored Jun 23, 2023
2 parents ac1d2b7 + 272900d commit 469e666
Show file tree
Hide file tree
Showing 11 changed files with 941 additions and 797 deletions.
51 changes: 27 additions & 24 deletions MinecraftClient/ChatBots/AntiAFK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ 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();

[TomlDoNotInlineObject]
public class Configs
{
[NonSerialized]
private const string BotName = "AntiAFK";
[NonSerialized] private const string BotName = "AntiAFK";

public bool Enabled = false;

Expand Down Expand Up @@ -99,32 +97,36 @@ public override void Initialize()
{
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)}");
}
}
}

public override void Update()
{
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)
{
Expand All @@ -134,10 +136,11 @@ private void DoAntiAfkStuff()
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);
Expand All @@ -148,10 +151,8 @@ private void DoAntiAfkStuff()
useAlternativeMethod = true;
break;
}
else
{
moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
}

moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
}

if (!useAlternativeMethod && Config.Use_Sneak)
Expand All @@ -169,12 +170,14 @@ private void DoAntiAfkStuff()
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));
}
}
}
}
Loading

0 comments on commit 469e666

Please sign in to comment.