Skip to content

Commit

Permalink
loop fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowHorizon committed Feb 6, 2024
1 parent 675091e commit 46f1278
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ class ConditionNode(
private val ifTasks: List<Node>,
private val elseTasks: MutableList<Node>
) : Node(), HasInnerNodes {
val initialCondition by lazy { condition() }
var index = 0
private val isEnd get() = index >= if (initialCondition) ifTasks.size else elseTasks.size
override val currentNode get() = if (initialCondition) ifTasks[index] else elseTasks[index]
private val isEnd get() = index >= if (condition()) ifTasks.size else elseTasks.size
override val currentNode get() = if (condition()) ifTasks[index] else elseTasks[index]

fun setElseTasks(tasks: List<Node>) {
elseTasks.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ class NpcLookToEntityNode(npcConsumer: NPCProperty, var target: () -> Entity?, v
return ticks-- > 0
}

override fun serializeNBT() = CompoundTag().apply {
val entity = target() ?: return@apply

putString("level", entity.level.dimension().location().toString())
putUUID("target", entity.uuid)
}
override fun serializeNBT() = CompoundTag()

override fun deserializeNBT(nbt: CompoundTag) {
val level = manager.server.getLevel(manager.server.levelKeys().find { it.location() == nbt.getString("level").rl } ?: return) ?: return
val entity = level.getEntity(nbt.getUUID("target")) ?: return
target = { entity }
}
}

Expand Down

0 comments on commit 46f1278

Please sign in to comment.