mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 22:19:40 +00:00
Heavy Action Refactoring
This commit is contained in:
1 parent
d3cae9e9cb
commit
ae4b4c8702
6 files changed
+464
-460
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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++), Integer.MAX_VALUE, offset, wrapper);
|
||||
a.setUpdateEveryXTick(1);
|
||||
scriptedActionManager.scheduleAction(a);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user