Prevent Action Crashing

This commit is contained in:
Kam committed 2025-05-15 20:45:22 -04:00
1 parent b34fb1a226
commit 8952963c74
3 files changed
+37 -16

No files matched your search

@@ -69,8 +69,14 @@ public class Action implements IAction {
return;
}
if (ticksExisted % updateEveryXTick == 0 && task != null) {
task.accept(this);
count++;
try {
task.accept(this);
count++;
} catch (Throwable t) {
System.err.println("Scripted action '" + name + "' threw an exception:");
t.printStackTrace();
markDone();
}
}
duration++;
}
@@ -48,23 +48,38 @@ public class ConditionalAction extends Action implements IConditionalAction {
@Override
public void tick(int ticksExisted) {
if (isDone()) return;
if (ticksExisted % updateEveryXTick == 0) {
checkCount++;
boolean terminated = terminateWhen != null && terminateWhen.get();
if (terminated && onTermination != null)
onTermination.accept(this);
if ((maxChecks >= 0 && checkCount > maxChecks) || terminated) {
markDone();
return;
}
try {
if (ticksExisted % updateEveryXTick == 0) {
checkCount++;
boolean terminated = terminateWhen != null && terminateWhen.get();
if (condition != null && condition.get()) {
task.accept(this);
taskExecuted = true;
if (terminated && onTermination != null) {
try {
onTermination.accept(this);
} catch (Throwable t) {
System.err.println("Error in onTermination for conditional '" + getName() + "':");
t.printStackTrace();
}
}
if ((maxChecks >= 0 && checkCount > maxChecks) || terminated) {
markDone();
return;
}
if (condition != null && condition.get()) {
task.accept(this);
taskExecuted = true;
}
}
} catch (Throwable t) {
System.err.println("Scripted conditional '" + getName() + "' threw an exception:");
t.printStackTrace();
markDone();
} finally {
duration++;
}
duration++;
}
@Override