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/repo | |
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/repo')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt | 61 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt | 11 |
2 files changed, 27 insertions, 45 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt index 067069b..adeb1c5 100644 --- a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt +++ b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt @@ -1,13 +1,12 @@ /* * 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 */ package moe.nea.firmament.repo -import com.mojang.authlib.GameProfile -import com.mojang.authlib.minecraft.MinecraftProfileTexture import com.mojang.serialization.Dynamic import io.github.cottonmc.cotton.gui.client.CottonHud import io.github.moulberry.repo.IReloadable @@ -19,28 +18,27 @@ import java.util.concurrent.ConcurrentHashMap import org.apache.logging.log4j.LogManager import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlin.jvm.optionals.getOrNull import net.minecraft.SharedConstants -import net.minecraft.block.entity.SkullBlockEntity import net.minecraft.client.resource.language.I18n +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.NbtComponent import net.minecraft.datafixer.Schemas import net.minecraft.datafixer.TypeReferences import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtHelper -import net.minecraft.nbt.NbtList import net.minecraft.nbt.NbtOps -import net.minecraft.nbt.NbtString import net.minecraft.text.Text import moe.nea.firmament.Firmament import moe.nea.firmament.util.LegacyTagParser +import moe.nea.firmament.util.MC import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.appendLore -import moe.nea.firmament.util.getOrCreateList -import moe.nea.firmament.util.item.MinecraftProfileTextureKt -import moe.nea.firmament.util.item.MinecraftTexturesPayloadKt -import moe.nea.firmament.util.item.setTextures +import moe.nea.firmament.util.item.setCustomName +import moe.nea.firmament.util.item.setSkullOwner +import moe.nea.firmament.util.modifyLore import moe.nea.firmament.util.skyblockId object ItemCache : IReloadable { @@ -90,10 +88,11 @@ object ItemCache : IReloadable { val oldItemTag = get10809CompoundTag() val modernItemTag = oldItemTag.transformFrom10809ToModern() ?: return brokenItemStack(this) - val itemInstance = ItemStack.fromNbt(modernItemTag) - if (itemInstance.nbt?.contains("Enchantments") == true) { - itemInstance.enchantments.add(NbtCompound()) - } + val itemInstance = + ItemStack.fromNbt(MC.defaultRegistries, modernItemTag).getOrNull() ?: return brokenItemStack(this) + val extraAttributes = oldItemTag.getCompound("tag").getCompound("ExtraAttributes") + if (extraAttributes != null) + itemInstance.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(extraAttributes)) return itemInstance } catch (e: Exception) { e.printStackTrace() @@ -117,19 +116,11 @@ object ItemCache : IReloadable { } fun ItemStack.applyLoreReplacements(loreReplacements: Map<String, String>) { - val component = getOrCreateSubNbt("display") - val lore = component.getOrCreateList("Lore", NbtString.STRING_TYPE) - val newLore = NbtList() - lore.forEach { - newLore.add( - NbtString.of( - Text.Serialization.toJsonString( - Text.Serialization.fromJson(it.asString())!!.applyLoreReplacements(loreReplacements) - ) - ) - ) + modifyLore { lore -> + lore.map { + it.applyLoreReplacements(loreReplacements) + } } - component["Lore"] = newLore } fun Text.applyLoreReplacements(loreReplacements: Map<String, String>): Text { @@ -141,10 +132,8 @@ object ItemCache : IReloadable { return Text.literal(string).styled { this.style } } - fun NEUItem.getIdentifier() = skyblockId.identifier - var job: Job? = null override fun reload(repository: NEURepository) { @@ -189,21 +178,7 @@ object ItemCache : IReloadable { } val itemStack = ItemStack(Items.PLAYER_HEAD) itemStack.setCustomName(Text.literal("§r§6" + NumberFormat.getInstance().format(coinAmount) + " Coins")) - val nbt: NbtCompound = itemStack.orCreateNbt - nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile( - NbtCompound(), - GameProfile(uuid, "CoolGuy123").also { - it.setTextures( - MinecraftTexturesPayloadKt( - mapOf( - MinecraftProfileTexture.Type.SKIN to MinecraftProfileTextureKt(texture), - ), - uuid, - "CoolGuy123" - ) - ) - } - ) + itemStack.setSkullOwner(uuid, texture) return itemStack } } diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt index 810e2a4..a26fa19 100644 --- a/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt +++ b/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt @@ -22,9 +22,12 @@ import net.minecraft.resource.InputSupplier import net.minecraft.resource.NamespaceResourceManager import net.minecraft.resource.Resource import net.minecraft.resource.ResourcePack +import net.minecraft.resource.ResourcePackInfo +import net.minecraft.resource.ResourcePackSource import net.minecraft.resource.ResourceType import net.minecraft.resource.metadata.ResourceMetadata import net.minecraft.resource.metadata.ResourceMetadataReader +import net.minecraft.text.Text import net.minecraft.util.Identifier import net.minecraft.util.PathUtil import moe.nea.firmament.Firmament @@ -113,12 +116,16 @@ class RepoModResourcePack(val basePath: Path) : ModResourcePack { ) } - override fun getName(): String { - return "NEU Repo Resources" + override fun getInfo(): ResourcePackInfo { + return ResourcePackInfo("neurepo", Text.literal("NEU Repo"), ResourcePackSource.BUILTIN, Optional.empty()) } override fun getFabricModMetadata(): ModMetadata { return FabricLoader.getInstance().getModContainer("firmament") .get().metadata } + + override fun createOverlay(overlay: String): ModResourcePack { + return RepoModResourcePack(basePath.resolve(overlay)) + } } |