Skip to content

Commit 272900d

Browse files
committed
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.
1 parent 497a117 commit 272900d

File tree

11 files changed

+941
-797
lines changed

11 files changed

+941
-797
lines changed

MinecraftClient/ChatBots/AntiAFK.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ namespace MinecraftClient.ChatBots
88
/// <summary>
99
/// This bot sends a command every 60 seconds in order to stay non-afk.
1010
/// </summary>
11-
1211
public class AntiAFK : ChatBot
1312
{
1413
public static Configs Config = new();
1514

1615
[TomlDoNotInlineObject]
1716
public class Configs
1817
{
19-
[NonSerialized]
20-
private const string BotName = "AntiAFK";
18+
[NonSerialized] private const string BotName = "AntiAFK";
2119

2220
public bool Enabled = false;
2321

@@ -99,32 +97,36 @@ public override void Initialize()
9997
{
10098
LogToConsole(Translations.bot_antiafk_not_using_terrain_handling);
10199
}
100+
else
101+
{
102+
var movementLock = BotMovementLock.Instance;
103+
if (movementLock is { IsLocked: true })
104+
LogToConsole(
105+
$"§§6§1§0{string.Format(Translations.bot_antiafk_may_not_move, movementLock.LockedBy)}");
106+
}
102107
}
103108
}
104109

105110
public override void Update()
106111
{
107112
count++;
108113

109-
if (count >= nextrun)
110-
{
111-
DoAntiAfkStuff();
112-
count = 0;
113-
nextrun = random.Next(Settings.DoubleToTick(Config.Delay.min), Settings.DoubleToTick(Config.Delay.max));
114-
}
115-
114+
if (count < nextrun) return;
115+
DoAntiAfkStuff();
116+
count = 0;
117+
nextrun = random.Next(Settings.DoubleToTick(Config.Delay.min), Settings.DoubleToTick(Config.Delay.max));
116118
}
117119

118120
private void DoAntiAfkStuff()
119121
{
120-
if (Config.Use_Terrain_Handling && GetTerrainEnabled())
122+
var isMovementLocked = BotMovementLock.Instance;
123+
if (Config.Use_Terrain_Handling && GetTerrainEnabled() && isMovementLocked is {IsLocked: false})
121124
{
122-
Location currentLocation = GetCurrentLocation();
123-
Location goal;
125+
var currentLocation = GetCurrentLocation();
124126

125-
bool moved = false;
126-
bool useAlternativeMethod = false;
127-
int triesCounter = 0;
127+
var moved = false;
128+
var useAlternativeMethod = false;
129+
var triesCounter = 0;
128130

129131
while (!moved)
130132
{
@@ -134,10 +136,11 @@ private void DoAntiAfkStuff()
134136
break;
135137
}
136138

137-
goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
139+
var goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
138140

139141
// Prevent getting the same location
140-
while ((currentLocation.X == goal.X) && (currentLocation.Y == goal.Y) && (currentLocation.Z == goal.Z))
142+
while ((currentLocation.X == goal.X) && (currentLocation.Y == goal.Y) &&
143+
(currentLocation.Z == goal.Z))
141144
{
142145
LogToConsole("Same location!, generating new one");
143146
goal = GetRandomLocationWithinRangeXZ(currentLocation, Config.Walk_Range);
@@ -148,10 +151,8 @@ private void DoAntiAfkStuff()
148151
useAlternativeMethod = true;
149152
break;
150153
}
151-
else
152-
{
153-
moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
154-
}
154+
155+
moved = MoveToLocation(goal, allowUnsafe: false, allowDirectTeleport: false);
155156
}
156157

157158
if (!useAlternativeMethod && Config.Use_Sneak)
@@ -169,12 +170,14 @@ private void DoAntiAfkStuff()
169170
Sneak(previousSneakState);
170171
previousSneakState = !previousSneakState;
171172
}
173+
172174
count = 0;
173175
}
174176

175177
private Location GetRandomLocationWithinRangeXZ(Location currentLocation, int range)
176178
{
177-
return new Location(currentLocation.X + random.Next(range * -1, range), currentLocation.Y, currentLocation.Z + random.Next(range * -1, range));
179+
return new Location(currentLocation.X + random.Next(range * -1, range), currentLocation.Y,
180+
currentLocation.Z + random.Next(range * -1, range));
178181
}
179182
}
180-
}
183+
}

0 commit comments

Comments
 (0)