diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
| commit | c93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch) | |
| tree | 5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/main/kotlin/util | |
| parent | af9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff) | |
| download | Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2 Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip | |
refactor: port to mojmaps
Diffstat (limited to 'src/main/kotlin/util')
65 files changed, 921 insertions, 921 deletions
diff --git a/src/main/kotlin/util/CommonSoundEffects.kt b/src/main/kotlin/util/CommonSoundEffects.kt index a97a2cb..a4d7129 100644 --- a/src/main/kotlin/util/CommonSoundEffects.kt +++ b/src/main/kotlin/util/CommonSoundEffects.kt @@ -2,18 +2,18 @@ package moe.nea.firmament.util -import net.minecraft.client.sound.PositionedSoundInstance -import net.minecraft.sound.SoundEvent -import net.minecraft.util.Identifier +import net.minecraft.client.resources.sounds.SimpleSoundInstance +import net.minecraft.sounds.SoundEvent +import net.minecraft.resources.ResourceLocation // TODO: Replace these with custom sound events that just re use the vanilla ogg s object CommonSoundEffects { - fun playSound(identifier: Identifier) { - MC.soundManager.play(PositionedSoundInstance.master(SoundEvent.of(identifier), 1F)) + fun playSound(identifier: ResourceLocation) { + MC.soundManager.play(SimpleSoundInstance.forUI(SoundEvent.createVariableRangeEvent(identifier), 1F)) } fun playFailure() { - playSound(Identifier.of("minecraft", "block.anvil.place")) + playSound(ResourceLocation.fromNamespaceAndPath("minecraft", "block.anvil.place")) } fun playSuccess() { @@ -21,6 +21,6 @@ object CommonSoundEffects { } fun playDing() { - playSound(Identifier.of("minecraft", "entity.arrow.hit_player")) + playSound(ResourceLocation.fromNamespaceAndPath("minecraft", "entity.arrow.hit_player")) } } diff --git a/src/main/kotlin/util/DurabilityBarEvent.kt b/src/main/kotlin/util/DurabilityBarEvent.kt index 993462c..c2f863f 100644 --- a/src/main/kotlin/util/DurabilityBarEvent.kt +++ b/src/main/kotlin/util/DurabilityBarEvent.kt @@ -2,7 +2,7 @@ package moe.nea.firmament.util import me.shedaniel.math.Color -import net.minecraft.item.ItemStack +import net.minecraft.world.item.ItemStack import moe.nea.firmament.events.FirmamentEvent import moe.nea.firmament.events.FirmamentEventBus diff --git a/src/main/kotlin/util/FirmFormatters.kt b/src/main/kotlin/util/FirmFormatters.kt index 03dafc5..c4cffc3 100644 --- a/src/main/kotlin/util/FirmFormatters.kt +++ b/src/main/kotlin/util/FirmFormatters.kt @@ -12,8 +12,8 @@ import kotlin.math.absoluteValue import kotlin.math.roundToInt import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.core.BlockPos object FirmFormatters { @@ -103,7 +103,7 @@ object FirmFormatters { return sb.toString() } - fun debugPath(path: Path): Text { + fun debugPath(path: Path): Component { if (!path.exists()) { return tr("firmament.path.missing", "$path (missing)").red() } @@ -127,13 +127,13 @@ object FirmFormatters { fun formatBool( boolean: Boolean, trueIsGood: Boolean = true, - ): Text { - val text = Text.literal(boolean.toString()) + ): Component { + val text = Component.literal(boolean.toString()) return if (boolean == trueIsGood) text.lime() else text.red() } - fun formatPosition(position: BlockPos): Text { - return Text.literal("x: ${position.x}, y: ${position.y}, z: ${position.z}") + fun formatPosition(position: BlockPos): Component { + return Component.literal("x: ${position.x}, y: ${position.y}, z: ${position.z}") } fun formatPercent(value: Double, decimals: Int = 1): String { diff --git a/src/main/kotlin/util/FragmentGuiScreen.kt b/src/main/kotlin/util/FragmentGuiScreen.kt index 74558a0..8797a31 100644 --- a/src/main/kotlin/util/FragmentGuiScreen.kt +++ b/src/main/kotlin/util/FragmentGuiScreen.kt @@ -6,23 +6,23 @@ import io.github.notenoughupdates.moulconfig.gui.GuiContext import me.shedaniel.math.Dimension import me.shedaniel.math.Point import me.shedaniel.math.Rectangle -import net.minecraft.client.gui.Click -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.screen.Screen -import net.minecraft.client.input.CharInput -import net.minecraft.client.input.KeyInput -import net.minecraft.text.Text +import net.minecraft.client.input.MouseButtonEvent +import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.gui.screens.Screen +import net.minecraft.client.input.CharacterEvent +import net.minecraft.client.input.KeyEvent +import net.minecraft.network.chat.Component abstract class FragmentGuiScreen( val dismissOnOutOfBounds: Boolean = true -) : Screen(Text.literal("")) { +) : Screen(Component.literal("")) { var popup: MoulConfigFragment? = null fun createPopup(context: GuiContext, position: Point) { popup = MoulConfigFragment(context, position) { popup = null } } - fun renderPopup(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { + fun renderPopup(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) { popup?.render(context, mouseX, mouseY, delta) } @@ -32,13 +32,13 @@ abstract class FragmentGuiScreen( return true } - override fun keyPressed(input: KeyInput): Boolean { + override fun keyPressed(input: KeyEvent): Boolean { return ifPopup { it.keyPressed(input) } } - override fun keyReleased(input: KeyInput): Boolean { + override fun keyReleased(input: KeyEvent): Boolean { return ifPopup { it.keyReleased(input) } @@ -48,19 +48,19 @@ abstract class FragmentGuiScreen( ifPopup { it.mouseMoved(mouseX, mouseY) } } - override fun mouseReleased(click: Click): Boolean { + override fun mouseReleased(click: MouseButtonEvent): Boolean { return ifPopup { it.mouseReleased(click) } } - override fun mouseDragged(click: Click, offsetX: Double, offsetY: Double): Boolean { + override fun mouseDragged(click: MouseButtonEvent, offsetX: Double, offsetY: Double): Boolean { return ifPopup { it.mouseDragged(click, offsetX, offsetY) } } - override fun mouseClicked(click: Click, doubled: Boolean): Boolean { + override fun mouseClicked(click: MouseButtonEvent, doubled: Boolean): Boolean { return ifPopup { if (!Rectangle( it.position, @@ -75,7 +75,7 @@ abstract class FragmentGuiScreen( }|| super.mouseClicked(click, doubled) } - override fun charTyped(input: CharInput): Boolean { + override fun charTyped(input: CharacterEvent): Boolean { return ifPopup { it.charTyped(input) } } diff --git a/src/main/kotlin/util/HoveredItemStack.kt b/src/main/kotlin/util/HoveredItemStack.kt index 1b54562..c8d33fd 100644 --- a/src/main/kotlin/util/HoveredItemStack.kt +++ b/src/main/kotlin/util/HoveredItemStack.kt @@ -1,13 +1,13 @@ package moe.nea.firmament.util import com.google.auto.service.AutoService -import net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.item.ItemStack +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen +import net.minecraft.world.item.ItemStack import moe.nea.firmament.mixins.accessor.AccessorHandledScreen import moe.nea.firmament.util.compatloader.CompatLoader interface HoveredItemStackProvider : Comparable<HoveredItemStackProvider> { - fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack? + fun provideHoveredItemStack(screen: AbstractContainerScreen<*>): ItemStack? override fun compareTo(other: HoveredItemStackProvider): Int { return compareValues(this.prio, other.prio) } @@ -22,9 +22,9 @@ interface HoveredItemStackProvider : Comparable<HoveredItemStackProvider> { @AutoService(HoveredItemStackProvider::class) class VanillaScreenProvider : HoveredItemStackProvider { - override fun provideHoveredItemStack(screen: HandledScreen<*>): ItemStack? { + override fun provideHoveredItemStack(screen: AbstractContainerScreen<*>): ItemStack? { screen as AccessorHandledScreen - val vanillaSlot = screen.focusedSlot_Firmament?.stack + val vanillaSlot = screen.focusedSlot_Firmament?.item return vanillaSlot } @@ -32,7 +32,7 @@ class VanillaScreenProvider : HoveredItemStackProvider { get() = -1 } -val HandledScreen<*>.focusedItemStack: ItemStack? +val AbstractContainerScreen<*>.focusedItemStack: ItemStack? get() = HoveredItemStackProvider.sorted .firstNotNullOfOrNull { it.provideHoveredItemStack(this)?.takeIf { !it.isEmpty } } diff --git a/src/main/kotlin/util/IdentifierSerializer.kt b/src/main/kotlin/util/IdentifierSerializer.kt index 65c5b1c..2255255 100644 --- a/src/main/kotlin/util/IdentifierSerializer.kt +++ b/src/main/kotlin/util/IdentifierSerializer.kt @@ -8,18 +8,18 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import net.minecraft.util.Identifier +import net.minecraft.resources.ResourceLocation -object IdentifierSerializer : KSerializer<Identifier> { +object IdentifierSerializer : KSerializer<ResourceLocation> { val delegateSerializer = String.serializer() override val descriptor: SerialDescriptor get() = PrimitiveSerialDescriptor("Identifier", PrimitiveKind.STRING) - override fun deserialize(decoder: Decoder): Identifier { - return Identifier.of(decoder.decodeSerializableValue(delegateSerializer)) + override fun deserialize(decoder: Decoder): ResourceLocation { + return ResourceLocation.parse(decoder.decodeSerializableValue(delegateSerializer)) } - override fun serialize(encoder: Encoder, value: Identifier) { + override fun serialize(encoder: Encoder, value: ResourceLocation) { encoder.encodeSerializableValue(delegateSerializer, value.toString()) } } diff --git a/src/main/kotlin/util/LegacyFormattingCode.kt b/src/main/kotlin/util/LegacyFormattingCode.kt index 1a5d1dd..20574d8 100644 --- a/src/main/kotlin/util/LegacyFormattingCode.kt +++ b/src/main/kotlin/util/LegacyFormattingCode.kt @@ -1,6 +1,6 @@ package moe.nea.firmament.util -import net.minecraft.util.Formatting +import net.minecraft.ChatFormatting enum class LegacyFormattingCode(val label: String, val char: Char, val index: Int) { BLACK("BLACK", '0', 0), @@ -30,7 +30,7 @@ enum class LegacyFormattingCode(val label: String, val char: Char, val index: In val byCode = entries.associateBy { it.char } } - val modern = Formatting.byCode(char)!! + val modern = ChatFormatting.getByCode(char)!! val formattingCode = "§$char" diff --git a/src/main/kotlin/util/LegacyTagParser.kt b/src/main/kotlin/util/LegacyTagParser.kt index 5a26335..0de4caa 100644 --- a/src/main/kotlin/util/LegacyTagParser.kt +++ b/src/main/kotlin/util/LegacyTagParser.kt @@ -3,17 +3,17 @@ package moe.nea.firmament.util import java.util.Stack -import net.minecraft.nbt.AbstractNbtNumber -import net.minecraft.nbt.NbtByte -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtDouble -import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtFloat -import net.minecraft.nbt.NbtInt -import net.minecraft.nbt.NbtList -import net.minecraft.nbt.NbtLong -import net.minecraft.nbt.NbtShort -import net.minecraft.nbt.NbtString +import net.minecraft.nbt.NumericTag +import net.minecraft.nbt.ByteTag +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.DoubleTag +import net.minecraft.nbt.Tag +import net.minecraft.nbt.FloatTag +import net.minecraft.nbt.IntTag +import net.minecraft.nbt.ListTag +import net.minecraft.nbt.LongTag +import net.minecraft.nbt.ShortTag +import net.minecraft.nbt.StringTag class LegacyTagParser private constructor(string: String) { data class TagParsingException(val baseString: String, val offset: Int, val mes0: String) : @@ -93,7 +93,7 @@ class LegacyTagParser private constructor(string: String) { companion object { val digitRange = "0123456789-" - fun parse(string: String): NbtCompound { + fun parse(string: String): CompoundTag { return LegacyTagParser(string).baseTag } } @@ -102,11 +102,11 @@ class LegacyTagParser private constructor(string: String) { racer.consumeWhile { Character.isWhitespace(it.last()) } // Only check last since other chars are always checked before. } - fun parseTag(): NbtCompound { + fun parseTag(): CompoundTag { skipWhitespace() racer.expect("{", "Expected '{’ at start of tag") skipWhitespace() - val tag = NbtCompound() + val tag = CompoundTag() while (!racer.tryConsume("}")) { skipWhitespace() val lhs = parseIdentifier() @@ -121,7 +121,7 @@ class LegacyTagParser private constructor(string: String) { return tag } - private fun parseAny(): NbtElement { + private fun parseAny(): Tag { skipWhitespace() val nextChar = racer.peekReq(1) ?: racer.error("Expected new object, found EOF") return when { @@ -133,11 +133,11 @@ class LegacyTagParser private constructor(string: String) { } } - fun parseList(): NbtList { + fun parseList(): ListTag { skipWhitespace() racer.expect("[", "Expected '[' at start of tag") skipWhitespace() - val list = NbtList() + val list = ListTag() while (!racer.tryConsume("]")) { skipWhitespace() racer.pushState() @@ -183,8 +183,8 @@ class LegacyTagParser private constructor(string: String) { return sb.toString() } - fun parseStringTag(): NbtString { - return NbtString.of(parseQuotedString()) + fun parseStringTag(): StringTag { + return StringTag.valueOf(parseQuotedString()) } object Patterns { @@ -198,7 +198,7 @@ class LegacyTagParser private constructor(string: String) { val ROUGH_PATTERN = "[-+]?[0-9]*\\.?[0-9]*[dDbBfFlLsS]?".toRegex() } - fun parseNumericTag(): AbstractNbtNumber { + fun parseNumericTag(): NumericTag { skipWhitespace() val textForm = racer.consumeWhile { Patterns.ROUGH_PATTERN.matchEntire(it) != null } if (textForm.isEmpty()) { @@ -206,27 +206,27 @@ class LegacyTagParser private constructor(string: String) { } val floatMatch = Patterns.FLOAT.matchEntire(textForm) if (floatMatch != null) { - return NbtFloat.of(floatMatch.groups[1]!!.value.toFloat()) + return FloatTag.valueOf(floatMatch.groups[1]!!.value.toFloat()) } val byteMatch = Patterns.BYTE.matchEntire(textForm) if (byteMatch != null) { - return NbtByte.of(byteMatch.groups[1]!!.value.toByte()) + return ByteTag.valueOf(byteMatch.groups[1]!!.value.toByte()) } val longMatch = Patterns.LONG.matchEntire(textForm) if (longMatch != null) { - return NbtLong.of(longMatch.groups[1]!!.value.toLong()) + return LongTag.valueOf(longMatch.groups[1]!!.value.toLong()) } val shortMatch = Patterns.SHORT.matchEntire(textForm) if (shortMatch != null) { - return NbtShort.of(shortMatch.groups[1]!!.value.toShort()) + return ShortTag.valueOf(shortMatch.groups[1]!!.value.toShort()) } val integerMatch = Patterns.INTEGER.matchEntire(textForm) if (integerMatch != null) { - return NbtInt.of(integerMatch.groups[1]!!.value.toInt()) + return IntTag.valueOf(integerMatch.groups[1]!!.value.toInt()) } val doubleMatch = Patterns.DOUBLE.matchEntire(textForm) ?: Patterns.DOUBLE_UNTYPED.matchEntire(textForm) if (doubleMatch != null) { - return NbtDouble.of(doubleMatch.groups[1]!!.value.toDouble()) + return DoubleTag.valueOf(doubleMatch.groups[1]!!.value.toDouble()) } throw IllegalStateException("Could not properly parse numeric tag '$textForm', despite passing rough verification. This is a bug in the LegacyTagParser") } diff --git a/src/main/kotlin/util/LegacyTagWriter.kt b/src/main/kotlin/util/LegacyTagWriter.kt index 9889b2c..eb755c4 100644 --- a/src/main/kotlin/util/LegacyTagWriter.kt +++ b/src/main/kotlin/util/LegacyTagWriter.kt @@ -1,27 +1,27 @@ package moe.nea.firmament.util import kotlinx.serialization.json.JsonPrimitive -import net.minecraft.nbt.AbstractNbtList -import net.minecraft.nbt.NbtByte -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtDouble -import net.minecraft.nbt.NbtElement -import net.minecraft.nbt.NbtEnd -import net.minecraft.nbt.NbtFloat -import net.minecraft.nbt.NbtInt -import net.minecraft.nbt.NbtLong -import net.minecraft.nbt.NbtShort -import net.minecraft.nbt.NbtString +import net.minecraft.nbt.CollectionTag +import net.minecraft.nbt.ByteTag +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.DoubleTag +import net.minecraft.nbt.Tag +import net.minecraft.nbt.EndTag +import net.minecraft.nbt.FloatTag +import net.minecraft.nbt.IntT |
