diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
3 files changed, 59 insertions, 4 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/IdentityCharacteristics.kt b/src/main/kotlin/moe/nea/firmament/util/IdentityCharacteristics.kt new file mode 100644 index 0000000..e6dad79 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/IdentityCharacteristics.kt @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.util + +class IdentityCharacteristics<T>(val value: T) { + override fun equals(other: Any?): Boolean { + return value === other + } + + override fun hashCode(): Int { + return System.identityHashCode(value) + } +} diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 78f2eec..0c09306 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -7,21 +7,44 @@ package moe.nea.firmament.util import io.github.moulberry.repo.data.Coordinate +import java.util.concurrent.ConcurrentLinkedQueue import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.screen.ingame.HandledScreen +import net.minecraft.text.Text import net.minecraft.util.math.BlockPos +import moe.nea.firmament.events.TickEvent object MC { + + private val messageQueue = ConcurrentLinkedQueue<Text>() + + init { + TickEvent.subscribe { + while (true) { + inGameHud.chatHud.addMessage(messageQueue.poll() ?: break) + } + } + } + + fun sendChat(text: Text) { + if (instance.isOnThread) + inGameHud.chatHud.addMessage(text) + else + messageQueue.add(text) + } + fun sendCommand(command: String) { player?.networkHandler?.sendCommand(command) } + inline val instance get() = MinecraftClient.getInstance() inline val keyboard get() = MinecraftClient.getInstance().keyboard inline val textureManager get() = MinecraftClient.getInstance().textureManager inline val inGameHud get() = MinecraftClient.getInstance().inGameHud inline val font get() = MinecraftClient.getInstance().textRenderer inline val soundManager get() = MinecraftClient.getInstance().soundManager inline val player get() = MinecraftClient.getInstance().player + inline val camera get() = MinecraftClient.getInstance().cameraEntity inline val world get() = MinecraftClient.getInstance().world inline var screen get() = MinecraftClient.getInstance().currentScreen diff --git a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt index 5b440b1..4d4d386 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt @@ -11,14 +11,16 @@ package moe.nea.firmament.util.item import com.mojang.authlib.GameProfile import com.mojang.authlib.minecraft.MinecraftProfileTexture import com.mojang.authlib.properties.Property -import java.util.UUID +import java.util.* import kotlinx.datetime.Clock import kotlinx.datetime.Instant import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers +import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import net.minecraft.client.texture.PlayerSkinProvider import moe.nea.firmament.Firmament +import moe.nea.firmament.util.assertTrueOr import moe.nea.firmament.util.json.DashlessUUIDSerializer import moe.nea.firmament.util.json.InstantAsLongSerializer @@ -30,9 +32,9 @@ data class MinecraftProfileTextureKt( @Serializable data class MinecraftTexturesPayloadKt( - val textures: Map<MinecraftProfileTexture.Type, MinecraftProfileTextureKt>, - val profileId: UUID, - val profileName: String, + val textures: Map<MinecraftProfileTexture.Type, MinecraftProfileTextureKt> = mapOf(), + val profileId: UUID? = null, + val profileName: String? = null, val isPublic: Boolean = true, val timestamp: Instant = Clock.System.now(), ) @@ -43,3 +45,16 @@ fun GameProfile.setTextures(textures: MinecraftTexturesPayloadKt) { properties.put(PlayerSkinProvider.TEXTURES, Property(PlayerSkinProvider.TEXTURES, encoded)) } +fun decodeProfileTextureProperty(property: Property): MinecraftTexturesPayloadKt? { + assertTrueOr(property.name == PlayerSkinProvider.TEXTURES) { return null } + try { + val json = java.util.Base64.getDecoder().decode(property.value).decodeToString() + return Firmament.json.decodeFromString<MinecraftTexturesPayloadKt>(json) + } catch (e: Exception) { + // Malformed profile data + if (Firmament.DEBUG) + e.printStackTrace() + return null + } +} + |