aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-26 18:04:45 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-26 18:15:54 +0200
commit7e0151569477df63601be50c82177ecfd21e5deb (patch)
treef30e5440a1855de92d2b424ef79339d3d6cf5f34 /src/main/kotlin/moe/nea/firmament/features
parent041da7c7d179df01c4048a81ddf40a9f13c3ce77 (diff)
downloadFirmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.gz
Firmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.bz2
Firmament-7e0151569477df63601be50c82177ecfd21e5deb.zip
Bump to 1.20.5
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt14
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt8
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/VirtualInventory.kt6
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/mining/PickaxeAbility.kt14
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt40
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/DisplayNamePredicate.kt9
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt10
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/StringMatcher.kt3
9 files changed, 46 insertions, 62 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
index 9341dad..99ef0d5 100644
--- a/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -8,9 +9,9 @@ package moe.nea.firmament.features.debug
import net.minecraft.block.SkullBlock
import net.minecraft.block.entity.SkullBlockEntity
+import net.minecraft.component.DataComponentTypes
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
-import net.minecraft.nbt.NbtHelper
import net.minecraft.text.Text
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.HitResult
@@ -27,7 +28,6 @@ import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.ClipboardUtils
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.focusedItemStack
-import moe.nea.firmament.util.getOrCreateCompoundTag
import moe.nea.firmament.util.skyBlockId
object PowerUserTools : FirmamentFeature {
@@ -120,7 +120,8 @@ object PowerUserTools : FirmamentFeature {
lastCopiedStack =
Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.modelid", model.toString()))
} else if (it.matches(TConfig.copyNbtData)) {
- val nbt = item.orCreateNbt.toString()
+ // TODO: copy full nbt
+ val nbt = item.get(DataComponentTypes.CUSTOM_DATA)?.nbt?.toString() ?: "<empty>"
ClipboardUtils.setTextContent(nbt)
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.nbt"))
} else if (it.matches(TConfig.copySkullTexture)) {
@@ -128,7 +129,7 @@ object PowerUserTools : FirmamentFeature {
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-skull"))
return@subscribe
}
- val profile = NbtHelper.toGameProfile(item.orCreateNbt.getOrCreateCompoundTag("SkullOwner"))
+ val profile = item.get(DataComponentTypes.PROFILE)
if (profile == null) {
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.skull-id.fail.no-profile"))
return@subscribe
@@ -140,7 +141,10 @@ object PowerUserTools : FirmamentFeature {
}
ClipboardUtils.setTextContent(skullTexture.toString())
lastCopiedStack =
- Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.skull-id", skullTexture.toString()))
+ Pair(
+ item,
+ Text.stringifiedTranslatable("firmament.tooltip.copied.skull-id", skullTexture.toString())
+ )
println("Copied skull id: $skullTexture")
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
index f3af27d..ac53546 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -9,7 +10,6 @@ package moe.nea.firmament.features.inventory
import java.awt.Color
import net.minecraft.client.gui.DrawContext
import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NbtElement
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
import moe.nea.firmament.events.HotbarItemRenderEvent
@@ -17,6 +17,8 @@ import moe.nea.firmament.events.SlotRenderEvents
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.item.loreAccordingToNbt
+import moe.nea.firmament.util.unformattedString
object ItemRarityCosmetics : FirmamentFeature {
override val identifier: String
@@ -47,9 +49,7 @@ object ItemRarityCosmetics : FirmamentFeature {
}
private val ItemStack.skyblockLoreRarityColor: Triple<Float, Float, Float>?
get() {
- val lore =
- getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
- val entry = lore.getString(lore.size - 1)
+ val entry = loreAccordingToNbt.lastOrNull()?.unformattedString ?: ""
return rarityToColor.entries.find { (k, v) -> k in entry }?.value
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
index 43243f1..9bf2182 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
@@ -1,8 +1,10 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
+
@file:UseSerializers(DashlessUUIDSerializer::class)
package moe.nea.firmament.features.inventory
@@ -90,7 +92,7 @@ object SlotLocking : FirmamentFeature {
if (sellItem == null) return false
if (sellItem.displayNameAccordingToNbt?.unformattedString == "Sell Item") return true
val lore = sellItem.loreAccordingToNbt
- return (lore.lastOrNull() ?: return false).value?.unformattedString == "Click to buyback!"
+ return (lore.lastOrNull() ?: return false).unformattedString == "Click to buyback!"
}
override fun onLoad() {
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 102b197..6b467eb 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
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -22,6 +23,7 @@ import net.minecraft.nbt.NbtList
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import net.minecraft.nbt.NbtSizeTracker
+import moe.nea.firmament.util.MC
@Serializable(with = VirtualInventory.Serializer::class)
data class VirtualInventory(
@@ -44,13 +46,13 @@ data class VirtualInventory(
val s = decoder.decodeString()
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) })
+ return VirtualInventory(items.map { ItemStack.fromNbtOrEmpty(MC.defaultRegistries, it as NbtCompound) })
}
override fun serialize(encoder: Encoder, value: VirtualInventory) {
val list = NbtList()
value.stacks.forEach {
- list.add(NbtCompound().also(it::writeNbt))
+ list.add(it.encode(MC.defaultRegistries))
}
val baos = ByteArrayOutputStream()
NbtIo.writeCompressed(NbtCompound().also { it.put(INVENTORY, list) }, baos)
diff --git a/src/main/kotlin/moe/nea/firmament/features/mining/PickaxeAbility.kt b/src/main/kotlin/moe/nea/firmament/features/mining/PickaxeAbility.kt
index 24a39e0..956ffc3 100644
--- a/src/main/kotlin/moe/nea/firmament/features/mining/PickaxeAbility.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/mining/PickaxeAbility.kt
@@ -91,11 +91,9 @@ object PickaxeAbility : FirmamentFeature {
DurabilityBarEvent.subscribe {
if (!TConfig.drillFuelBar) return@subscribe
val lore = it.item.loreAccordingToNbt
- if (lore.lastOrNull()?.value?.unformattedString?.contains("DRILL") != true) return@subscribe
+ if (lore.lastOrNull()?.unformattedString?.contains("DRILL") != true) return@subscribe
val maxFuel = lore.firstNotNullOfOrNull {
- fuelPattern.useMatch(
- it.value?.unformattedString ?: return@firstNotNullOfOrNull null
- ) {
+ fuelPattern.useMatch(it.unformattedString) {
parseShortNumber(group("maxFuel"))
}
} ?: return@subscribe
@@ -115,7 +113,7 @@ object PickaxeAbility : FirmamentFeature {
if (MC.screen?.title?.unformattedString == "Heart of the Mountain") {
val name = it.stack.displayNameAccordingToNbt?.unformattedString ?: return@subscribe
val cooldown = it.stack.loreAccordingToNbt.firstNotNullOfOrNull {
- cooldownPattern.useMatch(it.value?.unformattedString ?: return@firstNotNullOfOrNull null) {
+ cooldownPattern.useMatch(it.unformattedString) {
parseTimePattern(group("cooldown"))
}
} ?: return@subscribe
@@ -134,15 +132,15 @@ object PickaxeAbility : FirmamentFeature {
fun getCooldownFromLore(itemStack: ItemStack): PickaxeAbilityData? {
val lore = itemStack.loreAccordingToNbt
- if (!lore.any { it.value?.unformattedString?.contains("Breaking Power") == true })
+ if (!lore.any { it.unformattedString.contains("Breaking Power") == true })
return null
val cooldown = lore.firstNotNullOfOrNull {
- cooldownPattern.useMatch(it.value?.unformattedString ?: return@firstNotNullOfOrNull null) {
+ cooldownPattern.useMatch(it.unformattedString) {
parseTimePattern(group("cooldown"))
}
} ?: return null
val name = lore.firstNotNullOfOrNull {
- abilityPattern.useMatch(it.value?.unformattedString ?: return@firstNotNullOfOrNull null) {
+ abilityPattern.useMatch(it.unformattedString) {
group("name")
}
} ?: return null
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 3fb5e9c..9c2eafc 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
@@ -7,21 +7,20 @@
package moe.nea.firmament.features.texturepack
-import com.mojang.authlib.GameProfile
import com.mojang.authlib.minecraft.MinecraftProfileTexture
+import com.mojang.authlib.properties.Property
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import net.minecraft.block.SkullBlock
import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.RenderLayer
import net.minecraft.client.util.ModelIdentifier
-import net.minecraft.item.ItemStack
+import net.minecraft.component.type.ProfileComponent
import net.minecraft.util.Identifier
import moe.nea.firmament.events.CustomItemModelEvent
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,12 +52,12 @@ object CustomSkyBlockTextures : FirmamentFeature {
}
}
- private val skullTextureCache = mutableMapOf<IdentityCharacteristics<GameProfile>, Any>()
+ private val skullTextureCache = mutableMapOf<IdentityCharacteristics<ProfileComponent>, Any>()
private val sentinelPresentInvalid = Object()
private val mcUrlRegex = "https?://textures.minecraft.net/texture/([a-fA-F0-9]+)".toRegex()
- fun getSkullId(profile: GameProfile): String? {
- val textureProperty = MC.instance.sessionService.getPackedTextures(profile) ?: return null
+
+ fun getSkullId(textureProperty: Property): String? {
val texture = decodeProfileTextureProperty(textureProperty) ?: return null
val textureUrl =
texture.textures[MinecraftProfileTexture.Type.SKIN]?.url ?: return null
@@ -66,40 +65,23 @@ object CustomSkyBlockTextures : FirmamentFeature {
return mcUrlData.groupValues[1]
}
- fun getSkullTexture(profile: GameProfile): Identifier? {
- val id = getSkullId(profile) ?: return null
+ fun getSkullTexture(profile: ProfileComponent): Identifier? {
+ val id = getSkullId(profile.properties["textures"].firstOrNull() ?: return null) ?: return null
return Identifier("firmskyblock", "textures/placedskull/$id.png")
}
- fun getArmorTexture(
- itemStack: ItemStack, secondLayer: Boolean,
- overlay: String?
- ): Identifier? {
- val modelIdentifier = CustomItemModelEvent.getModelIdentifier(itemStack) ?: return null
- // Vanilla scheme: "textures/models/armor/" + var10000 + "_layer_" + (secondLayer ? 2 : 1) + (overlay == null ? "" : "_" + overlay) + ".png";
- val overlayPart = if (overlay != null) "_$overlay" else ""
- val identifier = Identifier(
- modelIdentifier.namespace,
- "textures/models/armor/${modelIdentifier.path}_layer_${if (secondLayer) 2 else 1}$overlayPart.png"
- )
- if (MC.resourceManager.getResource(identifier).isPresent) {
- return identifier
- }
- return null
- }
-
fun modifySkullTexture(
type: SkullBlock.SkullType?,
- profile: GameProfile?,
+ component: ProfileComponent?,
cir: CallbackInfoReturnable<RenderLayer>
) {
if (type != SkullBlock.Type.PLAYER) return
if (!TConfig.skullsEnabled) return
- if (profile == null) return
- val ic = IdentityCharacteristics(profile)
+ if (component == null) return
+ val ic = IdentityCharacteristics(component)
val n = skullTextureCache.getOrPut(ic) {
- val id = getSkullTexture(profile) ?: return@getOrPut sentinelPresentInvalid
+ val id = getSkullTexture(component) ?: return@getOrPut sentinelPresentInvalid
if (!MinecraftClient.getInstance().resourceManager.getResource(id).isPresent) {
return@getOrPut sentinelPresentInvalid
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/DisplayNamePredicate.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/DisplayNamePredicate.kt
index 373910a..7a1255b 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/DisplayNamePredicate.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/DisplayNamePredicate.kt
@@ -10,14 +10,13 @@ import com.google.gson.JsonElement
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtString
+import moe.nea.firmament.util.item.displayNameAccordingToNbt
+import moe.nea.firmament.util.item.loreAccordingToNbt
data class DisplayNamePredicate(val stringMatcher: StringMatcher) : FirmamentModelPredicate {
override fun test(stack: ItemStack): Boolean {
- val display = stack.getOrCreateSubNbt(ItemStack.DISPLAY_KEY)
- return if (display.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt()))
- stringMatcher.matches(display.get(ItemStack.NAME_KEY) as NbtString)
- else
- false
+ val display = stack.displayNameAccordingToNbt
+ return stringMatcher.matches(display)
}
object Parser : FirmamentModelPredicateParser {
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
index 604d29c..d10814d 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
@@ -8,8 +8,7 @@ package moe.nea.firmament.features.texturepack
import com.google.gson.JsonElement
import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NbtElement
-import net.minecraft.nbt.NbtString
+import moe.nea.firmament.util.item.loreAccordingToNbt
class LorePredicate(val matcher: StringMatcher) : FirmamentModelPredicate {
object Parser : FirmamentModelPredicateParser {
@@ -19,10 +18,7 @@ class LorePredicate(val matcher: StringMatcher) : FirmamentModelPredicate {
}
override fun test(stack: ItemStack): Boolean {
- val display = stack.getOrCreateSubNbt(ItemStack.DISPLAY_KEY)
- if (!display.contains(ItemStack.LORE_KEY, NbtElement.LIST_TYPE.toInt()))
- return false
- val lore = display.getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
- return lore.any { matcher.matches(it as NbtString)}
+ val lore = stack.loreAccordingToNbt
+ return lore.any { matcher.matches(it) }
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/StringMatcher.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/StringMatcher.kt
index e9d39a8..8c1ccbc 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/StringMatcher.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/StringMatcher.kt
@@ -12,6 +12,7 @@ import com.google.gson.JsonPrimitive
import java.util.function.Predicate
import net.minecraft.nbt.NbtString
import net.minecraft.text.Text
+import moe.nea.firmament.util.MC
import moe.nea.firmament.util.removeColorCodes
interface StringMatcher {
@@ -27,7 +28,7 @@ interface StringMatcher {
val isString = stringStart >= 0 && string.subSequence(0, stringStart).isBlank()
val isJson = jsonStart >= 0 && string.subSequence(0, jsonStart).isBlank()
if (isString || isJson)
- return matches(Text.Serialization.fromJson(string) ?: return false)
+ return matches(Text.Serialization.fromJson(string, MC.defaultRegistries) ?: return false)
return matches(string)
}