aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-09-28 12:45:56 +0200
committernea <romangraef@gmail.com>2022-09-28 12:45:56 +0200
commit4d73331a449f0b0647066f7dde0628730fe0e178 (patch)
tree047f463e13d14ea6cf9c8b37602a756f6880f9a0 /src
parentec66c82198fe2d61d699d553c1254f08b43fcc65 (diff)
downloadFirmament-4d73331a449f0b0647066f7dde0628730fe0e178.tar.gz
Firmament-4d73331a449f0b0647066f7dde0628730fe0e178.tar.bz2
Firmament-4d73331a449f0b0647066f7dde0628730fe0e178.zip
Fairy souls
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt23
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt22
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt29
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt13
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/ServerChatLineReceivedEvent.kt13
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/SkyblockServerUpdateEvent.kt13
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/events/WorldRenderLastEvent.kt22
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt27
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt93
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt2
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMessageHandler.kt33
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinWorldRenderer.kt41
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt2
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt131
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/Locraw.kt8
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/MC.kt7
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt63
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/config/ConfigHolder.kt60
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/config/IConfigHolder.kt75
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/config/ProfileSpecificConfigHolder.kt81
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt91
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/textutil.kt70
-rw-r--r--src/main/resources/assets/notenoughupdates/lang/en_us.json44
-rw-r--r--src/main/resources/hotswap-agent.properties2
-rw-r--r--src/main/resources/notenoughupdates.mixins.json24
25 files changed, 800 insertions, 189 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
index a2949a7..bf999bd 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
@@ -5,12 +5,8 @@ import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*
-import kotlinx.coroutines.*
-import kotlinx.serialization.json.Json
-import moe.nea.notenoughupdates.commands.registerNeuCommand
-import moe.nea.notenoughupdates.dbus.NEUDbusObject
-import moe.nea.notenoughupdates.repo.RepoManager
-import moe.nea.notenoughupdates.util.ConfigHolder
+import java.nio.file.Files
+import java.nio.file.Path
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
@@ -19,13 +15,18 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
-import net.minecraft.command.CommandRegistryAccess
import org.apache.logging.log4j.LogManager
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder
-import java.nio.file.Files
-import java.nio.file.Path
+import kotlinx.coroutines.*
+import kotlinx.serialization.json.Json
import kotlin.coroutines.EmptyCoroutineContext
+import net.minecraft.command.CommandRegistryAccess
+import moe.nea.notenoughupdates.commands.registerNeuCommand
+import moe.nea.notenoughupdates.dbus.NEUDbusObject
import moe.nea.notenoughupdates.features.FeatureManager
+import moe.nea.notenoughupdates.repo.RepoManager
+import moe.nea.notenoughupdates.util.SBData
+import moe.nea.notenoughupdates.util.config.IConfigHolder
object NotEnoughUpdates : ModInitializer, ClientModInitializer {
const val MOD_ID = "notenoughupdates"
@@ -59,7 +60,6 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
.build()
val coroutineScope =
CoroutineScope(EmptyCoroutineContext + CoroutineName("NotEnoughUpdates")) + SupervisorJob(globalJob)
- val coroutineScopeIo = coroutineScope + Dispatchers.IO + SupervisorJob(globalJob)
private fun registerCommands(
dispatcher: CommandDispatcher<FabricClientCommandSource>,
@@ -72,8 +72,9 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
override fun onInitialize() {
dbusConnection.requestBusName("moe.nea.notenoughupdates")
dbusConnection.exportObject(NEUDbusObject)
- ConfigHolder.registerEvents()
+ IConfigHolder.registerEvents()
RepoManager.initialize()
+ SBData.init()
FeatureManager.autoload()
ClientCommandRegistrationCallback.EVENT.register(this::registerCommands)
ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping {
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt b/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
index 55f2c50..6c75f20 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt
@@ -2,11 +2,12 @@ package moe.nea.notenoughupdates.commands
import com.mojang.brigadier.CommandDispatcher
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
+import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+import net.minecraft.text.Text
import moe.nea.notenoughupdates.gui.repoGui
import moe.nea.notenoughupdates.repo.RepoManager
+import moe.nea.notenoughupdates.util.SBData
import moe.nea.notenoughupdates.util.ScreenUtil.setScreenLater
-import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
-import net.minecraft.text.Text
fun neuCommand() = literal("neu") {
@@ -27,6 +28,23 @@ fun neuCommand() = literal("neu") {
setScreenLater(CottonClientScreen(repoGui()))
}
}
+ thenLiteral("dev") {
+ val sbData = thenLiteral("sbdata") {
+ thenExecute {
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.profile", SBData.profileCuteName))
+ val locrawInfo = SBData.locraw
+ if (locrawInfo == null) {
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.nolocraw"))
+ } else {
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.server", locrawInfo.server))
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.gametype", locrawInfo.gametype))
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.mode", locrawInfo.mode))
+ source.sendFeedback(Text.translatable("notenoughupdates.sbinfo.map", locrawInfo.map))
+ }
+
+ }
+ }
+ }
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt
index 278282e..81dc6fc 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt
@@ -1,7 +1,36 @@
package moe.nea.notenoughupdates.events
+/**
+ * An event that can be fired by a [NEUEventBus].
+ *
+ * Typically, that event bus is implemented as a companion object
+ *
+ * ```
+ * class SomeEvent : NEUEvent() {
+ * companion object : NEUEventBus<SomeEvent>()
+ * }
+ * ```
+ */
abstract class NEUEvent {
+ /**
+ * A [NEUEvent] that can be [cancelled]
+ */
abstract class Cancellable : NEUEvent() {
+ /**
+ * Cancels this is event.
+ *
+ * @see cancelled
+ */
+ fun cancel() {
+ cancelled = true
+ }
+
+ /**
+ * Whether this event is cancelled.
+ *
+ * Cancelled events will bypass handlers unless otherwise specified and will prevent the action that this
+ * event was originally fired for.
+ */
var cancelled: Boolean = false
}
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt
index eba71bc..7eb0ecd 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt
@@ -1,7 +1,14 @@
package moe.nea.notenoughupdates.events
import java.util.concurrent.CopyOnWriteArrayList
+import moe.nea.notenoughupdates.NotEnoughUpdates
+/**
+ * A pubsub event bus.
+ *
+ * [subscribe] to events [publish]ed on this event bus.
+ * Subscriptions may not necessarily be delivered in the order or registering.
+ */
open class NEUEventBus<T : NEUEvent> {
data class Handler<T>(val invocation: (T) -> Unit, val receivesCancelled: Boolean)
@@ -17,7 +24,11 @@ open class NEUEventBus<T : NEUEvent> {
fun publish(event: T): T {
for (function in toHandle) {
if (function.receivesCancelled || event !is NEUEvent.Cancellable || !event.cancelled) {
- function.invocation(event)
+ try {
+ function.invocation(event)
+ } catch (e: Exception) {
+ NotEnoughUpdates.logger.error("Caught exception during processing event $event", e)
+ }
}
}
return event
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/ServerChatLineReceivedEvent.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/ServerChatLineReceivedEvent.kt
new file mode 100644
index 0000000..681ec6c
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/ServerChatLineReceivedEvent.kt
@@ -0,0 +1,13 @@
+package moe.nea.notenoughupdates.events
+
+import net.minecraft.text.Text
+import moe.nea.notenoughupdates.util.unformattedString
+
+/**
+ * This event gets published whenever the client receives a chat message from the server.
+ */
+data class ServerChatLineReceivedEvent(val text: Text) : NEUEvent.Cancellable() {
+ companion object : NEUEventBus<ServerChatLineReceivedEvent>()
+
+ val unformattedString = text.unformattedString
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/SkyblockServerUpdateEvent.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/SkyblockServerUpdateEvent.kt
new file mode 100644
index 0000000..541b4c6
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/SkyblockServerUpdateEvent.kt
@@ -0,0 +1,13 @@
+package moe.nea.notenoughupdates.events
+
+import moe.nea.notenoughupdates.util.Locraw
+
+/**
+ * This event gets published whenever `/locraw` is queried and HyPixel returns a location different to the old one.
+ *
+ * **N.B.:** This event may get fired multiple times while on the server (for example, first to null, then to the
+ * correct location).
+ */
+data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : NEUEvent() {
+ companion object : NEUEventBus<SkyblockServerUpdateEvent>()
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/events/WorldRenderLastEvent.kt b/src/main/kotlin/moe/nea/notenoughupdates/events/WorldRenderLastEvent.kt
new file mode 100644
index 0000000..c230c9c
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/events/WorldRenderLastEvent.kt
@@ -0,0 +1,22 @@
+package moe.nea.notenoughupdates.events
+
+import net.minecraft.client.render.Camera
+import net.minecraft.client.render.GameRenderer
+import net.minecraft.client.render.LightmapTextureManager
+import net.minecraft.client.util.math.MatrixStack
+import net.minecraft.util.math.Matrix4f
+
+/**
+ * This event is called after all world rendering is done, but before any GUI rendering (including hand) has been done.
+ */
+data class WorldRenderLastEvent(
+ val matrices: MatrixStack,
+ val tickDelta: Float,
+ val renderBlockOutline: Boolean,
+ val camera: Camera,
+ val gameRenderer: GameRenderer,
+ val lightmapTextureManager: LightmapTextureManager,
+ val positionMatrix: Matrix4f,
+) : NEUEvent() {
+ companion object : NEUEventBus<WorldRenderLastEvent>()
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt
index 766cf1f..0ffaad5 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt
@@ -1,27 +1,42 @@
package moe.nea.notenoughupdates.features
+import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.features.world.FairySouls
-import moe.nea.notenoughupdates.util.ConfigHolder
+import moe.nea.notenoughupdates.util.config.ConfigHolder
object FeatureManager : ConfigHolder<FeatureManager.Config>(serializer(), "features", ::Config) {
+ @Serializable
data class Config(
val enabledFeatures: MutableMap<String, Boolean> = mutableMapOf()
)
private val features = mutableMapOf<String, NEUFeature>()
+ private var hasAutoloaded = false
+
+ init {
+ autoload()
+ }
+
fun autoload() {
- loadFeature(FairySouls)
+ synchronized(this) {
+ if (hasAutoloaded) return
+ loadFeature(FairySouls)
+ hasAutoloaded = true
+ }
}
fun loadFeature(feature: NEUFeature) {
- if (feature.identifier in features) {
- NotEnoughUpdates.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature")
- return
+ synchronized(features) {
+ if (feature.identifier in features) {
+ NotEnoughUpdates.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature")
+ return
+ }
+ features[feature.identifier] = feature
+ feature.onLoad()
}
- features[feature.identifier] = feature
}
fun isEnabled(identifier: String): Boolean? =
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt b/src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt
index b928f3d..9bd1a1f 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt
@@ -1,12 +1,103 @@
package moe.nea.notenoughupdates.features.world
+import io.github.moulberry.repo.data.Coordinate
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.serializer
+import net.minecraft.util.math.BlockPos
+import moe.nea.notenoughupdates.events.ServerChatLineReceivedEvent
+import moe.nea.notenoughupdates.events.SkyblockServerUpdateEvent
+import moe.nea.notenoughupdates.events.WorldRenderLastEvent
import moe.nea.notenoughupdates.features.NEUFeature
+import moe.nea.notenoughupdates.repo.RepoManager
+import moe.nea.notenoughupdates.util.MC
+import moe.nea.notenoughupdates.util.SBData
+import moe.nea.notenoughupdates.util.config.ProfileSpecificConfigHolder
+import moe.nea.notenoughupdates.util.render.RenderBlockContext.Companion.renderBlocks
+import moe.nea.notenoughupdates.util.unformattedString
+
+val Coordinate.blockPos: BlockPos
+ get() = BlockPos(x, y, z)
+
+object FairySouls : NEUFeature,
+ ProfileSpecificConfigHolder<FairySouls.Config>(serializer(), "fairy-souls.json", ::Config) {
+ @Serializable
+ data class Config(
+ val foundSouls: MutableMap<String, MutableSet<Int>> = mutableMapOf()
+ )
-object FairySouls : NEUFeature {
override val name: String get() = "Fairy Souls"
override val identifier: String get() = "fairy-souls"
+ val playerReach = 5
+ val playerReachSquared = playerReach * playerReach
+
+ var currentLocationName: String? = null
+ var currentLocationSouls: List<Coordinate> = emptyList()
+ var currentMissingSouls: List<Coordinate> = emptyList()
+
+ fun updateMissingSouls() {
+ currentMissingSouls = emptyList()
+ val c = config ?: return
+ val fi = c.foundSouls[currentLocationName] ?: setOf()
+ val cms = currentLocationSouls.toMutableList()
+ fi.asSequence().sortedDescending().filter { it in cms.indices }.forEach { cms.removeAt(it) }
+ currentMissingSouls = cms
+ }
+
+ fun updateWorldSouls() {
+ currentLocationSouls = emptyList()
+ val loc = currentLocationName ?: return
+ currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc] ?: return
+ }
+
+ fun findNearestClickableSoul(): Coordinate? {
+ val player = MC.player ?: return null
+ val pos = player.pos
+ val location = SBData.skyblockLocation ?: return null
+ val soulLocations: List<Coordinate> =
+ RepoManager.neuRepo.constants.fairySouls.soulLocations[location] ?: return null
+ return soulLocations
+ .map { it to it.blockPos.getSquaredDistance(pos) }
+ .filter { it.second < playerReachSquared }
+ .minByOrNull { it.second }
+ ?.first
+ }
+
+ private fun markNearestSoul() {
+ val nearestSoul = findNearestClickableSoul() ?: return
+ val c = config ?: return
+ val loc = currentLocationName ?: return
+ val idx = currentLocationSouls.indexOf(nearestSoul)
+ c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx)
+ markDirty()
+ updateMissingSouls()
+ }
+
+
override fun onLoad() {
+ SkyblockServerUpdateEvent.subscribe {
+ currentLocationName = it.newLocraw?.skyblockLocation
+ updateWorldSouls()
+ updateMissingSouls()
+ }
+ ServerChatLineReceivedEvent.subscribe {
+ when (it.text.unformattedString) {
+ "You have already found that Fairy Soul!" -> {
+ markNearestSoul()
+ }
+ "SOUL! You found a Fairy Soul!" -> {
+ markNearestSoul()
+ }
+ }
+ }
+ WorldRenderLastEvent.subscribe {
+ renderBlocks(it.camera) {
+ color(1F, 1F, 0F, 0.8F)
+ currentMissingSouls.forEach {
+ block(it.blockPos)
+ }
+ }
+ }
}
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
index 3792d80..a5453a9 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt
@@ -9,7 +9,7 @@ import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment
import io.github.cottonmc.cotton.gui.widget.data.Insets
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
import moe.nea.notenoughupdates.NotEnoughUpdates
-import moe.nea.notenoughupdates.util.ConfigHolder
+import moe.nea.notenoughupdates.util.config.ConfigHolder
import net.minecraft.text.Text
import kotlin.reflect.KMutableProperty1
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMessageHandler.kt b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMessageHandler.kt
new file mode 100644
index 0000000..b6151b9
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinMessageHandler.kt
@@ -0,0 +1,33 @@
+package moe.nea.notenoughupdates.mixins
+
+import org.spongepowered.asm.mixin.Mixin
+import org.spongepowered.asm.mixin.injection.At
+import org.spongepowered.asm.mixin.injection.Inject
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
+import net.minecraft.client.network.message.MessageHandler
+import net.minecraft.network.message.MessageType
+import net.minecraft.network.message.SignedMessage
+import net.minecraft.text.Text
+import moe.nea.notenoughupdates.events.ServerChatLineReceivedEvent
+
+@Mixin(MessageHandler::class)
+class MixinMessageHandler {
+ @Inject(method = ["onChatMessage"], at = [At("HEAD")], cancellable = true)
+ fun onOnChatMessage(message: SignedMessage, params: MessageType.Parameters, ci: CallbackInfo) {
+ val decoratedText = params.applyChatDecoration(message.unsignedContent.orElse(message.content))
+ val event = ServerChatLineReceivedEvent(decoratedText)
+ if (ServerChatLineReceivedEvent.publish(event).cancelled) {
+ ci.cancel()
+ }
+ }
+
+ @Inject(method = ["onGameMessage"], at = [At("HEAD")], cancellable = true)
+ fun onOnGameMessage(message: Text, overlay: Boolean, ci: CallbackInfo) {
+ if (!overlay) {
+ val event = ServerChatLineReceivedEvent(message)
+ if (ServerChatLineReceivedEvent.publish(event).cancelled) {
+ ci.cancel()
+ }
+ }
+ }
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinWorldRenderer.kt b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinWorldRenderer.kt
new file mode 100644
index 0000000..ac9ea15
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/mixins/MixinWorldRenderer.kt
@@ -0,0 +1,41 @@
+package moe.nea.notenoughupdates.mixins
+
+import org.spongepowered.asm.mixin.Mixin
+import org.spongepowered.asm.mixin.injection.At
+import org.spongepowered.asm.mixin.injection.Inject
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
+import net.minecraft.client.render.Camera
+import net.minecraft.client.render.GameRenderer
+import net.minecraft.client.render.LightmapTextureManager
+import net.minecraft.client.render.WorldRenderer
+import net.minecraft.client.util.math.MatrixStack
+import net.minecraft.util.math.Matrix4f
+import moe.nea.notenoughupdates.events.WorldRenderLastEvent
+
+@Mixin(WorldRenderer::class)
+class MixinWorldRenderer {
+
+ @Inject(
+ method = ["render"],
+ at = [At("INVOKE", target = "renderChunkDebugInfo", shift = At.Shift.AFTER)],
+ )
+ fun onWorldRenderLast(
+ matrices: MatrixStack,
+ tickDelta: Float,
+ arg2: Long,
+ renderBlockOutline: Boolean,
+ camera: Camera,
+ gameRenderer: GameRenderer,
+ lightmapTextureManager: LightmapTextureManager,
+ positionMatrix: Matrix4f,
+ ci: CallbackInfo
+ ) {
+ val event = WorldRenderLastEvent(
+ matrices, tickDelta, renderBlockOutline,
+ camera, gameRenderer, lightmapTextureManager,
+ positionMatrix
+ )
+ WorldRenderLastEvent.publish(event)
+ }
+
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
index 72603d9..26bca51 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
@@ -9,7 +9,7 @@ import kotlinx.serialization.serializer
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.NotEnoughUpdates.logger
import moe.nea.notenoughupdates.hud.ProgressBar
-import moe.nea.notenoughupdates.util.ConfigHolder
+import moe.nea.notenoughupdates.util.config.ConfigHolder
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.minecraft.client.MinecraftClient
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
deleted file mode 100644
index 50a3d9b..0000000
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
+++ /dev/null
@@ -1,131 +0,0 @@
-package moe.nea.notenoughupdates.util
-
-import java.io.IOException
-import java.nio.file.Path
-import java.util.concurrent.CopyOnWriteArrayList
-import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
-import kotlinx.serialization.KSerializer
-import kotlinx.serialization.SerializationException
-import kotlin.io.path.exists
-import kotlin.io.path.readText
-import kotlin.io.path.writeText
-import kotlin.reflect.KClass
-import net.minecraft.client.MinecraftClient
-import net.minecraft.server.command.CommandOutput
-import net.minecraft.text.Text
-import moe.nea.notenoughupdates.NotEnoughUpdates
-import moe.nea.notenoughupdates.events.ScreenOpenEvent
-
-abstract class ConfigHolder<T>(
- val serializer: KSerializer<T>,
- val name: String,
- val default: () -> T
-) {
-
- var config: T
- private set
-
- init {
- config = readValueOrDefault()
- putConfig(this::class, this)
- }
-
- val file: Path get() = NotEnoughUpdates.CONFIG_DIR.resolve("$name.json")
-
- protected fun readValueOrDefault(): T {
- if (file.exists())
- try {
- return NotEnoughUpdates.json.decodeFromString(
- serializer,
- file.readText()
- )
- } catch (e: IOException) {
- badLoads.add(name)
- NotEnoughUpdates.logger.error(
- "IO exception during loading of config file $name. This will reset this config.",
- e
- )
- } catch (e: SerializationException) {
- badLoads.add(name)
- NotEnoughUpdates.logger.error(
- "Serialization exception during loading of config file $name. This will reset this config.",
- e
- )
- }
- return default()
- }
-
- private fun writeValue(t: T) {
- file.writeText(NotEnoughUpdates.json.encodeToString(serializer, t))
- }
-
- fun save() {
- writeValue(config)
- }
-
- fun load() {
- config = readValueOrDefault()
- }
-
- fun markDirty() {
- Companion.markDirty(this::class)
- }
-
- companion object {
- private var badLoads: MutableList<String> = CopyOnWriteArrayList()
- private val allConfigs: MutableMap<KClass<out ConfigHolder<*>>, ConfigHolder<*>> = mutableMapOf()
- private val dirty: MutableSet<KClass<out ConfigHolder<*>>> = mutableSetOf()
-
- private fun <T : ConfigHolder<K>, K> putConfig(kClass: KClass<T>, inst: ConfigHolder<K>) {
- allConfigs[kClass] = inst
- }
-
- fun <T : ConfigHolder<K>, K> markDirty(kClass: KClass<T>) {
- if (kClass !in allConfigs) {
- NotEnoughUpdates.logger.error("Tried to markDirty '${kClass.qualifiedName}', which isn't registered as 'ConfigHolder'")
- return
- }
- dirty.add(kClass)
- }
-
- private fun performSaves() {
- val toSave = dirty.toList().also {
- dirty.clear()
- }
- for (it in toSave) {
- val obj = allConfigs[it]
- if (obj == null) {
- NotEnoughUpdates.logger.error("Tried to save '${it}', which isn't registered as 'ConfigHolder'")
- continue
- }
- obj.save()
- }
- }
-
- private fun warnForResetConfigs(player: CommandOutput) {
- if (badLoads.isNotEmpty()) {
- player.sendMessage(
- Text.literal(
- "The following configs have been reset: ${badLoads.joinToString(", ")}. " +
- "This can be intentional, but probably isn't."
- )
- )
- badLoads.clear()
- }
- }
-
- fun registerEvents() {
- ScreenOpenEvent.subscribe { event ->
- performSaves()
- val p = MinecraftClient.getInstance().player
- if (p != null) {
- warnForResetConfigs(p)
- }
- }
- ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping {
- performSaves()
- })
- }
-
- }
-}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/Locraw.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/Locraw.kt
new file mode 100644
index 0000000..400842f
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/Locraw.kt
@@ -0,0 +1,8 @@
+package moe.nea.notenoughupdates.util
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class Locraw(val server: String, val gametype: String? = null, val mode: String? = null, val map: String? = null) {
+ val skyblockLocation = if (gametype == "SKYBLOCK") mode else null
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/MC.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/MC.kt
new file mode 100644
index 0000000..da06c68
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/MC.kt
@@ -0,0 +1,7 @@
+package moe.nea.notenoughupdates.util
+
+import net.minecraft.client.MinecraftClient
+
+object MC {
+ inline val player get() = MinecraftClient.getInstance().player
+}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt
new file mode 100644
index 0000000..5391206
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt
@@ -0,0 +1,63 @@
+package moe.nea.notenoughupdates.util
+
+import dev.architectury.event.events.client.ClientPlayerEvent
+import kotlinx.serialization.SerializationException
+import kotlinx.serialization.decodeFromString
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
+import kotlin.time.ExperimentalTime
+import kotlin.time.TimeSource
+import moe.nea.notenoughupdates.NotEnoughUpdates
+import moe.nea.notenoughupdates.events.ServerChatLin