diff --git a/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/StoryStateMachine.kt b/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/StoryStateMachine.kt index 1e696564..1aac7b8d 100644 --- a/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/StoryStateMachine.kt +++ b/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/StoryStateMachine.kt @@ -21,6 +21,7 @@ import ru.hollowhorizon.hollowengine.common.scripting.story.nodes.base.serialize open class StoryStateMachine(val server: MinecraftServer, val team: Team) : IContextBuilder { val variables = ArrayList>() val startTasks = ArrayList<() -> Unit>() + val onTickTasks = ArrayList<() -> Unit>() var extra = CompoundTag() internal val nodes = ArrayList() internal val asyncNodes = ArrayList() @@ -33,7 +34,12 @@ open class StoryStateMachine(val server: MinecraftServer, val team: Team) : ICon fun tick(event: ServerTickEvent) { if (event.phase != TickEvent.Phase.END) return - asyncNodeIds.removeIf { !asyncNodes[it].tick() } + onTickTasks.forEach { it() } + onTickTasks.clear() + + val toRemove = asyncNodeIds.mapNotNull { if(!asyncNodes[it].tick()) it else null } + + toRemove.forEach(asyncNodeIds::remove) if(currentIndex >= nodes.size) return diff --git a/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/nodes/IContextBuilder.kt b/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/nodes/IContextBuilder.kt index 0c1c1174..2b863d7a 100644 --- a/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/nodes/IContextBuilder.kt +++ b/src/main/java/ru/hollowhorizon/hollowengine/common/scripting/story/nodes/IContextBuilder.kt @@ -684,11 +684,15 @@ interface IContextBuilder { } fun AsyncProperty.stop() = +SimpleNode { - stateMachine.asyncNodeIds.remove(this@stop.index) + stateMachine.onTickTasks += { + stateMachine.asyncNodeIds.remove(this@stop.index) + } } fun AsyncProperty.resume() = +SimpleNode { - stateMachine.asyncNodeIds.add(this@resume.index) + stateMachine.onTickTasks += { + stateMachine.asyncNodeIds.add(this@resume.index) + } } // @Serializable Крч, сам сделаешь. Просил сам сделать класс xD