diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:04:45 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:15:54 +0200 |
commit | 7e0151569477df63601be50c82177ecfd21e5deb (patch) | |
tree | f30e5440a1855de92d2b424ef79339d3d6cf5f34 /src/main/kotlin/moe/nea/firmament/features/texturepack | |
parent | 041da7c7d179df01c4048a81ddf40a9f13c3ce77 (diff) | |
download | firmament-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/texturepack')
4 files changed, 20 insertions, 42 deletions
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) } |