Files
CustomNPC-Plus/src/main/java/noppes/npcs/controllers/data/action/ActionChain.java
T

36 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package noppes.npcs.controllers.data.action;
import noppes.npcs.api.handler.data.IAction;
import noppes.npcs.api.handler.data.IActionChain;
import noppes.npcs.scripted.ScriptedActionManager;
import java.util.function.Consumer;
/**
* helper to build a back‐to‐back chain of one‐shot actions
*/
public class ActionChain implements IActionChain {
private final ScriptedActionManager scriptedActionManager;
private int offset = 0, index = 0;
public ActionChain(ScriptedActionManager scriptedActionManager) {
this.scriptedActionManager = scriptedActionManager;
}
/**
* schedule the next task ‘delay’ ticks after the previous one
*/
@Override
public IActionChain after(int delay, Consumer<IAction> task) {
offset += delay;
Consumer<IAction> wrapper = act -> {
task.accept(act);
act.markDone();
};
IAction a = scriptedActionManager.create("chain#" + (index++), offset, wrapper);
a.setUpdateEveryXTick(1);
scriptedActionManager.scheduleAction(a);
return this;
}
}