Skip to content

Commit

Permalink
ftb quests support
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowHorizon committed Feb 5, 2024
1 parent 1bfb95f commit 0b72f1b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ru/hollowhorizon/hollowengine/HollowEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ru.hollowhorizon.hollowengine.client.camera.ScreenShakeHandler
import ru.hollowhorizon.hollowengine.client.shaders.ModShaders
import ru.hollowhorizon.hollowengine.common.commands.HECommands
import ru.hollowhorizon.hollowengine.common.commands.HEStoryCommands
import ru.hollowhorizon.hollowengine.common.compat.ftbquests.FTBQuestsSupport
import ru.hollowhorizon.hollowengine.common.data.HollowStoryPack
import ru.hollowhorizon.hollowengine.common.events.StoryEngineSetup
import ru.hollowhorizon.hollowengine.common.files.DirectoryManager
Expand All @@ -44,6 +45,9 @@ import thedarkcolour.kotlinforforge.forge.MOD_BUS
class HollowEngine {
init {
getModScripts().forEach(::runModScript)

if(ModList.get().isLoaded("ftbquests")) FTBQuestsSupport

val forgeBus = MinecraftForge.EVENT_BUS
HollowCore.LOGGER.info("HollowEngine mod loading...")
forgeBus.addListener(::registerCommands)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.hollowhorizon.hollowengine.common.compat.ftbquests

import dev.ftb.mods.ftblibrary.icon.Icons
import dev.ftb.mods.ftbquests.quest.task.TaskTypes
import ru.hollowhorizon.hc.client.utils.rl
import ru.hollowhorizon.hollowengine.HollowEngine.Companion.MODID

object FTBQuestsSupport {
val STORY_EVENT = TaskTypes.register("$MODID:story_event".rl, ::StoryEventTask) { Icons.NOTES }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package ru.hollowhorizon.hollowengine.common.compat.ftbquests

import dev.ftb.mods.ftblibrary.config.ConfigGroup
import dev.ftb.mods.ftbquests.events.QuestProgressEventData
import dev.ftb.mods.ftbquests.quest.Quest
import dev.ftb.mods.ftbquests.quest.TeamData
import dev.ftb.mods.ftbquests.quest.task.Task
import dev.ftb.mods.ftbquests.quest.task.TaskType
import dev.ftb.mods.ftbteams.FTBTeamsAPI
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.FriendlyByteBuf
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.item.ItemStack
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.api.distmarker.OnlyIn
import net.minecraftforge.server.ServerLifecycleHooks
import ru.hollowhorizon.hc.client.utils.mcTranslate
import ru.hollowhorizon.hollowengine.common.events.StoryHandler
import ru.hollowhorizon.hollowengine.common.files.DirectoryManager.fromReadablePath
import ru.hollowhorizon.hollowengine.common.scripting.story.runScript
import java.time.LocalDateTime
import java.util.Date


class StoryEventTask(quest: Quest) : Task(quest) {
var storyEventName = ""
var lastCheckExists = false
override fun getType(): TaskType = FTBQuestsSupport.STORY_EVENT

override fun writeData(nbt: CompoundTag) {
super.writeData(nbt)
nbt.putString("story_event", storyEventName)
}

override fun readData(nbt: CompoundTag) {
super.readData(nbt)
storyEventName = nbt.getString("story_event")
}


override fun writeNetData(buffer: FriendlyByteBuf) {
super.writeNetData(buffer)
buffer.writeUtf(storyEventName)
}

override fun readNetData(buffer: FriendlyByteBuf) {
super.readNetData(buffer)
storyEventName = buffer.readUtf()
}

@OnlyIn(Dist.CLIENT)
override fun getConfig(config: ConfigGroup) {
super.getConfig(config)
config.addString("story_event", storyEventName, { input: String -> storyEventName = input }, "")
}

override fun getAltTitle() = storyEventName.mcTranslate

override fun getMaxProgress(): Long {
return 1L
}

override fun autoSubmitOnPlayerTick(): Int {
return 20
}

override fun submitTask(teamData: TeamData, player: ServerPlayer, craftedItem: ItemStack) {
if (teamData.isCompleted(this)) return
val team = FTBTeamsAPI.getManager().getTeamByID(teamData.uuid) ?: return

val hasEvent = StoryHandler.getActiveEvents(team).contains(storyEventName)

if(!lastCheckExists && !hasEvent) {
runScript(ServerLifecycleHooks.getCurrentServer(), team, storyEventName.fromReadablePath())
}

teamData.setProgress(this, if(!hasEvent && lastCheckExists) 1L else 0L)

lastCheckExists = hasEvent
}

override fun onStarted(data: QuestProgressEventData<*>) {
super.onStarted(data)
val team = FTBTeamsAPI.getManager().getTeamByID(data.teamData.uuid) ?: return


}

override fun formatProgress(teamData: TeamData, progress: Long): String {
val team = FTBTeamsAPI.getManager().getTeamByID(teamData.uuid) ?: return "???"
val event = StoryHandler.getEventByName(team, storyEventName) ?: return "???"
val realProgress = (event.currentIndex / event.nodes.size.toFloat()) * 100f
return realProgress.toInt().toString() + "%"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ object StoryHandler {
runScript(ServerLifecycleHooks.getCurrentServer(), team, eventPath.fromReadablePath())
}

fun getEventByName(team: Team, name: StoryStateMachine) = events[team]?.entries?.find { it.value == name }?.key
fun getEventByScript(team: Team, name: StoryStateMachine) = events[team]?.entries?.find { it.value == name }?.key

fun getEventByName(team: Team, name: String) = events[team]?.get(name)

@JvmStatic
fun onPlayerJoin(event: PlayerEvent.PlayerLoggedInEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ru.hollowhorizon.hollowengine.common.scripting.story.nodes.base

import net.minecraft.commands.CommandSigningContext
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import ru.hollowhorizon.hc.client.utils.mcText
import ru.hollowhorizon.hollowengine.common.events.StoryHandler
import ru.hollowhorizon.hollowengine.common.files.DirectoryManager.fromReadablePath
import ru.hollowhorizon.hollowengine.common.scripting.StoryLogger
Expand Down Expand Up @@ -50,7 +48,7 @@ fun IContextBuilder.stopScript(file: () -> String) = next {

fun IContextBuilder.restartScript() = next {
val team = this@restartScript.stateMachine.team
StoryHandler.getEventByName(team, this@restartScript.stateMachine)?.let {
StoryHandler.getEventByScript(team, this@restartScript.stateMachine)?.let {
StoryHandler.restartEvent(team, it)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/hollowengine/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
"hollowengine.npc_choicer.timecore": "Adds models from BlockBench, including animated. Supported formats:",
"hollowengine.npc_choicer.vanilla": "Adds models that other mobs in the game already have, so far only vanilla ones.",
"hollowengine.progress_manager.event_list": "Event List",
"hollowengine.progress_manager.no_tasks": "No tasks yet, maybe they will appear later!"
"hollowengine.progress_manager.no_tasks": "No tasks yet, maybe they will appear later!",
"ftbquests.task.hollowengine.story_event": "Story Event",
"ftbquests.task.hollowengine.story_event.story_event": "Script file path"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/hollowengine/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@
"hollowengine.progress_manager.event_list": "Список событий",
"hollowengine.progress_manager.no_tasks": "Заданий пока нет, возможно они появятся позже!",
"hollowengine.input_model_path": "Введите путь к модели:",
"hollowengine.model_edit.text": "текст"
"hollowengine.model_edit.text": "текст",
"ftbquests.task.hollowengine.story_event": "Сюжетное событие",
"ftbquests.task.hollowengine.story_event.story_event": "Путь к файлу скрипта"
}

0 comments on commit 0b72f1b

Please sign in to comment.