mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 02:37:27 +00:00
Added terminateWhen predicate for ConditionalAction
This commit is contained in:
1 parent
0fac6cf51e
commit
3e63a9ec94
2 files changed
+13
-2
No files matched your search
@@ -104,6 +104,11 @@ public class ScriptedActionManager implements IActionManager {
|
||||
scheduleAction(new ConditionalAction(name, checkIntervalTicks, predicate, task, maxChecks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleConditionalAction(String name, int checkIntervalTicks, Supplier<Boolean> predicate, Supplier<Boolean> terminateWhen, Consumer<IAction> task, int maxChecks) {
|
||||
scheduleAction(new ConditionalAction(name, checkIntervalTicks, predicate, terminateWhen, task, maxChecks));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call once per tick from your main loop.
|
||||
*
|
||||
@@ -261,6 +266,7 @@ public class ScriptedActionManager implements IActionManager {
|
||||
|
||||
private class ConditionalAction extends ActionBase {
|
||||
private final Supplier<Boolean> predicate;
|
||||
private Supplier<Boolean> terminate;
|
||||
private final int maxChecks;
|
||||
private int checkCount = 0;
|
||||
|
||||
@@ -275,12 +281,17 @@ public class ScriptedActionManager implements IActionManager {
|
||||
this.maxChecks = maxChecks;
|
||||
}
|
||||
|
||||
public ConditionalAction(String name, int checkIntervalTicks, Supplier<Boolean> predicate, Supplier<Boolean> terminate, Consumer<IAction> task, int maxChecks) {
|
||||
this(name, checkIntervalTicks, predicate, task, maxChecks);
|
||||
this.terminate = terminate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(int ticksExisted) {
|
||||
if (isDone()) return;
|
||||
if (ticksExisted % updateEveryXTick == 0) {
|
||||
checkCount++;
|
||||
if (maxChecks >= 0 && checkCount > maxChecks) {
|
||||
if ((maxChecks >= 0 && checkCount > maxChecks) || terminate.get()) {
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user