mirror of
https://github.com/AutismDevelopment/Autism-Client.git
synced 2026-10-28 17:29:46 +00:00
Refactor: extract MacroLifecycle from MacroExecutor (upstream #4)
Move 56 run-lifecycle methods (flow control, step overrides, client resources, run-list management, execute/track/stop) verbatim into MacroLifecycle. The public lifecycle API stays reachable via MacroExecutor delegates; all 150+ cross-helper call sites re-pointed. All bodies verified identical against HEAD modulo mechanical MacroExecutor./MacroLifecycle. qualification.
This commit is contained in:
parent
ad5826df73
commit
0e6d34f816
18 changed files with 1025 additions and 957 deletions
|
|
@ -75,8 +75,8 @@ final class MacroActionRunner {
|
||||||
return postGuiFuture;
|
return postGuiFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroExecutor.setCurrentStatus("Waiting target: " + action.getDisplayName());
|
MacroLifecycle.setCurrentStatus("Waiting target: " + action.getDisplayName());
|
||||||
while (MacroExecutor.isCurrentRunActive()) {
|
while (MacroLifecycle.isCurrentRunActive()) {
|
||||||
if (!canRunTargetInteractionNow(mc, action)) {
|
if (!canRunTargetInteractionNow(mc, action)) {
|
||||||
java.util.concurrent.locks.LockSupport.parkNanos(MacroExecutor.MACRO_WAIT_POLL_NANOS);
|
java.util.concurrent.locks.LockSupport.parkNanos(MacroExecutor.MACRO_WAIT_POLL_NANOS);
|
||||||
if (Thread.interrupted()) throw new InterruptedException();
|
if (Thread.interrupted()) throw new InterruptedException();
|
||||||
|
|
@ -172,7 +172,7 @@ final class MacroActionRunner {
|
||||||
private static void waitForCurrentGuiReady(Minecraft mc) throws InterruptedException {
|
private static void waitForCurrentGuiReady(Minecraft mc) throws InterruptedException {
|
||||||
|
|
||||||
long deadline = System.nanoTime() + 500_000_000L;
|
long deadline = System.nanoTime() + 500_000_000L;
|
||||||
while (MacroExecutor.isCurrentRunActive()) {
|
while (MacroLifecycle.isCurrentRunActive()) {
|
||||||
Boolean ready = MacroClientThread.callOnClientThread(mc, () -> {
|
Boolean ready = MacroClientThread.callOnClientThread(mc, () -> {
|
||||||
if (mc.player == null || mc.gui.screen() == null) return false;
|
if (mc.player == null || mc.gui.screen() == null) return false;
|
||||||
if (mc.player.containerMenu != null && mc.player.containerMenu != mc.player.inventoryMenu) {
|
if (mc.player.containerMenu != null && mc.player.containerMenu != mc.player.inventoryMenu) {
|
||||||
|
|
@ -206,17 +206,17 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runItemActionPaced(Minecraft mc, ItemAction ia) throws InterruptedException {
|
public static void runItemActionPaced(Minecraft mc, ItemAction ia) throws InterruptedException {
|
||||||
MacroExecutor.setCurrentStatus(ia.getDisplayName());
|
MacroLifecycle.setCurrentStatus(ia.getDisplayName());
|
||||||
java.util.List<Runnable> plan = MacroClientThread.callOnClientThread(mc, () -> ia.buildClickPlan(mc), java.util.Collections.<Runnable>emptyList());
|
java.util.List<Runnable> plan = MacroClientThread.callOnClientThread(mc, () -> ia.buildClickPlan(mc), java.util.Collections.<Runnable>emptyList());
|
||||||
if (plan == null || plan.isEmpty()) return;
|
if (plan == null || plan.isEmpty()) return;
|
||||||
long delayMs = Math.max(0, ia.clickDelayMs);
|
long delayMs = Math.max(0, ia.clickDelayMs);
|
||||||
MacroExecutor.RunState scheduledRun = MacroExecutor.CURRENT_RUN.get();
|
MacroExecutor.RunState scheduledRun = MacroExecutor.CURRENT_RUN.get();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Runnable op : plan) {
|
for (Runnable op : plan) {
|
||||||
if (!MacroExecutor.isCurrentRunActive()) break;
|
if (!MacroLifecycle.isCurrentRunActive()) break;
|
||||||
if (!first && delayMs > 0) Thread.sleep(delayMs);
|
if (!first && delayMs > 0) Thread.sleep(delayMs);
|
||||||
first = false;
|
first = false;
|
||||||
mc.execute(() -> MacroExecutor.withRunContext(scheduledRun, () -> {
|
mc.execute(() -> MacroLifecycle.withRunContext(scheduledRun, () -> {
|
||||||
if (PackHideState.isHardLocked()) return;
|
if (PackHideState.isHardLocked()) return;
|
||||||
try {
|
try {
|
||||||
op.run();
|
op.run();
|
||||||
|
|
@ -260,7 +260,7 @@ final class MacroActionRunner {
|
||||||
@Override public void runOnClientThread(Runnable r) {
|
@Override public void runOnClientThread(Runnable r) {
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
|
|
||||||
Runnable safe = () -> MacroExecutor.withRunContext(run, () -> {
|
Runnable safe = () -> MacroLifecycle.withRunContext(run, () -> {
|
||||||
try { r.run(); }
|
try { r.run(); }
|
||||||
catch (Throwable t) { AutismClientMessaging.sendPrefixed("\u00a7cAddon action (client task) error: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage())); }
|
catch (Throwable t) { AutismClientMessaging.sendPrefixed("\u00a7cAddon action (client task) error: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage())); }
|
||||||
});
|
});
|
||||||
|
|
@ -272,7 +272,7 @@ final class MacroActionRunner {
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
java.util.function.Supplier<T> safe = () -> {
|
java.util.function.Supplier<T> safe = () -> {
|
||||||
AtomicReference<T> value = new AtomicReference<>();
|
AtomicReference<T> value = new AtomicReference<>();
|
||||||
MacroExecutor.withRunContext(run, () -> {
|
MacroLifecycle.withRunContext(run, () -> {
|
||||||
try { value.set(s.get()); }
|
try { value.set(s.get()); }
|
||||||
catch (Throwable t) { AutismClientMessaging.sendPrefixed("\u00a7cAddon action (client task) error: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage())); }
|
catch (Throwable t) { AutismClientMessaging.sendPrefixed("\u00a7cAddon action (client task) error: " + (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage())); }
|
||||||
});
|
});
|
||||||
|
|
@ -283,24 +283,24 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void waitTicks(int ticks) {
|
@Override public void waitTicks(int ticks) {
|
||||||
MacroExecutor.withRunContext(run, () -> {
|
MacroLifecycle.withRunContext(run, () -> {
|
||||||
for (int i = 0; i < ticks && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < ticks && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
MacroRunLoop.waitForCondition(MacroConditionRegistry.waitForNextTick());
|
MacroRunLoop.waitForCondition(MacroConditionRegistry.waitForNextTick());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void awaitCondition(CompletableFuture<Void> future) {
|
@Override public void awaitCondition(CompletableFuture<Void> future) {
|
||||||
if (future != null) MacroExecutor.withRunContext(run, () -> MacroRunLoop.waitForCondition(future));
|
if (future != null) MacroLifecycle.withRunContext(run, () -> MacroRunLoop.waitForCondition(future));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void awaitCondition(autismclient.api.macro.AddonCondition condition) {
|
@Override public void awaitCondition(autismclient.api.macro.AddonCondition condition) {
|
||||||
if (condition != null) MacroExecutor.withRunContext(run, () -> MacroRunLoop.waitForCondition(MacroConditionRegistry.await(condition)));
|
if (condition != null) MacroLifecycle.withRunContext(run, () -> MacroRunLoop.waitForCondition(MacroConditionRegistry.await(condition)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isActive() { return run != null && run.running.get() && !PackHideState.isHardLocked(); }
|
@Override public boolean isActive() { return run != null && run.running.get() && !PackHideState.isHardLocked(); }
|
||||||
|
|
||||||
@Override public void setStatus(String status) { MacroExecutor.withRunContext(run, () -> MacroExecutor.setCurrentStatus(status)); }
|
@Override public void setStatus(String status) { MacroLifecycle.withRunContext(run, () -> MacroLifecycle.setCurrentStatus(status)); }
|
||||||
|
|
||||||
@Override public void sendPacket(net.minecraft.network.protocol.Packet<?> packet) {
|
@Override public void sendPacket(net.minecraft.network.protocol.Packet<?> packet) {
|
||||||
if (packet == null) return;
|
if (packet == null) return;
|
||||||
|
|
@ -333,7 +333,7 @@ final class MacroActionRunner {
|
||||||
|
|
||||||
public static void runUseItemPhaseAction(Minecraft mc, UseItemPhaseAction action) throws InterruptedException {
|
public static void runUseItemPhaseAction(Minecraft mc, UseItemPhaseAction action) throws InterruptedException {
|
||||||
int times = action.repeatTimes();
|
int times = action.repeatTimes();
|
||||||
for (int i = 0; i < times && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < times && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
|
|
||||||
MacroClientThread.runOnClientThread(mc, () -> {
|
MacroClientThread.runOnClientThread(mc, () -> {
|
||||||
try { action.sendUsePacket(mc); }
|
try { action.sendUsePacket(mc); }
|
||||||
|
|
@ -349,7 +349,7 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
for (int t = 0; t < action.holdTicks && MacroExecutor.isCurrentRunActive(); t++) {
|
for (int t = 0; t < action.holdTicks && MacroLifecycle.isCurrentRunActive(); t++) {
|
||||||
CompletableFuture<Void> tf = MacroConditionRegistry.waitForNextTick();
|
CompletableFuture<Void> tf = MacroConditionRegistry.waitForNextTick();
|
||||||
MacroRunLoop.waitForCondition(tf);
|
MacroRunLoop.waitForCondition(tf);
|
||||||
}
|
}
|
||||||
|
|
@ -363,7 +363,7 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!MacroExecutor.isCurrentRunActive()) break;
|
if (!MacroLifecycle.isCurrentRunActive()) break;
|
||||||
|
|
||||||
MacroClientThread.runOnClientThread(mc, () -> {
|
MacroClientThread.runOnClientThread(mc, () -> {
|
||||||
try { action.finishRelease(mc); }
|
try { action.finishRelease(mc); }
|
||||||
|
|
@ -376,7 +376,7 @@ final class MacroActionRunner {
|
||||||
int times = Math.max(1, action.clickCount);
|
int times = Math.max(1, action.clickCount);
|
||||||
|
|
||||||
MacroClientThread.runOnClientThread(mc, () -> {
|
MacroClientThread.runOnClientThread(mc, () -> {
|
||||||
for (int c = 0; c < times && MacroExecutor.isCurrentRunActive(); c++) {
|
for (int c = 0; c < times && MacroLifecycle.isCurrentRunActive(); c++) {
|
||||||
try {
|
try {
|
||||||
action.execute(mc);
|
action.execute(mc);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -407,7 +407,7 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> slots = MacroClientThread.callOnClientThread(mc, () -> action.collectTransferSlots(mc), List.of());
|
List<Integer> slots = MacroClientThread.callOnClientThread(mc, () -> action.collectTransferSlots(mc), List.of());
|
||||||
for (int i = 0; i < slots.size() && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < slots.size() && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
AutismInventoryClickHelper.click(mc, slots.get(i), 0, net.minecraft.world.inventory.ContainerInput.QUICK_MOVE);
|
AutismInventoryClickHelper.click(mc, slots.get(i), 0, net.minecraft.world.inventory.ContainerInput.QUICK_MOVE);
|
||||||
if (i + 1 < slots.size()) waitTicks(delayTicks);
|
if (i + 1 < slots.size()) waitTicks(delayTicks);
|
||||||
}
|
}
|
||||||
|
|
@ -418,7 +418,7 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void waitTicks(int ticks) {
|
private static void waitTicks(int ticks) {
|
||||||
for (int i = 0; i < ticks && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < ticks && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
CompletableFuture<Void> tickFuture = MacroConditionRegistry.waitForNextTick();
|
CompletableFuture<Void> tickFuture = MacroConditionRegistry.waitForNextTick();
|
||||||
MacroRunLoop.waitForCondition(tickFuture);
|
MacroRunLoop.waitForCondition(tickFuture);
|
||||||
}
|
}
|
||||||
|
|
@ -439,7 +439,7 @@ final class MacroActionRunner {
|
||||||
}, action.isTickAligned());
|
}, action.isTickAligned());
|
||||||
if (action.holdTicks > 0) {
|
if (action.holdTicks > 0) {
|
||||||
waitTicks(action.holdTicks);
|
waitTicks(action.holdTicks);
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return;
|
if (!MacroLifecycle.isCurrentRunActive()) return;
|
||||||
MacroClientThread.runOnClientThread(mc, () -> {
|
MacroClientThread.runOnClientThread(mc, () -> {
|
||||||
try { action.sendRelease(mc); }
|
try { action.sendRelease(mc); }
|
||||||
catch (Exception e) { AutismClientMessaging.sendPrefixed("\u00a7cError in UseItem release: " + e.getMessage()); }
|
catch (Exception e) { AutismClientMessaging.sendPrefixed("\u00a7cError in UseItem release: " + e.getMessage()); }
|
||||||
|
|
@ -450,7 +450,7 @@ final class MacroActionRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
int times = Math.max(1, action.useCount);
|
int times = Math.max(1, action.useCount);
|
||||||
for (int i = 0; i < times && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < times && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
MacroClientThread.runOnClientThread(mc, () -> {
|
MacroClientThread.runOnClientThread(mc, () -> {
|
||||||
try {
|
try {
|
||||||
if (sneaking) autismclient.util.AutismMacroSneak.forceSneak(mc, true);
|
if (sneaking) autismclient.util.AutismMacroSneak.forceSneak(mc, true);
|
||||||
|
|
@ -459,7 +459,7 @@ final class MacroActionRunner {
|
||||||
catch (Exception e) { AutismClientMessaging.sendPrefixed("\u00a7cError in UseItem: " + e.getMessage()); }
|
catch (Exception e) { AutismClientMessaging.sendPrefixed("\u00a7cError in UseItem: " + e.getMessage()); }
|
||||||
}, action.isTickAligned());
|
}, action.isTickAligned());
|
||||||
if (action.waitForFinish) waitForUseItemFinish(mc, 0);
|
if (action.waitForFinish) waitForUseItemFinish(mc, 0);
|
||||||
if (i + 1 < times && MacroExecutor.isCurrentRunActive()) MacroExecutor.waitOneTick();
|
if (i + 1 < times && MacroLifecycle.isCurrentRunActive()) MacroExecutor.waitOneTick();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (sneaking) mc.execute(() -> autismclient.util.AutismMacroSneak.forceSneak(mc, false));
|
if (sneaking) mc.execute(() -> autismclient.util.AutismMacroSneak.forceSneak(mc, false));
|
||||||
|
|
@ -473,9 +473,9 @@ final class MacroActionRunner {
|
||||||
int delay = Math.max(0, action.delayTicks);
|
int delay = Math.max(0, action.delayTicks);
|
||||||
int total = repeats * slots.size();
|
int total = repeats * slots.size();
|
||||||
int sent = 0;
|
int sent = 0;
|
||||||
for (int repeat = 0; repeat < repeats && MacroExecutor.isCurrentRunActive(); repeat++) {
|
for (int repeat = 0; repeat < repeats && MacroLifecycle.isCurrentRunActive(); repeat++) {
|
||||||
for (int slot : slots) {
|
for (int slot : slots) {
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return;
|
if (!MacroLifecycle.isCurrentRunActive()) return;
|
||||||
MacroClientThread.runOnClientThread(mc, () -> action.executeClick(mc, slot));
|
MacroClientThread.runOnClientThread(mc, () -> action.executeClick(mc, slot));
|
||||||
sent++;
|
sent++;
|
||||||
if (delay > 0 && sent < total) waitTicks(delay);
|
if (delay > 0 && sent < total) waitTicks(delay);
|
||||||
|
|
@ -488,14 +488,14 @@ final class MacroActionRunner {
|
||||||
if (action.flushBefore) AutismSharedState.get().flushDelayedPackets(mc.getConnection());
|
if (action.flushBefore) AutismSharedState.get().flushDelayedPackets(mc.getConnection());
|
||||||
int total = action.effectiveCount();
|
int total = action.effectiveCount();
|
||||||
int delay = Math.max(0, action.delayTicks);
|
int delay = Math.max(0, action.delayTicks);
|
||||||
for (int i = 0; i < total && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < total && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
action.sendOne(mc);
|
action.sendOne(mc);
|
||||||
if (delay > 0 && i + 1 < total) waitTicks(delay);
|
if (delay > 0 && i + 1 < total) waitTicks(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void waitForUseItemFinish(Minecraft mc, int fallbackTicks) throws InterruptedException {
|
private static void waitForUseItemFinish(Minecraft mc, int fallbackTicks) throws InterruptedException {
|
||||||
if (mc == null || !MacroExecutor.isCurrentRunActive()) return;
|
if (mc == null || !MacroLifecycle.isCurrentRunActive()) return;
|
||||||
|
|
||||||
if (!Boolean.TRUE.equals(MacroClientThread.callOnClientThread(mc,
|
if (!Boolean.TRUE.equals(MacroClientThread.callOnClientThread(mc,
|
||||||
() -> mc.player != null && mc.player.isUsingItem(),
|
() -> mc.player != null && mc.player.isUsingItem(),
|
||||||
|
|
@ -508,7 +508,7 @@ final class MacroActionRunner {
|
||||||
0);
|
0);
|
||||||
int maxTicks = Math.max(8, remaining > 0 ? remaining + 8 : fallbackTicks + 8);
|
int maxTicks = Math.max(8, remaining > 0 ? remaining + 8 : fallbackTicks + 8);
|
||||||
maxTicks = Math.min(maxTicks, 72000);
|
maxTicks = Math.min(maxTicks, 72000);
|
||||||
for (int i = 0; i < maxTicks && MacroExecutor.isCurrentRunActive(); i++) {
|
for (int i = 0; i < maxTicks && MacroLifecycle.isCurrentRunActive(); i++) {
|
||||||
if (!Boolean.TRUE.equals(MacroClientThread.callOnClientThread(mc,
|
if (!Boolean.TRUE.equals(MacroClientThread.callOnClientThread(mc,
|
||||||
() -> mc.player != null && mc.player.isUsingItem(),
|
() -> mc.player != null && mc.player.isUsingItem(),
|
||||||
Boolean.FALSE))) {
|
Boolean.FALSE))) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ final class MacroBreak {
|
||||||
try {
|
try {
|
||||||
long lastAttemptTick = AutismSharedState.get().getClientTickCounter() - (delayTicks + 1L);
|
long lastAttemptTick = AutismSharedState.get().getClientTickCounter() - (delayTicks + 1L);
|
||||||
long lastSneakTick = Long.MIN_VALUE;
|
long lastSneakTick = Long.MIN_VALUE;
|
||||||
while (MacroExecutor.isCurrentRunActive() && isActionStillInCurrentMacro(action)) {
|
while (MacroLifecycle.isCurrentRunActive() && isActionStillInCurrentMacro(action)) {
|
||||||
|
|
||||||
if (action.sneak) {
|
if (action.sneak) {
|
||||||
long sneakTick = AutismSharedState.get().getClientTickCounter();
|
long sneakTick = AutismSharedState.get().getClientTickCounter();
|
||||||
|
|
@ -53,7 +53,7 @@ final class MacroBreak {
|
||||||
boolean isAir = isInstaBreakAir(mc, target);
|
boolean isAir = isInstaBreakAir(mc, target);
|
||||||
if (wasSolid && isAir) {
|
if (wasSolid && isAir) {
|
||||||
completed++;
|
completed++;
|
||||||
MacroExecutor.setCurrentStatus("InstaBreak " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
MacroLifecycle.setCurrentStatus("InstaBreak " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
||||||
if (targetTimes > 0 && completed >= targetTimes) return;
|
if (targetTimes > 0 && completed >= targetTimes) return;
|
||||||
wasSolid = false;
|
wasSolid = false;
|
||||||
} else if (!isAir) {
|
} else if (!isAir) {
|
||||||
|
|
@ -91,7 +91,7 @@ final class MacroBreak {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroExecutor.setCurrentStatus("InstaBreak " + target.getX() + "," + target.getY() + "," + target.getZ()
|
MacroLifecycle.setCurrentStatus("InstaBreak " + target.getX() + "," + target.getY() + "," + target.getZ()
|
||||||
+ " " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
+ " " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
||||||
|
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
|
|
@ -191,7 +191,7 @@ final class MacroBreak {
|
||||||
AutismInstaBreakRenderer.setTarget(target);
|
AutismInstaBreakRenderer.setTarget(target);
|
||||||
long lastTick = -1L;
|
long lastTick = -1L;
|
||||||
try {
|
try {
|
||||||
while (MacroExecutor.isCurrentRunActive() && isActionStillInCurrentMacro(action)) {
|
while (MacroLifecycle.isCurrentRunActive() && isActionStillInCurrentMacro(action)) {
|
||||||
long now = AutismSharedState.get().getClientTickCounter();
|
long now = AutismSharedState.get().getClientTickCounter();
|
||||||
if (now == lastTick) {
|
if (now == lastTick) {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
|
|
@ -225,13 +225,13 @@ final class MacroBreak {
|
||||||
MacroClientThread.runOnClientThread(mc, () -> sendBlockInteract(mc, target, direction), action.isTickAligned());
|
MacroClientThread.runOnClientThread(mc, () -> sendBlockInteract(mc, target, direction), action.isTickAligned());
|
||||||
}
|
}
|
||||||
completed++;
|
completed++;
|
||||||
MacroExecutor.setCurrentStatus("Break " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
MacroLifecycle.setCurrentStatus("Break " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
||||||
if (targetTimes > 0 && completed >= targetTimes) return;
|
if (targetTimes > 0 && completed >= targetTimes) return;
|
||||||
started[0] = false;
|
started[0] = false;
|
||||||
nextStepsFired[0] = false;
|
nextStepsFired[0] = false;
|
||||||
waitForBreakSolid(mc, target);
|
waitForBreakSolid(mc, target);
|
||||||
} else {
|
} else {
|
||||||
MacroExecutor.setCurrentStatus("Break " + target.getX() + "," + target.getY() + "," + target.getZ()
|
MacroLifecycle.setCurrentStatus("Break " + target.getX() + "," + target.getY() + "," + target.getZ()
|
||||||
+ " " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
+ " " + completed + "/" + (targetTimes == 0 ? "\u221e" : targetTimes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +253,7 @@ final class MacroBreak {
|
||||||
|
|
||||||
if (plan.instant() && plan.interactFirst()) {
|
if (plan.instant() && plan.interactFirst()) {
|
||||||
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return -1;
|
if (!MacroLifecycle.isCurrentRunActive()) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = MacroClientThread.callOnClientThread(mc, () -> startPreparedBreakOnClient(mc, action, pos, dir, started), -1, action.isTickAligned());
|
int result = MacroClientThread.callOnClientThread(mc, () -> startPreparedBreakOnClient(mc, action, pos, dir, started), -1, action.isTickAligned());
|
||||||
|
|
@ -326,11 +326,11 @@ final class MacroBreak {
|
||||||
InteractTiming timing = action.interactTiming;
|
InteractTiming timing = action.interactTiming;
|
||||||
if (timing == InteractTiming.BEFORE && plan.breaksNextTick()) {
|
if (timing == InteractTiming.BEFORE && plan.breaksNextTick()) {
|
||||||
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return -1;
|
if (!MacroLifecycle.isCurrentRunActive()) return -1;
|
||||||
}
|
}
|
||||||
if (timing == InteractTiming.WITH && plan.breaksThisTick()) {
|
if (timing == InteractTiming.WITH && plan.breaksThisTick()) {
|
||||||
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return -1;
|
if (!MacroLifecycle.isCurrentRunActive()) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = MacroClientThread.callOnClientThread(mc, () -> continueBreakOnClient(mc, action, pos, dir), -1, action.isTickAligned());
|
int result = MacroClientThread.callOnClientThread(mc, () -> continueBreakOnClient(mc, action, pos, dir), -1, action.isTickAligned());
|
||||||
|
|
@ -396,7 +396,7 @@ final class MacroBreak {
|
||||||
int broke;
|
int broke;
|
||||||
if (action.interactCustomMs < 0) {
|
if (action.interactCustomMs < 0) {
|
||||||
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
runBreakNextStepsOnce(mc, action, nextStepsFired, missingNextStepsWarned);
|
||||||
if (!MacroExecutor.isCurrentRunActive()) return -1;
|
if (!MacroLifecycle.isCurrentRunActive()) return -1;
|
||||||
if (ns > 0) java.util.concurrent.locks.LockSupport.parkNanos(ns);
|
if (ns > 0) java.util.concurrent.locks.LockSupport.parkNanos(ns);
|
||||||
broke = MacroClientThread.callOnClientThread(mc, () -> breakAndDetectOnClient(mc, pos, dir), -1, action.isTickAligned());
|
broke = MacroClientThread.callOnClientThread(mc, () -> breakAndDetectOnClient(mc, pos, dir), -1, action.isTickAligned());
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -475,13 +475,13 @@ final class MacroBreak {
|
||||||
if (fired != null) fired[0] = true;
|
if (fired != null) fired[0] = true;
|
||||||
action.markNextActionsRan();
|
action.markNextActionsRan();
|
||||||
String names = actions.size() == 1 ? actions.get(0).getDisplayName() : actions.size() + " steps";
|
String names = actions.size() == 1 ? actions.get(0).getDisplayName() : actions.size() + " steps";
|
||||||
MacroExecutor.setCurrentStatus("Break: next " + names);
|
MacroLifecycle.setCurrentStatus("Break: next " + names);
|
||||||
AutismModule module = AutismModule.get();
|
AutismModule module = AutismModule.get();
|
||||||
boolean previousSuppressPostGui = Boolean.TRUE.equals(MacroExecutor.SUPPRESS_POST_GUI_AFTER.get());
|
boolean previousSuppressPostGui = Boolean.TRUE.equals(MacroExecutor.SUPPRESS_POST_GUI_AFTER.get());
|
||||||
try {
|
try {
|
||||||
MacroExecutor.SUPPRESS_POST_GUI_AFTER.set(true);
|
MacroExecutor.SUPPRESS_POST_GUI_AFTER.set(true);
|
||||||
for (MacroAction next : actions) {
|
for (MacroAction next : actions) {
|
||||||
if (next == null || !next.isEnabled() || !MacroExecutor.isCurrentRunActive()) continue;
|
if (next == null || !next.isEnabled() || !MacroLifecycle.isCurrentRunActive()) continue;
|
||||||
try {
|
try {
|
||||||
MacroDispatcher.executeSingleActionWithWaits(mc, next, module);
|
MacroDispatcher.executeSingleActionWithWaits(mc, next, module);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -524,7 +524,7 @@ final class MacroBreak {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void waitForBreakSolid(Minecraft mc, BlockPos pos) throws InterruptedException {
|
private static void waitForBreakSolid(Minecraft mc, BlockPos pos) throws InterruptedException {
|
||||||
while (MacroExecutor.isCurrentRunActive()) {
|
while (MacroLifecycle.isCurrentRunActive()) {
|
||||||
if (!isInstaBreakAir(mc, pos)) return;
|
if (!isInstaBreakAir(mc, pos)) return;
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
}
|
}
|
||||||
|
|
@ -532,7 +532,7 @@ final class MacroBreak {
|
||||||
|
|
||||||
private static void waitBreakClientTicks(int ticks) throws InterruptedException {
|
private static void waitBreakClientTicks(int ticks) throws InterruptedException {
|
||||||
long start = AutismSharedState.get().getClientTickCounter();
|
long start = AutismSharedState.get().getClientTickCounter();
|
||||||
while (MacroExecutor.isCurrentRunActive() && (AutismSharedState.get().getClientTickCounter() - start) < ticks) {
|
while (MacroLifecycle.isCurrentRunActive() && (AutismSharedState.get().getClientTickCounter() - start) < ticks) {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -543,6 +543,6 @@ final class MacroBreak {
|
||||||
|
|
||||||
private static void releaseMacroSneak(Minecraft mc, String mode) {
|
private static void releaseMacroSneak(Minecraft mc, String mode) {
|
||||||
autismclient.util.AutismMacroSneak.release(mc, mode);
|
autismclient.util.AutismMacroSneak.release(mc, mode);
|
||||||
if (!autismclient.util.AutismMacroSneak.isPacket(mode)) MacroExecutor.applyAggregateSneakState(mc);
|
if (!autismclient.util.AutismMacroSneak.isPacket(mode)) MacroLifecycle.applyAggregateSneakState(mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,11 +172,11 @@ final class MacroCaptureAutofill {
|
||||||
if (action.autofillCacheList) {
|
if (action.autofillCacheList) {
|
||||||
CachedSuggestions listCache = SUGGESTION_CACHE.get(query);
|
CachedSuggestions listCache = SUGGESTION_CACHE.get(query);
|
||||||
if (listCache != null && listCache.connection() == connection && !listCache.suggestions().isEmpty()) {
|
if (listCache != null && listCache.connection() == connection && !listCache.suggestions().isEmpty()) {
|
||||||
MacroExecutor.setCurrentStatus("Using cached suggestions");
|
MacroLifecycle.setCurrentStatus("Using cached suggestions");
|
||||||
applyCaptureSuggestions(run, action, listCache.suggestions(), query);
|
applyCaptureSuggestions(run, action, listCache.suggestions(), query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MacroExecutor.setCurrentStatus("Sweeping command suggestions");
|
MacroLifecycle.setCurrentStatus("Sweeping command suggestions");
|
||||||
java.util.List<String> all = sweepAutofillCommand(connection, query);
|
java.util.List<String> all = sweepAutofillCommand(connection, query);
|
||||||
if (all.isEmpty()) return;
|
if (all.isEmpty()) return;
|
||||||
if (SUGGESTION_CACHE.size() >= SUGGESTION_CACHE_MAX) SUGGESTION_CACHE.clear();
|
if (SUGGESTION_CACHE.size() >= SUGGESTION_CACHE_MAX) SUGGESTION_CACHE.clear();
|
||||||
|
|
@ -191,13 +191,13 @@ final class MacroCaptureAutofill {
|
||||||
|
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
|
|
||||||
MacroExecutor.setCurrentStatus("Using cached suggestions");
|
MacroLifecycle.setCurrentStatus("Using cached suggestions");
|
||||||
applyCaptureSuggestions(run, action, capturePool(connection, action, query, cached.suggestions()), query);
|
applyCaptureSuggestions(run, action, capturePool(connection, action, query, cached.suggestions()), query);
|
||||||
fireSuggestionFetch(connection, query, action.autofillTimeoutMs);
|
fireSuggestionFetch(connection, query, action.autofillTimeoutMs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroExecutor.setCurrentStatus("Requesting command suggestions");
|
MacroLifecycle.setCurrentStatus("Requesting command suggestions");
|
||||||
PendingFetch pending = fireSuggestionFetch(connection, query, action.autofillTimeoutMs);
|
PendingFetch pending = fireSuggestionFetch(connection, query, action.autofillTimeoutMs);
|
||||||
if (pending == null) return;
|
if (pending == null) return;
|
||||||
if (!MacroRace.waitForFutureDone(pending.future(), 0)) return;
|
if (!MacroRace.waitForFutureDone(pending.future(), 0)) return;
|
||||||
|
|
@ -210,7 +210,7 @@ final class MacroCaptureAutofill {
|
||||||
autismclient.util.AutismNameHarvest.Control control = new autismclient.util.AutismNameHarvest.Control() {
|
autismclient.util.AutismNameHarvest.Control control = new autismclient.util.AutismNameHarvest.Control() {
|
||||||
@Override public boolean cancelled() {
|
@Override public boolean cancelled() {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
return !MacroExecutor.isCurrentRunActive() || mc == null || mc.getConnection() != connection;
|
return !MacroLifecycle.isCurrentRunActive() || mc == null || mc.getConnection() != connection;
|
||||||
}
|
}
|
||||||
@Override public boolean paused() { return false; }
|
@Override public boolean paused() { return false; }
|
||||||
@Override public int limit() { return MAX_SWEEP_NAMES; }
|
@Override public int limit() { return MAX_SWEEP_NAMES; }
|
||||||
|
|
@ -230,11 +230,11 @@ final class MacroCaptureAutofill {
|
||||||
String cacheKey = " | |||||||