aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-24 18:12:39 +0200
committernea <nea@nea.moe>2023-08-24 18:12:39 +0200
commitb0cb9a70cd9a3f02b86e0386ab6bb70974bba35a (patch)
treeddb5e478c321e87c424f002b959265b25891b943
parent8c5570bfe6ab93855e24e6924fac1105fe8342ff (diff)
downloadFirmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.tar.gz
Firmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.tar.bz2
Firmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.zip
Revive old profile viewer
-rw-r--r--build.gradle.kts5
-rw-r--r--gradle/libs.versions.toml2
-rw-r--r--src/main/kotlin/moe/nea/firmament/apis/Routes.kt38
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt63
-rw-r--r--src/main/kotlin/moe/nea/firmament/jarvis/JarvisIntegration.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt2
7 files changed, 86 insertions, 30 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index bd5b0bc..a69a1ec 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -82,7 +82,6 @@ val hotswap by configurations.creating {
}
val nonModImplentation by configurations.creating {
- extendsFrom(shadowMe)
configurations.implementation.get().extendsFrom(this)
}
@@ -106,6 +105,8 @@ dependencies {
implementation(libs.mixinextras)
include(libs.mixinextras)
+ nonModImplentation(libs.nealisp)
+ shadowMe(libs.nealisp)
modApi(libs.fabric.api)
modApi(libs.architectury)
@@ -117,7 +118,9 @@ dependencies {
exclude(module = "architectury")
exclude(module = "architectury-fabric")
}
+ nonModImplentation(libs.repoparser)
shadowMe(libs.repoparser)
+ nonModImplentation(libs.bundles.dbus)
shadowMe(libs.bundles.dbus)
fun ktor(mod: String) = "io.ktor:ktor-$mod-jvm:${libs.versions.ktor.get()}"
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index c21ece5..c3f3c43 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -24,6 +24,7 @@ freecammod = "1.2.0-mc1.20"
ncr = "Fabric-1.20-v2.2.0"
mixinextras = "0.2.0-beta.9"
jarvis = "1.1.1"
+nealisp = "1.0.0"
[libraries]
@@ -40,6 +41,7 @@ libgui = { module = "io.github.cottonmc:LibGui", version.ref = "libgui" }
mixinextras = { module = "com.github.llamalad7.mixinextras:mixinextras-fabric", version.ref = "mixinextras" }
jarvis_api = { module = "moe.nea.jarvis:jarvis-api", version.ref = "jarvis" }
jarvis_fabric = { module = "moe.nea.jarvis:jarvis-fabric", version.ref = "jarvis" }
+nealisp = { module = "moe.nea:nealisp", version.ref = "nealisp" }
# Runtime:
hotswap = { module = "virtual.github.hotswapagent:hotswap-agent", version.ref = "hotswap_agent" }
diff --git a/src/main/kotlin/moe/nea/firmament/apis/Routes.kt b/src/main/kotlin/moe/nea/firmament/apis/Routes.kt
index 71802a5..1d25ac1 100644
--- a/src/main/kotlin/moe/nea/firmament/apis/Routes.kt
+++ b/src/main/kotlin/moe/nea/firmament/apis/Routes.kt
@@ -6,23 +6,23 @@
package moe.nea.firmament.apis
-import io.ktor.client.call.body
-import io.ktor.client.request.get
-import io.ktor.client.request.parameter
-import io.ktor.http.URLProtocol
-import io.ktor.http.isSuccess
-import io.ktor.http.path
-import io.ktor.util.CaseInsensitiveMap
-import java.util.UUID
+import io.ktor.client.call.*
+import io.ktor.client.request.*
+import io.ktor.http.*
+import io.ktor.util.*
+import java.util.*
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import kotlin.collections.MutableMap
+import kotlin.collections.listOf
+import kotlin.collections.mutableMapOf
+import kotlin.collections.set
import moe.nea.firmament.Firmament
import moe.nea.firmament.util.MinecraftDispatcher
object Routes {
- val apiKey = "e721a103-96e0-400f-af2a-73b2a91007b1"
private val nameToUUID: MutableMap<String, Deferred<UUID?>> = CaseInsensitiveMap()
private val profiles: MutableMap<UUID, Deferred<Profiles?>> = mutableMapOf()
private val accounts: MutableMap<UUID, Deferred<PlayerData?>> = mutableMapOf()
@@ -64,15 +64,7 @@ object Routes {
return withContext(MinecraftDispatcher) {
accounts.computeIfAbsent(uuid) {
async(Firmament.coroutineScope.coroutineContext) {
- val response = Firmament.httpClient.get {
- url {
- protocol = URLProtocol.HTTPS
- host = "api.hypixel.net"
- path("player")
- parameter("key", apiKey)
- parameter("uuid", uuid)
- }
- }
+ val response = UrsaManager.request(listOf("v1", "hypixel","player", uuid.toString()))
if (!response.status.isSuccess()) {
launch(MinecraftDispatcher) {
@Suppress("DeferredResultUnused")
@@ -90,15 +82,7 @@ object Routes {
return withContext(MinecraftDispatcher) {
profiles.computeIfAbsent(uuid) {
async(Firmament.coroutineScope.coroutineContext) {
- val response = Firmament.httpClient.get {
- url {
- protocol = URLProtocol.HTTPS
- host = "api.hypixel.net"
- path("skyblock", "profiles")
- parameter("key", apiKey)
- parameter("uuid", uuid)
- }
- }
+ val response = UrsaManager.request(listOf("v1", "hypixel","profiles", uuid.toString()))
if (!response.status.isSuccess()) {
launch(MinecraftDispatcher) {
@Suppress("DeferredResultUnused")
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
index bebcbcc..5561476 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
@@ -9,7 +9,7 @@ package moe.nea.firmament.gui.profileviewer
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
import io.github.cottonmc.cotton.gui.widget.WTabPanel
-import java.util.UUID
+import java.util.*
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import kotlinx.coroutines.launch
import net.minecraft.text.Text
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
new file mode 100644
index 0000000..3c49443
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
@@ -0,0 +1,63 @@
+package moe.nea.firmament.gui.profileviewer
+
+import com.mojang.brigadier.StringReader
+import io.github.cottonmc.cotton.gui.client.CottonClientScreen
+import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
+import io.github.cottonmc.cotton.gui.widget.WGridPanel
+import io.github.cottonmc.cotton.gui.widget.WText
+import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
+import moe.nea.firmament.gui.WTitledItem
+import moe.nea.firmament.util.ScreenUtil
+import moe.nea.firmament.util.modifyLore
+import moe.nea.lisp.LispData
+import moe.nea.lisp.LispExecutionContext
+import moe.nea.lisp.LispParser
+import moe.nea.lisp.bind.AutoBinder
+import moe.nea.lisp.bind.LispBinding
+import moe.nea.lisp.bind.UnmapForeignObject
+import net.minecraft.command.argument.ItemStringReader
+import net.minecraft.item.ItemStack
+import net.minecraft.registry.Registries
+import net.minecraft.text.Text
+
+class ProfileViewerLibrary {
+
+ @LispBinding("mk-item")
+ fun makeItem(itemType: String, title: String, vararg lore: String): LispData.ForeignObject<ItemStack> {
+ val item = ItemStringReader.item(Registries.ITEM.readOnlyWrapper, StringReader(itemType))
+ val itemStack = ItemStack(item.item.value())
+ itemStack.nbt = item.nbt
+ itemStack.modifyLore { lore.map { Text.literal(it) } }
+ itemStack.setCustomName(Text.literal(title))
+ return LispData.ForeignObject(itemStack)
+ }
+
+ @LispBinding("def-page")
+ fun defPage(name: String, @UnmapForeignObject icon: ItemStack) {
+ pages.add(Pair(name, icon))
+ }
+
+ val pages = mutableListOf<Pair<String, ItemStack>>()
+ val coreEnvironment = LispExecutionContext()
+
+ fun run() {
+ val t = coreEnvironment.genBindings()
+ val ab = AutoBinder()
+ ab.bindTo(this, t)
+ val prog = LispParser.parse(
+ "testfile.lisp", """
+ (def-page "Test" (mk-item "minecraft:tnt" "§aThis is a test page" "§aMore text"))
+ (def-page "Skills" (mk-item "minecraft:diamond_sword" "§aThis is a test page" "§aMore text"))
+ """.trimIndent()
+ )
+ coreEnvironment.executeProgram(t, prog)
+ val light = LightweightGuiDescription()
+ val root = light.rootPanel as WGridPanel
+ root.setGaps(8, 8)
+ pages.forEachIndexed { i, (name, item) ->
+ root.add(WTitledItem(item), 0, i)
+ root.add(WText(Text.literal(name)).also { it.verticalAlignment = VerticalAlignment.CENTER }, 1, i, 6, 1)
+ }
+ ScreenUtil.setScreenLater(CottonClientScreen(light))
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/jarvis/JarvisIntegration.kt b/src/main/kotlin/moe/nea/firmament/jarvis/JarvisIntegration.kt
index 9c27030..d760862 100644
--- a/src/main/kotlin/moe/nea/firmament/jarvis/JarvisIntegration.kt
+++ b/src/main/kotlin/moe/nea/firmament/jarvis/JarvisIntegration.kt
@@ -42,6 +42,10 @@ class JarvisIntegration : JarvisPlugin {
}
}
+ override fun onHudEditorClosed() {
+ configs.forEach { it.save() }
+ }
+
override fun getAllConfigOptions(): List<JarvisConfigOption> {
return configs.flatMap { config ->
config.sortedOptions.map {
diff --git a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
index 51c8c22..fe2b4e5 100644
--- a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt
@@ -28,7 +28,7 @@ import moe.nea.firmament.util.json.DashlessUUIDSerializer
@JvmInline
@Serializable
value class SkyblockId(val neuItem: String) {
- val identifier get() = Identifier("skyblockitem", neuItem.lowercase().replace(";", "__"))
+ val identifier get() = Identifier("skyblockitem", neuItem.lowercase().replace(";", "__").replace(":", "___"))
/**
* A bazaar stock item id, as returned by the HyPixel bazaar api endpoint.