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/util | |
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/util')
7 files changed, 37 insertions, 70 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt index 5a7a116..4ae226e 100644 --- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt +++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt @@ -10,33 +10,22 @@ package moe.nea.firmament.util import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtList -import net.minecraft.nbt.NbtString import net.minecraft.text.Text +import moe.nea.firmament.util.item.loreAccordingToNbt fun ItemStack.appendLore(args: List<Text>) { if (args.isEmpty()) return - val compoundTag = getOrCreateSubNbt("display") - val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE) - for (arg in args) { - loreList.add(NbtString.of(Text.Serialization.toJsonString(arg))) + modifyLore { + val loreList = loreAccordingToNbt.toMutableList() + for (arg in args) { + loreList.add(arg) + } + loreList } } 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.Serialization.fromJson(it.asString())!! } - val updated = update(parsed) - loreList.clear() - loreList.addAll(updated.map { NbtString.of(Text.Serialization.toJsonString(it)) }) -} - - -fun NbtCompound.getOrCreateList(label: String, tag: Byte): NbtList = getList(label, tag.toInt()).also { - put(label, it) -} - -fun NbtCompound.getOrCreateCompoundTag(label: String): NbtCompound = getCompound(label).also { - put(label, it) + val loreList = loreAccordingToNbt + loreAccordingToNbt = update(loreList) } diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 5c4bf5c..2fb1c75 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.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 */ @@ -7,13 +8,12 @@ package moe.nea.firmament.util import io.github.moulberry.repo.data.Coordinate -import java.time.Instant import java.util.concurrent.ConcurrentLinkedQueue import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.network.message.ArgumentSignatureDataMap -import net.minecraft.network.message.LastSeenMessagesCollector.LastSeenMessages import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket +import net.minecraft.registry.BuiltinRegistries +import net.minecraft.registry.RegistryWrapper import net.minecraft.resource.ReloadableResourceManagerImpl import net.minecraft.text.Text import net.minecraft.util.math.BlockPos @@ -40,14 +40,9 @@ object MC { fun sendServerCommand(command: String) { val nh = player?.networkHandler ?: return - val lastSeenMessages: LastSeenMessages = nh.lastSeenMessagesCollector.collect() nh.sendPacket( CommandExecutionC2SPacket( command, - Instant.now(), - 0L, - ArgumentSignatureDataMap.EMPTY, - lastSeenMessages.update() ) ) } @@ -77,6 +72,8 @@ object MC { set(value) = MinecraftClient.getInstance().setScreen(value) inline val handledScreen: HandledScreen<*>? get() = MinecraftClient.getInstance().currentScreen as? HandledScreen<*> inline val window get() = MinecraftClient.getInstance().window + inline val currentRegistries: RegistryWrapper.WrapperLookup? get() = world?.registryManager + val defaultRegistries: RegistryWrapper.WrapperLookup = BuiltinRegistries.createWrapperLookup() } diff --git a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt index fb63eba..413231d 100644 --- a/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt +++ b/src/main/kotlin/moe/nea/firmament/util/SkyblockId.kt @@ -16,6 +16,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json +import net.minecraft.component.DataComponentTypes import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.util.Identifier @@ -76,7 +77,7 @@ data class HypixelPetInfo( private val jsonparser = Json { ignoreUnknownKeys = true } val ItemStack.extraAttributes: NbtCompound - get() = getOrCreateSubNbt("ExtraAttributes") + get() = get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: NbtCompound() val ItemStack.skyblockUUIDString: String? get() = extraAttributes.getString("uuid")?.takeIf { it.isNotBlank() } @@ -121,7 +122,7 @@ val ItemStack.skyBlockId: SkyblockId? else SkyblockId("${enchantName.uppercase()};${enchantmentData.getInt(enchantName)}") } - // TODO: PARTY_HAT_CRAB{,_ANIMATED,_SLOTH} + // TODO: PARTY_HAT_CRAB{,_ANIMATED,_SLOTH},POTION else -> { SkyblockId(id) } diff --git a/src/main/kotlin/moe/nea/firmament/util/data/ProfileSpecificDataHolder.kt b/src/main/kotlin/moe/nea/firmament/util/data/ProfileSpecificDataHolder.kt index a016c32..063076b 100644 --- a/src/main/kotlin/moe/nea/firmament/util/data/ProfileSpecificDataHolder.kt +++ b/src/main/kotlin/moe/nea/firmament/util/data/ProfileSpecificDataHolder.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 */ @@ -35,7 +36,6 @@ abstract class ProfileSpecificDataHolder<S>( init { allConfigs = readValues() - readValues() IDataHolder.putDataHolder(this::class, this) } 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 80628ae..c366dc2 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/NbtItemData.kt @@ -7,27 +7,20 @@ package moe.nea.firmament.util.item +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.LoreComponent import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtString import net.minecraft.text.Text -fun textFromNbt() { - -} - -val ItemStack.loreAccordingToNbt - get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt()) - .map { - lazy(LazyThreadSafetyMode.NONE) { - Text.Serialization.fromJson((it as NbtString).asString()) - } - } +var ItemStack.loreAccordingToNbt + get() = get(DataComponentTypes.LORE)?.lines ?: listOf() + set(value) { + set(DataComponentTypes.LORE, LoreComponent(value)) + } val ItemStack.displayNameAccordingToNbt - get() = getOrCreateSubNbt(ItemStack.DISPLAY_KEY).let { - if (it.contains(ItemStack.NAME_KEY, NbtElement.STRING_TYPE.toInt())) - Text.Serialization.fromJson(it.getString(ItemStack.NAME_KEY)) - else - null - } + get() = get(DataComponentTypes.CUSTOM_NAME) ?: get(DataComponentTypes.ITEM_NAME) ?: item.name + +fun ItemStack.setCustomName(literal: Text) { + set(DataComponentTypes.CUSTOM_NAME, literal) +} 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 a061ee4..96bf49a 100644 --- a/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/item/SkullItemData.kt @@ -17,15 +17,12 @@ 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.block.entity.SkullBlockEntity +import net.minecraft.component.DataComponentTypes +import net.minecraft.component.type.ProfileComponent import net.minecraft.item.ItemStack import net.minecraft.item.Items -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtHelper import moe.nea.firmament.Firmament -import moe.nea.firmament.repo.set import moe.nea.firmament.util.assertTrueOr import moe.nea.firmament.util.json.DashlessUUIDSerializer import moe.nea.firmament.util.json.InstantAsLongSerializer @@ -60,11 +57,7 @@ fun ItemStack.setEncodedSkullOwner(uuid: UUID, encodedData: String) { assert(this.item == Items.PLAYER_HEAD) val gameProfile = GameProfile(uuid, "LameGuy123") gameProfile.properties.put(propertyTextures, Property(propertyTextures, encodedData.padBase64())) - val nbt: NbtCompound = this.orCreateNbt - nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile( - NbtCompound(), - gameProfile - ) + this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile)) } val zeroUUID = UUID.fromString("d3cb85e2-3075-48a1-b213-a9bfb62360c1") @@ -76,12 +69,7 @@ fun ItemStack.setSkullOwner(uuid: UUID, url: String) { mapOf(MinecraftProfileTexture.Type.SKIN to MinecraftProfileTextureKt(url)) ) ) - val nbt: NbtCompound = this.orCreateNbt - nbt[SkullBlockEntity.SKULL_OWNER_KEY] = NbtHelper.writeGameProfile( - NbtCompound(), - gameProfile - ) - + this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile)) } diff --git a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt index ecaf3f9..d5fb464 100644 --- a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt +++ b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt @@ -23,7 +23,6 @@ import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormats import net.minecraft.client.texture.Sprite import net.minecraft.client.util.math.MatrixStack -import net.minecraft.client.util.math.MatrixStack.Entry import net.minecraft.text.Text import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos @@ -166,7 +165,7 @@ class RenderInWorldContext private constructor( companion object { private fun doLine( - matrix: Entry, + matrix: MatrixStack.Entry, buf: BufferBuilder, i: Number, j: Number, @@ -179,9 +178,9 @@ class RenderInWorldContext private constructor( .sub(i.toFloat(), j.toFloat(), k.toFloat()) .normalize() buf.vertex(matrix.positionMatrix, i.toFloat(), j.toFloat(), k.toFloat()) - .normal(matrix.normalMatrix, normal.x, normal.y, normal.z).next() + .normal(matrix, normal.x, normal.y, normal.z).next() buf.vertex(matrix.positionMatrix, x.toFloat(), y.toFloat(), z.toFloat()) - .normal(matrix.normalMatrix, normal.x, normal.y, normal.z).next() + .normal(matrix, normal.x, normal.y, normal.z).next() } |