-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bfb95f
commit 0b72f1b
Showing
7 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/ru/hollowhorizon/hollowengine/common/compat/ftbquests/FTBQuestsSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/ru/hollowhorizon/hollowengine/common/compat/ftbquests/StoryEventTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() + "%" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters