aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-21 14:06:34 +0100
committerLinnea Gräf <nea@nea.moe>2024-01-21 14:06:34 +0100
commit3e1f75e32253bca3312f478a60d315bec37bc112 (patch)
tree14260e41bd2d8669d6d3ffa9a9a30d1d9ee2fe6c /src/main/kotlin/moe/nea/firmament
parent18ebd21cb0f97dea8367e65002e0bf32e5c686e2 (diff)
downloadFirmament-3e1f75e32253bca3312f478a60d315bec37bc112.tar.gz
Firmament-3e1f75e32253bca3312f478a60d315bec37bc112.tar.bz2
Firmament-3e1f75e32253bca3312f478a60d315bec37bc112.zip
Bump to 1.20.4
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt3
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt6
-rw-r--r--src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt6
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt15
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt6
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/textutil.kt6
8 files changed, 28 insertions, 22 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt
index 3c7bedd..102b197 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt
@@ -21,6 +21,7 @@ import net.minecraft.nbt.NbtIo
import net.minecraft.nbt.NbtList
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
+import net.minecraft.nbt.NbtSizeTracker
@Serializable(with = VirtualInventory.Serializer::class)
data class VirtualInventory(
@@ -41,7 +42,7 @@ data class VirtualInventory(
override fun deserialize(decoder: Decoder): VirtualInventory {
val s = decoder.decodeString()
- val n = NbtIo.readCompressed(ByteArrayInputStream(s.decodeBase64Bytes()))
+ val n = NbtIo.readCompressed(ByteArrayInputStream(s.decodeBase64Bytes()), NbtSizeTracker.of(100_000_000))
val items = n.getList(INVENTORY, NbtCompound.COMPOUND_TYPE.toInt())
return VirtualInventory(items.map { ItemStack.fromNbt(it as NbtCompound) })
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
index 66c0987..11b0a06 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
@@ -20,6 +20,7 @@ import moe.nea.firmament.events.TickEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.IdentityCharacteristics
+import moe.nea.firmament.util.MC
import moe.nea.firmament.util.item.decodeProfileTextureProperty
import moe.nea.firmament.util.skyBlockId
@@ -53,10 +54,9 @@ object CustomSkyBlockTextures : FirmamentFeature {
private val skullTextureCache = mutableMapOf<IdentityCharacteristics<GameProfile>, Any>()
private val sentinelPresentInvalid = Object()
- val mcUrlRegex = "https?://textures.minecraft.net/texture/([a-fA-F0-9]+)".toRegex()
+ private val mcUrlRegex = "https?://textures.minecraft.net/texture/([a-fA-F0-9]+)".toRegex()
fun getSkullId(profile: GameProfile): String? {
- val textures = profile.properties.get(PlayerSkinProvider.TEXTURES)
- val textureProperty = textures.singleOrNull() ?: return null
+ val textureProperty = MC.instance.sessionService.getPackedTextures(profile) ?: return null
val texture = decodeProfileTextureProperty(textureProperty) ?: return null
val textureUrl =
texture.textures[MinecraftProfileTexture.Type.SKIN]?.url ?: return null
diff --git a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
index f6ae2aa..0688497 100644
--- a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
+++ b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
@@ -116,8 +116,8 @@ object ItemCache : IReloadable {
lore.forEach {
newLore.add(
NbtString.of(
- Text.Serializer.toJson(
- Text.Serializer.fromJson(it.asString())!!.applyLoreReplacements(loreReplacements)
+ Text.Serialization.toJsonString(
+ Text.Serialization.fromJson(it.asString())!!.applyLoreReplacements(loreReplacements)
)
)
)
diff --git a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
index cccff64..4f8c90c 100644
--- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt
@@ -17,17 +17,17 @@ fun ItemStack.appendLore(args: List<Text>) {
val compoundTag = getOrCreateSubNbt("display")
val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE)
for (arg in args) {
- loreList.add(NbtString.of(Text.Serializer.toJson(arg)))
+ loreList.add(NbtString.of(Text.Serialization.toJsonString(arg)))
}
}
fun ItemStack.modifyLore(update: (List<Text>) -> List<Text>) {
val compoundTag = getOrCreateSubNbt("display")
val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE)
- val parsed = loreList.map { Text.Serializer.fromJson(it.asString())!! }
+ val parsed = loreList.map { Text.Serialization.fromJson(it.asString())!! }
val updated = update(parsed)
loreList.clear()
- loreList.addAll(updated.map { NbtString.of(Text.Serializer.toJson(it)) })
+ loreList.addAll(updated.map { NbtString.of(Text.Serialization.toJsonString(it)) })
}
diff --git a/src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt
index 1ddf1db..1935a14 100644
--- a/src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/ScoreboardUtil.kt
@@ -6,7 +6,8 @@
package moe.nea.firmament.util
-import java.util.Optional
+import java.util.*
+import net.minecraft.client.gui.hud.InGameHud
import net.minecraft.scoreboard.ScoreboardDisplaySlot
import net.minecraft.scoreboard.Team
import net.minecraft.text.StringVisitable
@@ -17,10 +18,14 @@ import net.minecraft.util.Formatting
fun getScoreboardLines(): List<Text> {
val scoreboard = MC.player?.scoreboard ?: return listOf()
val activeObjective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.SIDEBAR) ?: return listOf()
- return scoreboard.getAllPlayerScores(activeObjective).reversed().take(15).map {
- val team = scoreboard.getPlayerTeam(it.playerName)
- Team.decorateName(team, Text.literal(it.playerName))
- }
+ return scoreboard.getScoreboardEntries(activeObjective)
+ .filter { !it.hidden() }
+ .sortedWith(InGameHud.SCOREBOARD_ENTRY_COMPARATOR)
+ .take(15).map {
+ val team = scoreboard.getScoreHolderTeam(it.owner)
+ val text = it.name()
+ Team.decorateName(team, text)
+ }
}
diff --git a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
index ff3e09d..d226da0 100644
--- a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt
@@ -17,12 +17,12 @@ fun textFromNbt() {
val ItemStack.loreAccordingToNbt
get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
- .map { lazy(LazyThreadSafetyMode.NONE) { Text.Serializer.fromJson((it as NbtString).asString()) } }
+ .map { lazy(LazyThreadSafetyMode.NONE) { Text.Serialization.fromJson((it as NbtString).asString()) } }
val ItemStack.displayNameAccordingToNbt
get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).let {
if (it.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt()))
- Text.Serializer.fromJson(it.getString(ItemStack.NAME_KEY))
+ Text.Serialization.fromJson(it.getString(ItemStack.NAME_KEY))
else
null
}
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 39088ec..4b72c5e 100644
--- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt
@@ -42,11 +42,13 @@ data class MinecraftTexturesPayloadKt(
fun GameProfile.setTextures(textures: MinecraftTexturesPayloadKt) {
val json = Firmament.json.encodeToString(textures)
val encoded = java.util.Base64.getEncoder().encodeToString(json.encodeToByteArray())
- properties.put(PlayerSkinProvider.TEXTURES, Property(PlayerSkinProvider.TEXTURES, encoded))
+ properties.put(propertyTextures, Property(propertyTextures, encoded))
}
+private val propertyTextures = "textures"
+
fun decodeProfileTextureProperty(property: Property): MinecraftTexturesPayloadKt? {
- assertTrueOr(property.name == PlayerSkinProvider.TEXTURES) { return null }
+ assertTrueOr(property.name == propertyTextures) { return null }
return try {
var encodedF: String = property.value
while (encodedF.length % 4 != 0 && encodedF.last() == '=') {
diff --git a/src/main/kotlin/moe/nea/firmament/util/textutil.kt b/src/main/kotlin/moe/nea/firmament/util/textutil.kt
index 2ed9af3..f811bd8 100644
--- a/src/main/kotlin/moe/nea/firmament/util/textutil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/textutil.kt
@@ -6,9 +6,8 @@
package moe.nea.firmament.util
-import net.minecraft.text.LiteralTextContent
+import net.minecraft.text.PlainTextContent
import net.minecraft.text.Text
-import net.minecraft.text.TextContent
import net.minecraft.text.TranslatableTextContent
import moe.nea.firmament.Firmament
@@ -33,8 +32,7 @@ class TextMatcher(text: Text) {
state.offset = 0
state.currentText = firstOrNull
state.textContent = when (val content = firstOrNull.content) {
- is LiteralTextContent -> content.string
- TextContent.EMPTY -> ""
+ is PlainTextContent.Literal -> content.string
else -> {
Firmament.logger.warn("TextContent of type ${content.javaClass} not understood.")
return false