aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/Firmament.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/Firmament.kt')
-rw-r--r--src/main/kotlin/Firmament.kt67
1 files changed, 27 insertions, 40 deletions
diff --git a/src/main/kotlin/Firmament.kt b/src/main/kotlin/Firmament.kt
index 7bc7d44..68789f1 100644
--- a/src/main/kotlin/Firmament.kt
+++ b/src/main/kotlin/Firmament.kt
@@ -2,14 +2,6 @@ package moe.nea.firmament
import com.google.gson.Gson
import com.mojang.brigadier.CommandDispatcher
-import io.ktor.client.HttpClient
-import io.ktor.client.plugins.UserAgent
-import io.ktor.client.plugins.cache.HttpCache
-import io.ktor.client.plugins.compression.ContentEncoding
-import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
-import io.ktor.client.plugins.logging.LogLevel
-import io.ktor.client.plugins.logging.Logging
-import io.ktor.serialization.kotlinx.json.json
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Path
@@ -26,7 +18,6 @@ import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
-import org.spongepowered.asm.launch.MixinBootstrap
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@@ -36,8 +27,8 @@ import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import kotlin.coroutines.EmptyCoroutineContext
-import net.minecraft.command.CommandRegistryAccess
-import net.minecraft.util.Identifier
+import net.minecraft.commands.CommandBuildContext
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.commands.registerFirmamentCommand
import moe.nea.firmament.events.ClientInitEvent
import moe.nea.firmament.events.ClientStartedEvent
@@ -47,11 +38,13 @@ import moe.nea.firmament.events.ScreenRenderPostEvent
import moe.nea.firmament.events.TickEvent
import moe.nea.firmament.events.registration.registerFirmamentEvents
import moe.nea.firmament.features.FeatureManager
+import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader
+import moe.nea.firmament.impl.v1.FirmamentAPIImpl
import moe.nea.firmament.repo.HypixelStaticData
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData
-import moe.nea.firmament.util.data.IDataHolder
+import moe.nea.firmament.util.mc.InitLevel
import moe.nea.firmament.util.tr
object Firmament {
@@ -60,45 +53,38 @@ object Firmament {
val DEBUG = System.getProperty("firmament.debug") == "true"
val DATA_DIR: Path = Path.of(".firmament").also { Files.createDirectories(it) }
- val CONFIG_DIR: Path = Path.of("config/firmament").also { Files.createDirectories(it) }
val logger: Logger = LogManager.getLogger("Firmament")
private val metadata: ModMetadata by lazy {
FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().metadata
}
val version: Version by lazy { metadata.version }
+ private val DEFAULT_JSON_INDENT = " "
+
@OptIn(ExperimentalSerializationApi::class)
val json = Json {
prettyPrint = DEBUG
isLenient = true
allowTrailingComma = true
+ allowComments = true
ignoreUnknownKeys = true
encodeDefaults = true
+ prettyPrintIndent = if (prettyPrint) "\t" else DEFAULT_JSON_INDENT
+ }
+
+ /**
+ * FUCK two space indentation
+ */
+ val twoSpaceJson = Json(from = json) {
+ prettyPrint = true
+ prettyPrintIndent = " "
}
val gson = Gson()
val tightJson = Json(from = json) {
prettyPrint = false
- }
-
-
- val httpClient by lazy {
- HttpClient {
- install(ContentNegotiation) {
- json(json)
- }
- install(ContentEncoding) {
- gzip()
- deflate()
- }
- install(UserAgent) {
- agent = "Firmament/$version"
- }
- if (DEBUG)
- install(Logging) {
- level = LogLevel.INFO
- }
- install(HttpCache)
- }
+ // Reset pretty print indent back to default to prevent getting yelled at by json
+ prettyPrintIndent = DEFAULT_JSON_INDENT
+ explicitNulls = false
}
val globalJob = Job()
@@ -108,10 +94,10 @@ object Firmament {
private fun registerCommands(
dispatcher: CommandDispatcher<FabricClientCommandSource>,
@Suppress("UNUSED_PARAMETER")
- ctx: CommandRegistryAccess
+ ctx: CommandBuildContext
) {
- registerFirmamentCommand(dispatcher)
- CommandEvent.publish(CommandEvent(dispatcher, ctx, MC.networkHandler?.commandDispatcher))
+ registerFirmamentCommand(dispatcher, ctx)
+ CommandEvent.publish(CommandEvent(dispatcher, ctx, MC.networkHandler?.commands))
}
@JvmStatic
@@ -120,14 +106,14 @@ object Firmament {
@JvmStatic
fun onClientInitialize() {
+ InitLevel.bump(InitLevel.MC_INIT)
FeatureManager.subscribeEvents()
+ FirmamentConfigLoader.loadConfig()
ClientTickEvents.END_CLIENT_TICK.register(ClientTickEvents.EndTick { instance ->
TickEvent.publish(TickEvent(MC.currentTick++))
})
- IDataHolder.registerEvents()
RepoManager.initialize()
SBData.init()
- FeatureManager.autoload()
HypixelStaticData.spawnDataCollectionLoop()
ClientCommandRegistrationCallback.EVENT.register(this::registerCommands)
ClientLifecycleEvents.CLIENT_STARTED.register(ClientLifecycleEvents.ClientStarted {
@@ -138,6 +124,7 @@ object Firmament {
globalJob.cancel()
})
registerFirmamentEvents()
+ FirmamentAPIImpl.loadExtensions()
ItemTooltipCallback.EVENT.register { stack, context, type, lines ->
ItemTooltipEvent.publish(ItemTooltipEvent(stack, context, type, lines))
}
@@ -157,7 +144,7 @@ object Firmament {
}
- fun identifier(path: String) = Identifier.of(MOD_ID, path)
+ fun identifier(path: String) = ResourceLocation.fromNamespaceAndPath(MOD_ID, path)
inline fun <reified T : Any> tryDecodeJsonFromStream(inputStream: InputStream): Result<T> {
return runCatching {
json.decodeFromStream<T>(inputStream)