From ead6762eb1c005914b05f9d3c29f334989c67513 Mon Sep 17 00:00:00 2001 From: nea Date: Tue, 16 May 2023 01:23:43 +0200 Subject: Replace references to NEU with Firmament --- src/main/kotlin/moe/nea/firmament/Firmament.kt | 92 ++++++++ src/main/kotlin/moe/nea/firmament/commands/dsl.kt | 81 +++++++ src/main/kotlin/moe/nea/firmament/commands/rome.kt | 66 ++++++ .../nea/firmament/dbus/FirmamentDbusInterface.kt | 11 + .../moe/nea/firmament/dbus/FirmamentDbusObject.kt | 21 ++ .../kotlin/moe/nea/firmament/events/NEUEvent.kt | 36 +++ .../kotlin/moe/nea/firmament/events/NEUEventBus.kt | 37 ++++ .../moe/nea/firmament/events/ParticleSpawnEvent.kt | 13 ++ .../moe/nea/firmament/events/ScreenOpenEvent.kt | 7 + .../events/ServerChatLineReceivedEvent.kt | 13 ++ .../firmament/events/SkyblockServerUpdateEvent.kt | 13 ++ .../moe/nea/firmament/events/WorldReadyEvent.kt | 5 + .../nea/firmament/events/WorldRenderLastEvent.kt | 22 ++ .../moe/nea/firmament/features/FeatureManager.kt | 53 +++++ .../moe/nea/firmament/features/NEUFeature.kt | 18 ++ .../firmament/features/fishing/FishingWarning.kt | 117 ++++++++++ .../moe/nea/firmament/features/world/FairySouls.kt | 120 ++++++++++ src/main/kotlin/moe/nea/firmament/gui/ConfigGui.kt | 94 ++++++++ .../moe/nea/firmament/gui/WGridPanelWithPadding.kt | 33 +++ src/main/kotlin/moe/nea/firmament/gui/repogui.kt | 36 +++ .../moe/nea/firmament/hud/RepoDownloadProgress.kt | 63 ++++++ .../moe/nea/firmament/recipes/SBCraftingRecipe.kt | 53 +++++ .../moe/nea/firmament/recipes/SBForgeRecipe.kt | 53 +++++ .../kotlin/moe/nea/firmament/recipes/SBRecipe.kt | 24 ++ .../moe/nea/firmament/rei/FirmamentReiPlugin.kt | 73 +++++++ .../moe/nea/firmament/rei/NEUItemEntryRenderer.kt | 31 +++ .../nea/firmament/rei/NEUItemEntrySerializer.kt | 25 +++ .../moe/nea/firmament/rei/SBItemEntryDefinition.kt | 85 +++++++ .../rei/SkyblockCraftingRecipeDynamicGenerator.kt | 52 +++++ .../rei/SkyblockItemIdFocusedStackProvider.kt | 25 +++ .../kotlin/moe/nea/firmament/repo/ItemCache.kt | 123 +++++++++++ .../moe/nea/firmament/repo/RepoDownloadManager.kt | 118 ++++++++++ .../kotlin/moe/nea/firmament/repo/RepoManager.kt | 102 +++++++++ src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt | 24 ++ .../moe/nea/firmament/util/LegacyTagParser.kt | 243 +++++++++++++++++++++ src/main/kotlin/moe/nea/firmament/util/Locraw.kt | 8 + src/main/kotlin/moe/nea/firmament/util/MC.kt | 13 ++ .../moe/nea/firmament/util/MinecraftDispatcher.kt | 22 ++ src/main/kotlin/moe/nea/firmament/util/SBData.kt | 62 ++++++ .../kotlin/moe/nea/firmament/util/ScreenUtil.kt | 36 +++ .../kotlin/moe/nea/firmament/util/SequenceUtil.kt | 9 + .../kotlin/moe/nea/firmament/util/SkyblockId.kt | 48 ++++ src/main/kotlin/moe/nea/firmament/util/TimeMark.kt | 15 ++ src/main/kotlin/moe/nea/firmament/util/Timer.kt | 23 ++ .../moe/nea/firmament/util/config/ManagedConfig.kt | 204 +++++++++++++++++ .../moe/nea/firmament/util/data/DataHolder.kt | 60 +++++ .../moe/nea/firmament/util/data/IDataHolder.kt | 75 +++++++ .../util/data/ProfileSpecificDataHolder.kt | 82 +++++++ .../kotlin/moe/nea/firmament/util/render/block.kt | 105 +++++++++ src/main/kotlin/moe/nea/firmament/util/textutil.kt | 70 ++++++ .../moe/nea/notenoughupdates/NotEnoughUpdates.kt | 92 -------- .../moe/nea/notenoughupdates/commands/dsl.kt | 81 ------- .../moe/nea/notenoughupdates/commands/rome.kt | 66 ------ .../nea/notenoughupdates/dbus/NEUDbusInterface.kt | 11 - .../moe/nea/notenoughupdates/dbus/NEUDbusObject.kt | 21 -- .../moe/nea/notenoughupdates/events/NEUEvent.kt | 36 --- .../moe/nea/notenoughupdates/events/NEUEventBus.kt | 37 ---- .../notenoughupdates/events/ParticleSpawnEvent.kt | 13 -- .../nea/notenoughupdates/events/ScreenOpenEvent.kt | 7 - .../events/ServerChatLineReceivedEvent.kt | 13 -- .../events/SkyblockServerUpdateEvent.kt | 13 -- .../nea/notenoughupdates/events/WorldReadyEvent.kt | 5 - .../events/WorldRenderLastEvent.kt | 22 -- .../notenoughupdates/features/FeatureManager.kt | 53 ----- .../nea/notenoughupdates/features/NEUFeature.kt | 18 -- .../features/fishing/FishingWarning.kt | 117 ---------- .../notenoughupdates/features/world/FairySouls.kt | 120 ---------- .../moe/nea/notenoughupdates/gui/ConfigGui.kt | 94 -------- .../notenoughupdates/gui/WGridPanelWithPadding.kt | 33 --- .../kotlin/moe/nea/notenoughupdates/gui/repogui.kt | 36 --- .../notenoughupdates/hud/RepoDownloadProgress.kt | 63 ------ .../notenoughupdates/recipes/SBCraftingRecipe.kt | 53 ----- .../nea/notenoughupdates/recipes/SBForgeRecipe.kt | 53 ----- .../moe/nea/notenoughupdates/recipes/SBRecipe.kt | 24 -- .../notenoughupdates/rei/NEUItemEntryRenderer.kt | 31 --- .../notenoughupdates/rei/NEUItemEntrySerializer.kt | 25 --- .../moe/nea/notenoughupdates/rei/NEUReiPlugin.kt | 73 ------- .../notenoughupdates/rei/SBItemEntryDefinition.kt | 85 ------- .../rei/SkyblockCraftingRecipeDynamicGenerator.kt | 52 ----- .../rei/SkyblockItemIdFocusedStackProvider.kt | 25 --- .../moe/nea/notenoughupdates/repo/ItemCache.kt | 123 ----------- .../notenoughupdates/repo/RepoDownloadManager.kt | 118 ---------- .../moe/nea/notenoughupdates/repo/RepoManager.kt | 102 --------- .../moe/nea/notenoughupdates/util/ItemUtil.kt | 24 -- .../nea/notenoughupdates/util/LegacyTagParser.kt | 243 --------------------- .../kotlin/moe/nea/notenoughupdates/util/Locraw.kt | 8 - .../kotlin/moe/nea/notenoughupdates/util/MC.kt | 13 -- .../notenoughupdates/util/MinecraftDispatcher.kt | 22 -- .../kotlin/moe/nea/notenoughupdates/util/SBData.kt | 64 ------ .../moe/nea/notenoughupdates/util/ScreenUtil.kt | 36 --- .../moe/nea/notenoughupdates/util/SequenceUtil.kt | 9 - .../moe/nea/notenoughupdates/util/SkyblockId.kt | 48 ---- .../moe/nea/notenoughupdates/util/TimeMark.kt | 15 -- .../kotlin/moe/nea/notenoughupdates/util/Timer.kt | 23 -- .../notenoughupdates/util/config/ManagedConfig.kt | 206 ----------------- .../nea/notenoughupdates/util/data/DataHolder.kt | 60 ----- .../nea/notenoughupdates/util/data/IDataHolder.kt | 75 ------- .../util/data/ProfileSpecificDataHolder.kt | 82 ------- .../moe/nea/notenoughupdates/util/render/block.kt | 105 --------- .../moe/nea/notenoughupdates/util/textutil.kt | 70 ------ 100 files changed, 2814 insertions(+), 2818 deletions(-) create mode 100644 src/main/kotlin/moe/nea/firmament/Firmament.kt create mode 100644 src/main/kotlin/moe/nea/firmament/commands/dsl.kt create mode 100644 src/main/kotlin/moe/nea/firmament/commands/rome.kt create mode 100644 src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusInterface.kt create mode 100644 src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusObject.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/NEUEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/NEUEventBus.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/ParticleSpawnEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/ScreenOpenEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/ServerChatLineReceivedEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/SkyblockServerUpdateEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/WorldReadyEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/events/WorldRenderLastEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt create mode 100644 src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt create mode 100644 src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt create mode 100644 src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt create mode 100644 src/main/kotlin/moe/nea/firmament/gui/ConfigGui.kt create mode 100644 src/main/kotlin/moe/nea/firmament/gui/WGridPanelWithPadding.kt create mode 100644 src/main/kotlin/moe/nea/firmament/gui/repogui.kt create mode 100644 src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt create mode 100644 src/main/kotlin/moe/nea/firmament/recipes/SBCraftingRecipe.kt create mode 100644 src/main/kotlin/moe/nea/firmament/recipes/SBForgeRecipe.kt create mode 100644 src/main/kotlin/moe/nea/firmament/recipes/SBRecipe.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/SkyblockCraftingRecipeDynamicGenerator.kt create mode 100644 src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt create mode 100644 src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt create mode 100644 src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt create mode 100644 src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/LegacyTagParser.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/Locraw.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/MC.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/MinecraftDispatcher.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/SBData.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/ScreenUtil.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/SequenceUtil.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/TimeMark.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/Timer.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/config/ManagedConfig.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/data/DataHolder.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/data/IDataHolder.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/data/ProfileSpecificDataHolder.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/render/block.kt create mode 100644 src/main/kotlin/moe/nea/firmament/util/textutil.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/commands/rome.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusInterface.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusObject.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/NEUEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/NEUEventBus.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/ParticleSpawnEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/ScreenOpenEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/ServerChatLineReceivedEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/SkyblockServerUpdateEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/WorldReadyEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/events/WorldRenderLastEvent.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/features/NEUFeature.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/features/fishing/FishingWarning.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/features/world/FairySouls.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/gui/ConfigGui.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/gui/repogui.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/hud/RepoDownloadProgress.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/recipes/SBCraftingRecipe.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/recipes/SBForgeRecipe.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/recipes/SBRecipe.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntryRenderer.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/NEUItemEntrySerializer.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockCraftingRecipeDynamicGenerator.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockItemIdFocusedStackProvider.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/LegacyTagParser.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/Locraw.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/MC.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/MinecraftDispatcher.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/SBData.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/SequenceUtil.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/SkyblockId.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/TimeMark.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/Timer.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/config/ManagedConfig.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/data/IDataHolder.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/data/ProfileSpecificDataHolder.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/util/textutil.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/moe/nea/firmament/Firmament.kt b/src/main/kotlin/moe/nea/firmament/Firmament.kt new file mode 100644 index 0000000..ec6cd3e --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/Firmament.kt @@ -0,0 +1,92 @@ +package moe.nea.firmament + +import com.mojang.brigadier.CommandDispatcher +import io.ktor.client.* +import io.ktor.client.plugins.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.serialization.kotlinx.json.* +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 +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource +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 org.apache.logging.log4j.LogManager +import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder +import kotlinx.coroutines.* +import kotlinx.serialization.json.Json +import kotlin.coroutines.EmptyCoroutineContext +import net.minecraft.command.CommandRegistryAccess +import moe.nea.firmament.commands.registerFirmamentCommand +import moe.nea.firmament.dbus.FirmamentDbusObject +import moe.nea.firmament.features.FeatureManager +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.data.IDataHolder + +object Firmament : ModInitializer, ClientModInitializer { + const val MOD_ID = "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 = LogManager.getLogger("Firmament") + val metadata: ModMetadata by lazy { FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().metadata } + val version: Version by lazy { metadata.version } + + val json = Json { + prettyPrint = DEBUG + ignoreUnknownKeys = true + encodeDefaults = true + } + + val httpClient by lazy { + HttpClient { + install(ContentNegotiation) { + json(json) + } + install(UserAgent) { + agent = "Firmament/$version" + } + } + } + + val globalJob = Job() + val dbusConnection = DBusConnectionBuilder.forSessionBus() + .build() + val coroutineScope = + CoroutineScope(EmptyCoroutineContext + CoroutineName("Firmament")) + SupervisorJob(globalJob) + + private fun registerCommands( + dispatcher: CommandDispatcher, + @Suppress("UNUSED_PARAMETER") + ctx: CommandRegistryAccess + ) { + registerFirmamentCommand(dispatcher) + } + + override fun onInitialize() { + + dbusConnection.requestBusName("moe.nea.firmament") + dbusConnection.exportObject(FirmamentDbusObject) + IDataHolder.registerEvents() + RepoManager.initialize() + SBData.init() + FeatureManager.autoload() + + ClientCommandRegistrationCallback.EVENT.register(this::registerCommands) + ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping { + runBlocking { + logger.info("Shutting down NEU coroutines") + globalJob.cancel() + } + }) + } + + override fun onInitializeClient() { + } +} diff --git a/src/main/kotlin/moe/nea/firmament/commands/dsl.kt b/src/main/kotlin/moe/nea/firmament/commands/dsl.kt new file mode 100644 index 0000000..5ead624 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/commands/dsl.kt @@ -0,0 +1,81 @@ +package moe.nea.firmament.commands + +import com.mojang.brigadier.arguments.ArgumentType +import com.mojang.brigadier.builder.ArgumentBuilder +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.builder.RequiredArgumentBuilder +import com.mojang.brigadier.context.CommandContext +import java.lang.reflect.ParameterizedType +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource +import moe.nea.firmament.util.iterate + + +typealias DefaultSource = FabricClientCommandSource + + +inline val > T.context get() = this +operator fun > C.get(arg: TypeSafeArg): T { + return arg.get(this) +} + +fun literal( + name: String, + block: LiteralArgumentBuilder.() -> Unit +): LiteralArgumentBuilder = + LiteralArgumentBuilder.literal(name).also(block) + +data class TypeSafeArg(val name: String, val argument: ArgumentType) { + val argClass by lazy { + argument.javaClass + .iterate>> { + it.superclass + } + .map { + it.genericSuperclass + } + .filterIsInstance() + .find { it.rawType == ArgumentType::class.java }!! + .let { it.actualTypeArguments[0] as Class<*> } + } + + @JvmName("getWithThis") + fun CommandContext.get(): T = + get(this) + + + fun get(ctx: CommandContext): T { + return ctx.getArgument(name, argClass) as T + } +} + + +fun argument( + name: String, + argument: ArgumentType, + block: RequiredArgumentBuilder.(TypeSafeArg) -> Unit +): RequiredArgumentBuilder = + RequiredArgumentBuilder.argument(name, argument).also { block(it, TypeSafeArg(name, argument)) } + +fun , AT : Any> T.thenArgument( + name: String, + argument: ArgumentType, + block: RequiredArgumentBuilder.(TypeSafeArg) -> Unit +): T = then(argument(name, argument, block)) + + +fun > T.thenLiteral( + name: String, + block: LiteralArgumentBuilder.() -> Unit +): T = + then(literal(name, block)) + +fun > T.then(node: ArgumentBuilder, block: T.() -> Unit): T = + then(node).also(block) + +fun > T.thenExecute(block: CommandContext.() -> Unit): T = + executes { + block(it) + 1 + } + + diff --git a/src/main/kotlin/moe/nea/firmament/commands/rome.kt b/src/main/kotlin/moe/nea/firmament/commands/rome.kt new file mode 100644 index 0000000..bdbaa3f --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/commands/rome.kt @@ -0,0 +1,66 @@ +package moe.nea.firmament.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.firmament.features.world.FairySouls +import moe.nea.firmament.gui.repoGui +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.ScreenUtil.setScreenLater + + +fun firmamentCommand() = literal("firmament") { + thenLiteral("repo") { + thenLiteral("reload") { + thenLiteral("fetch") { + thenExecute { + source.sendFeedback(Text.translatable("firmament.repo.reload.network")) // TODO better reporting + RepoManager.launchAsyncUpdate() + } + } + thenExecute { + source.sendFeedback(Text.translatable("firmament.repo.reload.disk")) + RepoManager.reload() + } + } + thenExecute { + setScreenLater(CottonClientScreen(repoGui())) + } + } + thenLiteral("dev") { + thenLiteral("config") { + thenExecute { + FairySouls.TConfig.showConfigEditor() + } + } + thenLiteral("sbdata") { + thenExecute { + source.sendFeedback(Text.translatable("firmament.sbinfo.profile", SBData.profileCuteName)) + val locrawInfo = SBData.locraw + if (locrawInfo == null) { + source.sendFeedback(Text.translatable("firmament.sbinfo.nolocraw")) + } else { + source.sendFeedback(Text.translatable("firmament.sbinfo.server", locrawInfo.server)) + source.sendFeedback(Text.translatable("firmament.sbinfo.gametype", locrawInfo.gametype)) + source.sendFeedback(Text.translatable("firmament.sbinfo.mode", locrawInfo.mode)) + source.sendFeedback(Text.translatable("firmament.sbinfo.map", locrawInfo.map)) + } + + } + } + } +} + + +fun registerFirmamentCommand(dispatcher: CommandDispatcher) { + val firmament = dispatcher.register(firmamentCommand()) + dispatcher.register(literal("firm") { + redirect(firmament) + }) +} + + + + diff --git a/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusInterface.kt b/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusInterface.kt new file mode 100644 index 0000000..24b7dc8 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusInterface.kt @@ -0,0 +1,11 @@ +package moe.nea.firmament.dbus + +import org.freedesktop.dbus.annotations.DBusInterfaceName +import org.freedesktop.dbus.interfaces.DBusInterface + +@DBusInterfaceName("moe.nea.Firmament") +interface FirmamentDbusInterface : DBusInterface { + fun sayHello(): String + fun getCurrentRepoCommit(): String + fun requestRepoReDownload() +} diff --git a/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusObject.kt b/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusObject.kt new file mode 100644 index 0000000..48d4cf7 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/dbus/FirmamentDbusObject.kt @@ -0,0 +1,21 @@ +package moe.nea.firmament.dbus + +import moe.nea.firmament.repo.RepoManager + +object FirmamentDbusObject : FirmamentDbusInterface { + override fun sayHello(): String { + return "Hello from Firmanet" + } + + override fun getCurrentRepoCommit(): String { + return RepoManager.currentDownloadedSha ?: "none" + } + + override fun requestRepoReDownload() { + RepoManager.launchAsyncUpdate() + } + + override fun getObjectPath(): String { + return "/moe/nea/Firmament" + } +} diff --git a/src/main/kotlin/moe/nea/firmament/events/NEUEvent.kt b/src/main/kotlin/moe/nea/firmament/events/NEUEvent.kt new file mode 100644 index 0000000..722ea64 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/NEUEvent.kt @@ -0,0 +1,36 @@ +package moe.nea.firmament.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() + * } + * ``` + */ +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/firmament/events/NEUEventBus.kt b/src/main/kotlin/moe/nea/firmament/events/NEUEventBus.kt new file mode 100644 index 0000000..b3b9152 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/NEUEventBus.kt @@ -0,0 +1,37 @@ +package moe.nea.firmament.events + +import java.util.concurrent.CopyOnWriteArrayList +import moe.nea.firmament.Firmament + +/** + * 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 { + data class Handler(val invocation: (T) -> Unit, val receivesCancelled: Boolean) + + private val toHandle: MutableList> = CopyOnWriteArrayList() + fun subscribe(handle: (T) -> Unit) { + subscribe(handle, false) + } + + fun subscribe(handle: (T) -> Unit, receivesCancelled: Boolean) { + toHandle.add(Handler(handle, receivesCancelled)) + } + + fun publish(event: T): T { + for (function in toHandle) { + if (function.receivesCancelled || event !is NEUEvent.Cancellable || !event.cancelled) { + try { + function.invocation(event) + } catch (e: Exception) { + Firmament.logger.error("Caught exception during processing event $event", e) + } + } + } + return event + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/events/ParticleSpawnEvent.kt b/src/main/kotlin/moe/nea/firmament/events/ParticleSpawnEvent.kt new file mode 100644 index 0000000..bbf7289 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/ParticleSpawnEvent.kt @@ -0,0 +1,13 @@ +package moe.nea.firmament.events + +import net.minecraft.particle.ParticleEffect +import net.minecraft.util.math.Vec3d + +data class ParticleSpawnEvent( + val particleEffect: ParticleEffect, + val position: Vec3d, + val offset: Vec3d, + val longDistance: Boolean, +) : NEUEvent() { + companion object : NEUEventBus() +} diff --git a/src/main/kotlin/moe/nea/firmament/events/ScreenOpenEvent.kt b/src/main/kotlin/moe/nea/firmament/events/ScreenOpenEvent.kt new file mode 100644 index 0000000..ee162ab --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/ScreenOpenEvent.kt @@ -0,0 +1,7 @@ +package moe.nea.firmament.events + +import net.minecraft.client.gui.screen.Screen + +data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : NEUEvent.Cancellable() { + companion object : NEUEventBus() +} diff --git a/src/main/kotlin/moe/nea/firmament/events/ServerChatLineReceivedEvent.kt b/src/main/kotlin/moe/nea/firmament/events/ServerChatLineReceivedEvent.kt new file mode 100644 index 0000000..7e8531c --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/ServerChatLineReceivedEvent.kt @@ -0,0 +1,13 @@ +package moe.nea.firmament.events + +import net.minecraft.text.Text +import moe.nea.firmament.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() + + val unformattedString = text.unformattedString +} diff --git a/src/main/kotlin/moe/nea/firmament/events/SkyblockServerUpdateEvent.kt b/src/main/kotlin/moe/nea/firmament/events/SkyblockServerUpdateEvent.kt new file mode 100644 index 0000000..ae3227f --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/SkyblockServerUpdateEvent.kt @@ -0,0 +1,13 @@ +package moe.nea.firmament.events + +import moe.nea.firmament.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() +} diff --git a/src/main/kotlin/moe/nea/firmament/events/WorldReadyEvent.kt b/src/main/kotlin/moe/nea/firmament/events/WorldReadyEvent.kt new file mode 100644 index 0000000..5b01258 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/WorldReadyEvent.kt @@ -0,0 +1,5 @@ +package moe.nea.firmament.events + +class WorldReadyEvent : NEUEvent() { + companion object : NEUEventBus() +} diff --git a/src/main/kotlin/moe/nea/firmament/events/WorldRenderLastEvent.kt b/src/main/kotlin/moe/nea/firmament/events/WorldRenderLastEvent.kt new file mode 100644 index 0000000..c23d923 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/WorldRenderLastEvent.kt @@ -0,0 +1,22 @@ +package moe.nea.firmament.events + +import org.joml.Matrix4f +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 + +/** + * 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() +} diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt new file mode 100644 index 0000000..68205f4 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -0,0 +1,53 @@ +package moe.nea.firmament.features + +import kotlinx.serialization.Serializable +import kotlinx.serialization.serializer +import moe.nea.firmament.Firmament +import moe.nea.firmament.features.fishing.FishingWarning +import moe.nea.firmament.features.world.FairySouls +import moe.nea.firmament.util.data.DataHolder + +object FeatureManager : DataHolder(serializer(), "features", ::Config) { + @Serializable + data class Config( + val enabledFeatures: MutableMap = mutableMapOf() + ) + + private val features = mutableMapOf() + + private var hasAutoloaded = false + + init { + autoload() + } + + fun autoload() { + synchronized(this) { + if (hasAutoloaded) return + loadFeature(FairySouls) + loadFeature(FishingWarning) + hasAutoloaded = true + } + } + + fun loadFeature(feature: NEUFeature) { + synchronized(features) { + if (feature.identifier in features) { + Firmament.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature") + return + } + features[feature.identifier] = feature + feature.onLoad() + } + } + + fun isEnabled(identifier: String): Boolean? = + data.enabledFeatures[identifier] + + + fun setEnabled(identifier: String, value: Boolean) { + data.enabledFeatures[identifier] = value + markDirty() + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt b/src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt new file mode 100644 index 0000000..f231003 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt @@ -0,0 +1,18 @@ +package moe.nea.firmament.features + +import moe.nea.firmament.util.config.ManagedConfig + +interface NEUFeature { + val name: String + val identifier: String + val defaultEnabled: Boolean + get() = true + var isEnabled: Boolean + get() = FeatureManager.isEnabled(identifier) ?: defaultEnabled + set(value) { + FeatureManager.setEnabled(identifier, value) + } + val config: ManagedConfig? get() = null + fun onLoad() + +} diff --git a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt new file mode 100644 index 0000000..cdeb24c --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt @@ -0,0 +1,117 @@ +package moe.nea.firmament.features.fishing + +import kotlin.math.abs +import kotlin.math.absoluteValue +import kotlin.math.acos +import kotlin.math.asin +import kotlin.math.atan2 +import kotlin.math.sqrt +import kotlin.time.Duration.Companion.seconds +import net.minecraft.entity.projectile.FishingBobberEntity +import net.minecraft.particle.ParticleTypes +import net.minecraft.util.math.Vec3d +import moe.nea.firmament.events.ParticleSpawnEvent +import moe.nea.firmament.events.WorldReadyEvent +import moe.nea.firmament.events.WorldRenderLastEvent +import moe.nea.firmament.features.NEUFeature +import moe.nea.firmament.util.MC +import moe.nea.firmament.util.TimeMark +import moe.nea.firmament.util.config.ManagedConfig +import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks + +object FishingWarning : NEUFeature { + override val name: String + get() = "Fishing Warning" + override val identifier: String + get() = "fishing-warning" + + object TConfig : ManagedConfig("fishing-warning") { + // Display a warning when you are about to hook a fish + val displayWarning by toggle("display-warning") { false } + val highlightWakeChain by toggle("highlight-wake-chain") { false } + } + + override val config: ManagedConfig get() = TConfig + + + data class WakeChain( + val delta: Vec3d, + val momentum: Vec3d, + val lastContinued: TimeMark, + ) + + + val chains = mutableListOf() + + private fun areAnglesClose(a: Double, b: Double, tolerance: Double): Boolean { + var dist = (a - b).absoluteValue + if (180 < dist) dist = 360 - dist; + return dist <= tolerance + } + + private fun calculateAngleFromOffsets(xOffset: Double, zOffset: Double): Double { + // See also: Vanilla 1.8.9 Fishing particle code. + var angleX = Math.toDegrees(acos(xOffset / 0.04)) + var angleZ = Math.toDegrees(asin(zOffset / 0.04)) + if (xOffset < 0) { + // Old: angleZ = 180 - angleZ; + angleZ = 180 - angleZ + } + if (zOffset < 0) { + angleX = 360 - angleX + } + angleX %= 360.0 + angleZ %= 360.0 + if (angleX < 0) angleX += 360.0 + if (angleZ < 0) angleZ += 360.0 + var dist = angleX - angleZ + if (dist < -180) dist += 360.0 + if (dist > 180) dist -= 360.0 + return angleZ + dist / 2 + } + + private fun toDegrees(d: Double) = d * 180 / Math.PI + + fun isHookPossible(hook: FishingBobberEntity, particlePos: Vec3d, angle1: Double, angle2: Double): Boolean { + val dx = particlePos.x - hook.pos.x + val dz = particlePos.z - hook.pos.z + val dist = sqrt(dx * dx + dz * dz) + + if (dist < 0.2) return true + val tolerance = toDegrees(atan2(0.03125, dist)) * 1.5 + var angleToHook = toDegrees(atan2(dx, dz)) % 360 + if (angleToHook < 0) angleToHook += 360 + return areAnglesClose(angle1, angleToHook, tolerance) || areAnglesClose(angle2, angleToHook, tolerance) + } + + val recentParticles = mutableListOf>() + + private fun onParticleSpawn(event: ParticleSpawnEvent) { + if (event.particleEffect.type != ParticleTypes.FISHING) return + if (!(abs(event.offset.y - 0.01f) < 0.001f)) return + val hook = MC.player?.fishHook ?: return + val actualOffset = event.offset + val candidate1 = calculateAngleFromOffsets(actualOffset.x, -actualOffset.z) + val candidate2 = calculateAngleFromOffsets(-actualOffset.x, actualOffset.z) + + if (isHookPossible(hook, event.position, candidate1, candidate2)) { + recentParticles.add(Pair(event.position, TimeMark.now())) + } + } + + override fun onLoad() { + ParticleSpawnEvent.subscribe(::onParticleSpawn) + WorldReadyEvent.subscribe { + recentParticles.clear() + } + WorldRenderLastEvent.subscribe { + recentParticles.removeIf { it.second.passedTime() > 5.seconds } + renderBlocks(it.matrices, it.camera) { + color(0f, 0f, 1f, 1f) + recentParticles.forEach { + tinyBlock(it.first, 0.1F) + } + } + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt new file mode 100644 index 0000000..f752963 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt @@ -0,0 +1,120 @@ +package moe.nea.firmament.features.world + +import io.github.moulberry.repo.data.Coordinate +import kotlinx.serialization.Serializable +import kotlinx.serialization.serializer +import moe.nea.firmament.events.ServerChatLineReceivedEvent +import moe.nea.firmament.events.SkyblockServerUpdateEvent +import moe.nea.firmament.events.WorldRenderLastEvent +import moe.nea.firmament.features.NEUFeature +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.MC +import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.blockPos +import moe.nea.firmament.util.config.ManagedConfig +import moe.nea.firmament.util.data.ProfileSpecificDataHolder +import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks +import moe.nea.firmament.util.unformattedString + + +object FairySouls : NEUFeature { + + + @Serializable + data class Data( + val foundSouls: MutableMap> = mutableMapOf() + ) + + override val config: ManagedConfig + get() = TConfig + + object DConfig : ProfileSpecificDataHolder(serializer(), "found-fairysouls", ::Data) + + + object TConfig : ManagedConfig("fairy-souls") { + + val displaySouls by toggle("show") { false } + val resetSouls by button("reset") { + DConfig.data?.foundSouls?.clear() != null + updateMissingSouls() + } + } + + + 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 = emptyList() + var currentMissingSouls: List = emptyList() + + fun updateMissingSouls() { + currentMissingSouls = emptyList() + val c = DConfig.data ?: 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 = + 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 = DConfig.data ?: return + val loc = currentLocationName ?: return + val idx = currentLocationSouls.indexOf(nearestSoul) + c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx) + DConfig.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 { + if (!TConfig.displaySouls) return@subscribe + renderBlocks(it.matrices, it.camera) { + color(1F, 1F, 0F, 0.8F) + currentMissingSouls.forEach { + block(it.blockPos) + } + } + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/gui/ConfigGui.kt b/src/main/kotlin/moe/nea/firmament/gui/ConfigGui.kt new file mode 100644 index 0000000..6acf68a --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/gui/ConfigGui.kt @@ -0,0 +1,94 @@ +package moe.nea.firmament.gui + +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription +import io.github.cottonmc.cotton.gui.widget.WButton +import io.github.cottonmc.cotton.gui.widget.WLabel +import io.github.cottonmc.cotton.gui.widget.WTextField +import io.github.cottonmc.cotton.gui.widget.WToggleButton +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.firmament.Firmament +import moe.nea.firmament.util.data.DataHolder +import net.minecraft.text.Text +import kotlin.reflect.KMutableProperty1 + +class ConfigGui(val holder: DataHolder, val build: ConfigGui.() -> Unit) : LightweightGuiDescription() { + private val root = WGridPanelWithPadding(verticalPadding = 4) + private val reloadables = mutableListOf<(() -> Unit)>() + + init { + setRootPanel(root) + root.insets = Insets.ROOT_PANEL + build() + reload() + } + + fun title(text: Text) { + if (col != 0) { + Firmament.logger.warn("Set title not at the top of the ConfigGui") + } + val label = WLabel(text) + label.verticalAlignment = VerticalAlignment.TOP + label.horizontalAlignment = HorizontalAlignment.CENTER + root.add(label, 0, col, 11, 1) + col++ + } + + private fun label(text: Text) { + val label = WLabel(text) + label.verticalAlignment = VerticalAlignment.CENTER + root.add(label, 0, col, 5, 1) + } + + fun toggle(text: Text, prop: KMutableProperty1) { + val toggle = WToggleButton(text) + reloadables.add { toggle.toggle = prop.get(holder.data) } + toggle.setOnToggle { + prop.set(holder.data, true) + holder.markDirty() + } + root.add(toggle, 5, col, 6, 1) + label(text) + col++ + } + + fun button(text: Text, buttonText: Text, runnable: () -> Unit) { + val button = WButton(buttonText) + button.setOnClick { + runnable.invoke() + } + root.add(button, 5, col, 6, 1) + label(text) + col++ + } + + fun textfield( + text: Text, + background: Text, + prop: KMutableProperty1, + maxLength: Int = 255 + ) { + val textfield = WTextField(background) + textfield.isEditable = true + reloadables.add { + textfield.text = prop.get(holder.data) + } + textfield.maxLength = maxLength + textfield.setChangedListener { + prop.set(holder.data, it) + holder.markDirty() + } + root.add(textfield, 5, col, 6, 11) + label(text) + col++ + } + + fun reload() { + reloadables.forEach { it.invoke() } + } + + private var col = 0 + + +} diff --git a/src/main/kotlin/moe/nea/firmament/gui/WGridPanelWithPadding.kt b/src/main/kotlin/moe/nea/firmament/gui/WGridPanelWithPadding.kt new file mode 100644 index 0000000..255b80d --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/gui/WGridPanelWithPadding.kt @@ -0,0 +1,33 @@ +package moe.nea.firmament.gui + +import io.github.cottonmc.cotton.gui.widget.WPanelWithInsets +import io.github.cottonmc.cotton.gui.widget.WWidget +import io.github.cottonmc.cotton.gui.widget.data.Insets + +class WGridPanelWithPadding( + val grid: Int = 18, + val verticalPadding: Int = 0, + val horizontalPadding: Int = 0, +) : WPanelWithInsets() { + + private inline val vertOffset get() = grid + verticalPadding + private inline val horiOffset get() = grid + horizontalPadding + + fun add(w: WWidget, x: Int, y: Int, width: Int = 1, height: Int = 1) { + children.add(w) + w.parent = this + w.setLocation(x * horiOffset + insets.left, y * vertOffset + insets.top) + if (w.canResize()) + w.setSize( + grid + (horiOffset * (width - 1)), + grid + (vertOffset * (height - 1)), + ) + expandToFit(w, insets) + } + + override fun setInsets(insets: Insets): WGridPanelWithPadding { + super.setInsets(insets) + return this + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/gui/repogui.kt b/src/main/kotlin/moe/nea/firmament/gui/repogui.kt new file mode 100644 index 0000000..da681e4 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/gui/repogui.kt @@ -0,0 +1,36 @@ +package moe.nea.firmament.gui + +import net.minecraft.text.Text +import moe.nea.firmament.repo.RepoManager + +fun repoGui(): ConfigGui { + return ConfigGui(RepoManager) { + title(Text.translatable("firmament.gui.repo.title")) + toggle(Text.translatable("firmament.gui.repo.autoupdate"), RepoManager.Config::autoUpdate) + textfield( + Text.translatable("firmament.gui.repo.username"), + Text.translatable("firmament.gui.repo.hint.username"), + RepoManager.Config::user, + maxLength = 255 + ) + textfield( + Text.translatable("firmament.gui.repo.reponame"), + Text.translatable("firmament.gui.repo.hint.reponame"), + RepoManager.Config::repo + ) + textfield( + Text.translatable("firmament.gui.repo.branch"), + Text.translatable("firmament.gui.repo.hint.branch"), + RepoManager.Config::branch + ) + button( + Text.translatable("firmament.gui.repo.reset.label"), + Text.translatable("firmament.gui.repo.reset"), + ) { + RepoManager.data.user = "NotEnoughUpdates" + RepoManager.data.repo = "NotEnoughUpdates-REPO" + RepoManager.data.branch = "dangerous" + reload() + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt b/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt new file mode 100644 index 0000000..315230b --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt @@ -0,0 +1,63 @@ +package moe.nea.firmament.hud + +import io.github.cottonmc.cotton.gui.client.ScreenDrawing +import io.github.cottonmc.cotton.gui.widget.WWidget +import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment +import io.github.cottonmc.cotton.gui.widget.data.Insets +import net.minecraft.client.util.math.MatrixStack +import kotlin.math.roundToInt +import kotlin.math.sin + + +val Insets.vertical get() = bottom + top +val Insets.horizontal get() = left + right + +class ProgressBar( + var label: String, + var total: Int?, // If total is null, then make it a bouncy rectangle + var progress: Int = 0, +) : WWidget() { + + var insets: Insets = Insets(7) + override fun canResize(): Boolean = true + + + fun reportProgress(label: String, progress: Int, total: Int?) { + synchronized(this) { + this.label = label + this.progress = progress + this.total = total + } + + } + + override fun paint(matrices: MatrixStack, x: Int, y: Int, mouseX: Int, mouseY: Int) { + ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF808080.toInt()) + val (l, prog) = synchronized(this) { + label to (progress to total) + } + val (p, t) = prog + + if (t == null) { + ScreenDrawing.coloredRect( + matrices, + (x + (1 + sin(System.currentTimeMillis().toDouble() / 1000)) * width * 3 / 4 / 2).roundToInt(), + y, + width / 4, + height, + 0xFF00FF00.toInt() + ) + } else { + ScreenDrawing.coloredRect(matrices, x, y, width * p / t, height, 0xFF00FF00.toInt()) + } + ScreenDrawing.drawString( + matrices, + if (t != null) "$l ($p/$t)" else l, + HorizontalAlignment.CENTER, + x + insets.left, + y + insets.top, + width - insets.horizontal, + height - insets.vertical, + ) + } +} diff --git a/src/main/kotlin/moe/nea/firmament/recipes/SBCraftingRecipe.kt b/src/main/kotlin/moe/nea/firmament/recipes/SBCraftingRecipe.kt new file mode 100644 index 0000000..0cf63fc --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/recipes/SBCraftingRecipe.kt @@ -0,0 +1,53 @@ +package moe.nea.firmament.recipes + +import io.github.moulberry.repo.data.NEUCraftingRecipe +import io.github.moulberry.repo.data.NEUIngredient +import me.shedaniel.math.Point +import me.shedaniel.math.Rectangle +import me.shedaniel.rei.api.client.gui.Renderer +import me.shedaniel.rei.api.client.gui.widgets.Widget +import me.shedaniel.rei.api.client.gui.widgets.Widgets +import me.shedaniel.rei.api.client.registry.display.DisplayCategory +import me.shedaniel.rei.api.common.category.CategoryIdentifier +import me.shedaniel.rei.api.common.util.EntryStacks +import net.minecraft.block.Blocks +import net.minecraft.text.Text +import moe.nea.firmament.Firmament +import moe.nea.firmament.rei.SBItemEntryDefinition + +class SBCraftingRecipe(override val neuRecipe: NEUCraftingRecipe) : SBRecipe() { + override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.catIdentifier + + object Category : DisplayCategory { + val catIdentifier = CategoryIdentifier.of(Firmament.MOD_ID, "crafing_recipe") + override fun getCategoryIdentifier(): CategoryIdentifier = catIdentifier + + override fun getTitle(): Text = Text.literal("SkyBlock Crafting") + + override fun getIcon(): Renderer = EntryStacks.of(Blocks.CRAFTING_TABLE) + override fun setupDisplay(display: SBCraftingRecipe, bounds: Rectangle): List { + val point = Point(bounds.centerX - 58, bounds.centerY - 27) + return buildList { + add(Widgets.createRecipeBase(bounds)) + add(Widgets.createArrow(Point(point.x + 60, point.y + 18))) + add(Widgets.createResultSlotBackground(Point(point.x + 95, point.y + 19))) + for (i in 0 until 3) { + for (j in 0 until 3) { + val slot = Widgets.createSlot(Point(point.x + 1 + i * 18, point.y + 1 + j * 18)).markInput() + add(slot) + val item = display.neuRecipe.inputs[i + j * 3] + if (item == NEUIngredient.SENTINEL_EMPTY) continue + slot.entry(SBItemEntryDefinition.getEntry(item)) // TODO: make use of stackable item entries + } + } + add( + Widgets.createSlot(Point(point.x + 95, point.y + 19)) + .entry(SBItemEntryDefinition.getEntry(display.neuRecipe.output)) + .disableBackground().markOutput() + ) + } + } + + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/recipes/SBForgeRecipe.kt b/src/main/kotlin/moe/nea/firmament/recipes/SBForgeRecipe.kt new file mode 100644 index 0000000..b00005f --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/recipes/SBForgeRecipe.kt @@ -0,0 +1,53 @@ +package moe.nea.firmament.recipes + +import io.github.moulberry.repo.data.NEUForgeRecipe +import me.shedaniel.math.Point +import me.shedaniel.math.Rectangle +import me.shedaniel.rei.api.client.gui.Renderer +import me.shedaniel.rei.api.client.gui.widgets.Widget +import me.shedaniel.rei.api.client.gui.widgets.Widgets +import me.shedaniel.rei.api.client.registry.display.DisplayCategory +import me.shedaniel.rei.api.common.category.CategoryIdentifier +import me.shedaniel.rei.api.common.util.EntryStacks +import net.minecraft.block.Blocks +import net.minecraft.text.Text +import moe.nea.firmament.Firmament +import moe.nea.firmament.rei.SBItemEntryDefinition + +class SBForgeRecipe(override val neuRecipe: NEUForgeRecipe) : SBRecipe() { + override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.categoryIdentifier + + object Category : DisplayCategory { + override fun getCategoryIdentifier(): CategoryIdentifier = + CategoryIdentifier.of(Firmament.MOD_ID, "forge_recipe") + + override fun getTitle(): Text = Text.literal("Forge Recipes") + override fun getDisplayHeight(): Int { + return super.getDisplayHeight() + } + + override fun getIcon(): Renderer = EntryStacks.of(Blocks.ANVIL) + override fun setupDisplay(display: SBForgeRecipe, bounds: Rectangle): List { + return buildList { + // TODO: proper gui for this (possibly inspired by the old circular gui) + add(Widgets.createRecipeBase(bounds)) + val resultSlot = Point(bounds.centerX, bounds.centerY + 5) + add(Widgets.createResultSlotBackground(resultSlot)) + val ingredientsCenter = Point(bounds.centerX, bounds.centerY - 20) + val count = display.neuRecipe.inputs.size + display.neuRecipe.inputs.forEachIndexed { idx, ingredient -> + add( + Widgets.createSlot( + Point(ingredientsCenter.x + 12 - count * 24 / 2 + idx * 24, ingredientsCenter.y) + ).markInput().entry(SBItemEntryDefinition.getEntry(ingredient)) + ) + } + add( + Widgets.createSlot(resultSlot).markOutput().disableBackground() + .entry(SBItemEntryDefinition.getEntry(display.neuRecipe.outputStack)) + ) + } + } + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/recipes/SBRecipe.kt b/src/main/kotlin/moe/nea/firmament/recipes/SBRecipe.kt new file mode 100644 index 0000000..ed982bd --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/recipes/SBRecipe.kt @@ -0,0 +1,24 @@ +package moe.nea.firmament.recipes + +import io.github.moulberry.repo.data.NEURecipe +import me.shedaniel.rei.api.common.display.Display +import me.shedaniel.rei.api.common.entry.EntryIngredient +import moe.nea.firmament.rei.SBItemEntryDefinition +import moe.nea.firmament.util.SkyblockId + +abstract class SBRecipe() : Display { + abstract val neuRecipe: NEURecipe + override fun getInputEntries(): List { + return neuRecipe.allInputs.map { + val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) + EntryIngredient.of(entryStack) + } + } + + override fun getOutputEntries(): List { + return neuRecipe.allOutputs.map { + val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) + EntryIngredient.of(entryStack) + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt b/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt new file mode 100644 index 0000000..992b104 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt @@ -0,0 +1,73 @@ +package moe.nea.firmament.rei + +import io.github.moulberry.repo.data.NEUItem +import me.shedaniel.rei.api.client.plugins.REIClientPlugin +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry +import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry +import me.shedaniel.rei.api.client.registry.entry.EntryRegistry +import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry +import me.shedaniel.rei.api.common.entry.EntryStack +import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes +import net.minecraft.item.ItemStack +import net.minecraft.text.Text +import net.minecraft.util.Identifier +import moe.nea.firmament.recipes.SBCraftingRecipe +import moe.nea.firmament.recipes.SBForgeRecipe +import moe.nea.firmament.repo.ItemCache.asItemStack +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.SkyblockId + + +class FirmamentReiPlugin : REIClientPlugin { + + companion object { + fun EntryStack.asItemEntry(): EntryStack { + return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack()) + } + + val SKYBLOCK_ITEM_TYPE_ID = Identifier("firmament", "skyblockitems") + } + + override fun registerEntryTypes(registry: EntryTypeRegistry) { + registry.register(SKYBLOCK_ITEM_TYPE_ID, SBItemEntryDefinition) + } + + override fun registerCategories(registry: CategoryRegistry) { + registry.add(SBCraftingRecipe.Category) + registry.add(SBForgeRecipe.Category) + } + + override fun registerDisplays(registry: DisplayRegistry) { + registry.registerDisplayGenerator( + SBCraftingRecipe.Category.catIdentifier, + SkyblockCraftingRecipeDynamicGenerator + ) + registry.registerDisplayGenerator( + SBForgeRecipe.Category.categoryIdentifier, + SkyblockForgeRecipeDynamicGenerator + ) + } + + override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { + RepoManager.neuRepo.constants.parents.parents + .forEach { (parent, children) -> + registry.group( + SkyblockId(parent).identifier, + Text.literal(RepoManager.getNEUItem(SkyblockId(parent))?.displayName ?: parent), + (children + parent).map { SBItemEntryDefinition.getEntry(RepoManager.getNEUItem(SkyblockId(it))) }) + } + } + + override fun registerScreens(registry: ScreenRegistry) { + registry.registerFocusedStack(SkyblockItemIdFocusedStackProvider) + } + + override fun registerEntries(registry: EntryRegistry) { + RepoManager.neuRepo.items?.items?.values?.forEach { + if (!it.isVanilla) + registry.addEntry(EntryStack.of(SBItemEntryDefinition, it)) + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt new file mode 100644 index 0000000..8253c96 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt @@ -0,0 +1,31 @@ +package moe.nea.firmament.rei + +import io.github.moulberry.repo.data.NEUItem +import me.shedaniel.math.Rectangle +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer +import me.shedaniel.rei.api.client.gui.widgets.Tooltip +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext +import me.shedaniel.rei.api.common.entry.EntryStack +import net.minecraft.client.util.math.MatrixStack +import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry + +object NEUItemEntryRenderer : EntryRenderer { + override fun render( + entry: EntryStack, + matrices: MatrixStack, + bounds: Rectangle, + mouseX: Int, + mouseY: Int, + delta: Float + ) { + matrices.push() + matrices.translate(0F, 0F, 100F) + entry.asItemEntry().render(matrices, bounds, mouseX, mouseY, delta) + matrices.pop() + } + + override fun getTooltip(entry: EntryStack, tooltipContext: TooltipContext): Tooltip? { + return entry.asItemEntry().getTooltip(tooltipContext, false) + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt new file mode 100644 index 0000000..15731cb --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt @@ -0,0 +1,25 @@ +package moe.nea.firmament.rei + +import io.github.moulberry.repo.data.NEUItem +import me.shedaniel.rei.api.common.entry.EntrySerializer +import me.shedaniel.rei.api.common.entry.EntryStack +import net.minecraft.nbt.NbtCompound +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.SkyblockId + +object NEUItemEntrySerializer : EntrySerializer { + const val SKYBLOCK_ID_ENTRY = "SKYBLOCK_ID" + + override fun supportSaving(): Boolean = true + override fun supportReading(): Boolean = true + + override fun read(tag: NbtCompound): NEUItem? { + return RepoManager.getNEUItem(SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY))) + } + + override fun save(entry: EntryStack, value: NEUItem?): NbtCompound { + return NbtCompound().apply { + putString(SKYBLOCK_ID_ENTRY, value?.skyblockItemId ?: "null") + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt new file mode 1006