From 8a4bfe24b364612e3e783ed9569082b130aa2bfc Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 6 Mar 2025 21:43:11 +0100 Subject: refactor: Use custom ray trace provider --- src/main/kotlin/repo/MiningRepoData.kt | 22 +++++++++++++++++++- .../kotlin/util/mc/FirmamentDataComponentTypes.kt | 24 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/kotlin/repo/MiningRepoData.kt b/src/main/kotlin/repo/MiningRepoData.kt index 46eaeb0..7c4a2ef 100644 --- a/src/main/kotlin/repo/MiningRepoData.kt +++ b/src/main/kotlin/repo/MiningRepoData.kt @@ -11,11 +11,14 @@ import net.minecraft.block.Block import net.minecraft.item.BlockItem import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound +import net.minecraft.text.Text import moe.nea.firmament.repo.ReforgeStore.kJson import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.SkyblockId +import moe.nea.firmament.util.mc.FirmamentDataComponentTypes +import moe.nea.firmament.util.mc.displayNameAccordingToNbt class MiningRepoData : IReloadable { var customMiningAreas: Map = mapOf() @@ -41,7 +44,23 @@ class MiningRepoData : IReloadable { val name: String? = null, val baseDrop: SkyblockId? = null, val blocks189: List = emptyList() - ) + ) { + @Transient + val dropItem = baseDrop?.let(::SBItemStack) + private val labeledStack by lazy { + dropItem?.asCopiedItemStack()?.also(::markItemStack) + } + + private fun markItemStack(itemStack: ItemStack) { + itemStack.set(FirmamentDataComponentTypes.CUSTOM_MINING_BLOCK_DATA, this) + if (name != null) + itemStack.displayNameAccordingToNbt = Text.literal(name) + } + + fun getDisplayItem(block: Block): ItemStack { + return labeledStack ?: ItemStack(block).also(::markItemStack) + } + } @Serializable data class Block189( @@ -54,6 +73,7 @@ class MiningRepoData : IReloadable { val isCurrentlyActive: Boolean get() = isActiveIn(SBData.skyblockLocation ?: SkyBlockIsland.NIL) + fun isActiveIn(location: SkyBlockIsland) = onlyIn == null || location in onlyIn private fun convertToModernBlock(): Block? { diff --git a/src/main/kotlin/util/mc/FirmamentDataComponentTypes.kt b/src/main/kotlin/util/mc/FirmamentDataComponentTypes.kt index 012f52e..0866665 100644 --- a/src/main/kotlin/util/mc/FirmamentDataComponentTypes.kt +++ b/src/main/kotlin/util/mc/FirmamentDataComponentTypes.kt @@ -1,12 +1,15 @@ package moe.nea.firmament.util.mc import com.mojang.serialization.Codec +import io.netty.buffer.ByteBuf import net.minecraft.component.ComponentType +import net.minecraft.network.codec.PacketCodec import net.minecraft.registry.Registries import net.minecraft.registry.Registry import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ClientInitEvent +import moe.nea.firmament.repo.MiningRepoData object FirmamentDataComponentTypes { @@ -26,11 +29,32 @@ object FirmamentDataComponentTypes { ) } + fun errorCodec(message: String): PacketCodec = + object : PacketCodec { + override fun decode(buf: ByteBuf?): T? { + error(message) + } + + override fun encode(buf: ByteBuf?, value: T?) { + error(message) + } + } + + fun > B.neverEncode(message: String = "This element should never be encoded or decoded"): B { + packetCodec(errorCodec(message)) + codec(null) + return this + } + val IS_BROKEN = register( "is_broken" ) { it.codec(Codec.BOOL.fieldOf("is_broken").codec()) } + val CUSTOM_MINING_BLOCK_DATA = register("custom_mining_block") { + it.neverEncode() + } + } -- cgit