Bump to 1.20.5

This commit is contained in:
Linnea Gräf
2024-04-26 18:04:45 +02:00
parent 041da7c7d1
commit 7e01515694
44 changed files with 351 additions and 358 deletions

View File

@@ -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)
}

View File

@@ -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()
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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))
}

View File

@@ -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()
}