Skip to content

Commit

Permalink
big refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowHorizon committed Feb 5, 2024
1 parent 2e5a0c1 commit 1bfb95f
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 323 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ dependencies {
implementation(fg.deobf("curse.maven:embeddium-908741:4984830"))
implementation(fg.deobf("curse.maven:oculus-581495:4763262"))
implementation(fg.deobf("curse.maven:spark-361579:4505309"))
implementation(fg.deobf("curse.maven:firstperson:2.3.2"))
implementation(fg.deobf("curse.maven:item-filters-309674:4553326"))
implementation(fg.deobf("curse.maven:ftb-quests-forge-289412:5060506"))

implementation(kotlin("script-runtime"))
implementation(kotlin("scripting-jvm-host"))
Expand Down
Binary file removed hc/hc-1.18.2-1.2.1.jar
Binary file not shown.
Binary file modified hc/hc-1.19.2-1.4.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.ftb.mods.ftbteams.FTBTeamsAPI
import dev.ftb.mods.ftbteams.data.Team
import dev.ftb.mods.ftbteams.event.TeamEvent
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerPlayer
import net.minecraft.stats.Stats
import net.minecraftforge.event.TickEvent.ServerTickEvent
Expand All @@ -13,6 +14,8 @@ import net.minecraftforge.event.server.ServerStoppingEvent
import net.minecraftforge.server.ServerLifecycleHooks
import ru.hollowhorizon.hc.api.utils.HollowConfig
import ru.hollowhorizon.hc.client.utils.isLogicalClient
import ru.hollowhorizon.hc.client.utils.mcText
import ru.hollowhorizon.hc.client.utils.mcTranslate
import ru.hollowhorizon.hollowengine.common.files.DirectoryManager
import ru.hollowhorizon.hollowengine.common.files.DirectoryManager.fromReadablePath
import ru.hollowhorizon.hollowengine.common.scripting.StoryLogger
Expand Down Expand Up @@ -54,7 +57,22 @@ object StoryHandler {
isStoryPlaying = true
events.forEach { (team, stories) ->
stories
.filter { it.value.tick(event); it.value.isEnded }
.filter {
try {
it.value.tick(event)
it.value.isEnded
} catch (exception: Exception) {
team.onlineMembers.forEach { player ->
player.sendSystemMessage(Component.translatable("hollowengine.executing_error", it.key))
player.sendSystemMessage("${exception.message}".mcText)
player.sendSystemMessage("hollowengine.check_logs".mcTranslate)
}

StoryLogger.LOGGER.error("(HollowEngine) Error while executing event \"${it.key}\"", exception)

return@filter true
}
}
.map { it.key }
.onEach { StoryLogger.LOGGER.info("Finished event \"{}\", for team \"{}\".", it, team) }
.forEach(stories::remove)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import ru.hollowhorizon.hc.client.utils.rl
import ru.hollowhorizon.hc.common.capabilities.CapabilityInstance
import ru.hollowhorizon.hc.common.capabilities.HollowCapabilityV2
import ru.hollowhorizon.hollowengine.common.entities.NPCEntity
import java.util.UUID

@HollowCapabilityV2(NPCEntity::class)
class NPCCapability: CapabilityInstance() {
var hitboxMode by syncable(HitboxMode.PULLING)
var icon by syncable(NpcIcon.EMPTY)
var teamUUID by syncable(UUID.randomUUID().toString())
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ru.hollowhorizon.hollowengine.common.files.DirectoryManager.toReadablePat
import ru.hollowhorizon.hollowengine.common.scripting.StoryLogger
import ru.hollowhorizon.hollowengine.common.scripting.story.coroutines.ScriptContext
import java.io.File
import kotlin.script.experimental.api.ResultValue
import kotlin.script.experimental.api.ResultWithDiagnostics
import kotlin.script.experimental.api.constructorArgs
import kotlin.script.experimental.api.valueOrThrow
Expand All @@ -23,42 +24,52 @@ import kotlin.script.experimental.jvm.util.isError

fun runScript(server: MinecraftServer, team: Team, file: File, isCommand: Boolean = false) =
ScriptContext.scope.async(ScriptContext.scriptContext) {
try {
StoryLogger.LOGGER.info("Starting event \"{}\", for team \"{}\".", file.toReadablePath(), team.name.string)
val shouldRecompile = ScriptingCompiler.shouldRecompile(file) || isCommand
val story = ScriptingCompiler.compileFile<StoryScript>(file)

story.errors?.let { errors ->
errors.forEach { error ->
team.onlineMembers.forEach {
StoryLogger.LOGGER.error(error.replace("\\r\\n", "\n"))
it.sendSystemMessage("§c[ERROR]§r $error".mcText)
}
StoryLogger.LOGGER.info("Starting event \"{}\", for team \"{}\".", file.toReadablePath(), team.name.string)
val shouldRecompile = ScriptingCompiler.shouldRecompile(file) || isCommand
val story = ScriptingCompiler.compileFile<StoryScript>(file)

story.errors?.let { errors ->
errors.forEach { error ->
team.onlineMembers.forEach {
StoryLogger.LOGGER.error(error.replace("\\r\\n", "\n"))
it.sendSystemMessage("§c[ERROR]§r $error".mcText)
}
return@async
}
return@async
}

val res = story.execute {
constructorArgs(server, team)
jvm {
loadDependencies(false)
}
val res = story.execute {
constructorArgs(server, team)
jvm {
loadDependencies(false)
}
}

if (res.isError()) {
val returnValue = res.valueOrThrow().returnValue

when {
res.isError() -> {
(res as ResultWithDiagnostics.Failure).errors().forEach { error ->
team.onlineMembers.forEach { it.sendSystemMessage("§c[ERROR]§r $error".mcText) }
}
} else {
}

returnValue is ResultValue.Error -> {
val error = returnValue.error
team.onlineMembers.forEach {
it.sendSystemMessage(Component.translatable("hollowengine.executing_error", file.toReadablePath()))
it.sendSystemMessage("${error.message}".mcText)
it.sendSystemMessage("hollowengine.check_logs".mcTranslate)
}

StoryLogger.LOGGER.error("(HollowEngine) Error while executing event \"${file.toReadablePath()}\"", error)
}

else -> {
val resScript = res.valueOrThrow().returnValue.scriptInstance as StoryStateMachine
StoryHandler.addStoryEvent(file.toReadablePath(), resScript, shouldRecompile)
}
} catch (e: Exception) {
team.onlineMembers.forEach {
it.sendSystemMessage(Component.translatable("hollowengine.executing_error", file.toReadablePath()))
it.sendSystemMessage("${e.message}".mcText)
it.sendSystemMessage("hollowengine.check_logs".mcTranslate)
}
HollowCore.LOGGER.error("(HollowEngine) Error while executing event \"${file.toReadablePath()}\"", e)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class StoryStateMachine(val server: MinecraftServer, val team: Team) : ICon
internal var currentIndex = 0
val asyncNodeIds = ArrayList<Int>()
var isStarted = false
val isEnded get() = currentIndex >= nodes.size && asyncNodeIds.isEmpty()
val isEnded get() = currentIndex >= nodes.size && asyncNodeIds.isEmpty() && onTickTasks.isEmpty()


fun tick(event: ServerTickEvent) {
Expand Down
Loading

0 comments on commit 1bfb95f

Please sign in to comment.