This commit is contained in:
@@ -14,11 +14,14 @@ import net.minecraft.util.Identifier;
|
|||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import skybot.commands.CommandManager;
|
import skybot.commands.CommandManager;
|
||||||
import skybot.controller.Controller;
|
import skybot.controller.Controller;
|
||||||
import skybot.farmers.Farmer;
|
import skybot.farmers.Farmer;
|
||||||
import skybot.task.TaskQueue;
|
import skybot.task.TaskQueue;
|
||||||
import skybot.utilities.ChatMenu;
|
import skybot.utilities.ChatMenu;
|
||||||
|
import skybot.utilities.TickScheduler;
|
||||||
|
|
||||||
public class SkybotClient implements ClientModInitializer {
|
public class SkybotClient implements ClientModInitializer {
|
||||||
|
|
||||||
@@ -93,6 +96,7 @@ public class SkybotClient implements ClientModInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
KeyBindingHelper.registerKeyBinding(STOP_KEY);
|
KeyBindingHelper.registerKeyBinding(STOP_KEY);
|
||||||
|
TickScheduler.register();
|
||||||
|
|
||||||
ClientPlayerBlockBreakEvents.AFTER
|
ClientPlayerBlockBreakEvents.AFTER
|
||||||
.register((world, player, pos, state) -> lastBreakTime = System.currentTimeMillis());
|
.register((world, player, pos, state) -> lastBreakTime = System.currentTimeMillis());
|
||||||
@@ -137,7 +141,11 @@ public class SkybotClient implements ClientModInitializer {
|
|||||||
tickCount++;
|
tickCount++;
|
||||||
if (botEnabled && tickCount % HEALTHCHECK_INTERVAL_TICKS == 0 && !activeFarmer.healthcheck()) {
|
if (botEnabled && tickCount % HEALTHCHECK_INTERVAL_TICKS == 0 && !activeFarmer.healthcheck()) {
|
||||||
ChatMenu.send("§cHealthcheck failed, stopping bot.§r");
|
ChatMenu.send("§cHealthcheck failed, stopping bot.§r");
|
||||||
|
ChatMenu.send("§cDisconnecting in 3 seconds...§r");
|
||||||
stopBot();
|
stopBot();
|
||||||
|
TickScheduler.schedule(
|
||||||
|
() -> MinecraftClient.getInstance().disconnect(Text.literal("Skybot healthcheck failed")),
|
||||||
|
60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package skybot.utilities;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
|
public class TickScheduler {
|
||||||
|
private record Task(Runnable action, int ticksRemaining) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ConcurrentLinkedQueue<Task> tasks = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
ClientTickEvents.END_CLIENT_TICK.register(client -> tick());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void schedule(Runnable action, int delayTicks) {
|
||||||
|
tasks.add(new Task(action, delayTicks));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void tick() {
|
||||||
|
int size = tasks.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
Task t = tasks.poll();
|
||||||
|
if (t == null)
|
||||||
|
break;
|
||||||
|
int remaining = t.ticksRemaining() - 1;
|
||||||
|
if (remaining <= 0) {
|
||||||
|
t.action().run();
|
||||||
|
} else {
|
||||||
|
tasks.add(new Task(t.action(), remaining));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user