From f98a1f5d53792c026c3688fa89dea3e69910cb3a Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 8 Jun 2023 00:11:46 +0200 Subject: Update to 1.20 - Remove some devenv mods that are not updated yet - Replace lib39 with fletchingtable for automixins - Use non kotlin entrypoints - Make use of DrawContext in a bunch of places --- src/main/kotlin/moe/nea/firmament/Firmament.kt | 25 +++++++++++----------- .../moe/nea/firmament/events/SlotRenderEvents.kt | 8 +++---- .../firmament/features/inventory/SlotLocking.kt | 5 ++--- src/main/kotlin/moe/nea/firmament/gui/WBar.kt | 15 +++++++------ .../nea/firmament/gui/profileviewer/PetsPage.kt | 8 +++---- .../moe/nea/firmament/hud/RepoDownloadProgress.kt | 11 +++++----- .../moe/nea/firmament/rei/NEUItemEntryRenderer.kt | 12 +++++------ 7 files changed, 42 insertions(+), 42 deletions(-) (limited to 'src/main/kotlin/moe/nea') diff --git a/src/main/kotlin/moe/nea/firmament/Firmament.kt b/src/main/kotlin/moe/nea/firmament/Firmament.kt index 6132d3b..f130742 100644 --- a/src/main/kotlin/moe/nea/firmament/Firmament.kt +++ b/src/main/kotlin/moe/nea/firmament/Firmament.kt @@ -19,18 +19,15 @@ package moe.nea.firmament import com.mojang.brigadier.CommandDispatcher -import io.ktor.client.HttpClient -import io.ktor.client.plugins.UserAgent -import io.ktor.client.plugins.cache.HttpCache -import io.ktor.client.plugins.compression.ContentEncoding -import io.ktor.client.plugins.contentnegotiation.ContentNegotiation -import io.ktor.client.plugins.logging.LogLevel -import io.ktor.client.plugins.logging.Logging -import io.ktor.serialization.kotlinx.json.json +import io.ktor.client.* +import io.ktor.client.plugins.* +import io.ktor.client.plugins.cache.* +import io.ktor.client.plugins.compression.* +import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.logging.* +import io.ktor.serialization.kotlinx.json.* import java.nio.file.Files import java.nio.file.Path -import net.fabricmc.api.ClientModInitializer -import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents @@ -58,7 +55,7 @@ import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.SBData import moe.nea.firmament.util.data.IDataHolder -object Firmament : ModInitializer, ClientModInitializer { +object Firmament { const val MOD_ID = "firmament" val DEBUG = System.getProperty("firmament.debug") == "true" @@ -110,10 +107,12 @@ object Firmament : ModInitializer, ClientModInitializer { registerFirmamentCommand(dispatcher) } - override fun onInitialize() { + @JvmStatic + fun onInitialize() { } - override fun onInitializeClient() { + @JvmStatic + fun onClientInitialize() { dbusConnection.requestBusName("moe.nea.firmament") dbusConnection.exportObject(FirmamentDbusObject) IDataHolder.registerEvents() diff --git a/src/main/kotlin/moe/nea/firmament/events/SlotRenderEvents.kt b/src/main/kotlin/moe/nea/firmament/events/SlotRenderEvents.kt index 695d9c2..c4b0a3d 100644 --- a/src/main/kotlin/moe/nea/firmament/events/SlotRenderEvents.kt +++ b/src/main/kotlin/moe/nea/firmament/events/SlotRenderEvents.kt @@ -18,18 +18,18 @@ package moe.nea.firmament.events -import net.minecraft.client.util.math.MatrixStack +import net.minecraft.client.gui.DrawContext import net.minecraft.screen.slot.Slot interface SlotRenderEvents { - val matrices: MatrixStack + val context: DrawContext val slot: Slot val mouseX: Int val mouseY: Int val delta: Float data class Before( - override val matrices: MatrixStack, override val slot: Slot, + override val context: DrawContext, override val slot: Slot, override val mouseX: Int, override val mouseY: Int, override val delta: Float @@ -39,7 +39,7 @@ interface SlotRenderEvents { } data class After( - override val matrices: MatrixStack, override val slot: Slot, + override val context: DrawContext, override val slot: Slot, override val mouseX: Int, override val mouseY: Int, override val delta: Float diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt index 27761ce..eab0da0 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt @@ -20,7 +20,7 @@ package moe.nea.firmament.features.inventory import kotlinx.serialization.Serializable import kotlinx.serialization.serializer -import net.minecraft.client.gui.DrawableHelper +import net.minecraft.client.gui.DrawContext import net.minecraft.entity.player.PlayerInventory import moe.nea.firmament.events.HandledScreenKeyPressedEvent import moe.nea.firmament.events.IsSlotProtectedEvent @@ -72,8 +72,7 @@ object SlotLocking : FirmamentFeature { } SlotRenderEvents.Before.subscribe { if (it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) { - DrawableHelper.fill( - it.matrices, + it.context.fill( it.slot.x, it.slot.y, it.slot.x + 16, diff --git a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt b/src/main/kotlin/moe/nea/firmament/gui/WBar.kt index 04c5e3d..ed812ec 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/WBar.kt @@ -5,6 +5,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing import io.github.cottonmc.cotton.gui.widget.WWidget import io.github.cottonmc.cotton.gui.widget.data.Texture import me.shedaniel.math.Color +import net.minecraft.client.gui.DrawContext import net.minecraft.client.util.math.MatrixStack import moe.nea.firmament.Firmament @@ -27,7 +28,7 @@ open class WBar( } private fun drawSection( - matrices: MatrixStack, + context: DrawContext, texture: Texture, x: Int, y: Int, @@ -36,18 +37,18 @@ open class WBar( sectionEnd: Double ) { if (sectionEnd < progress && width == 4) { - ScreenDrawing.texturedRect(matrices, x, y, 4, 8, texture, fillColor.color) + ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, fillColor.color) return } if (sectionStart > progress && width == 4) { - ScreenDrawing.texturedRect(matrices, x, y, 4, 8, texture, emptyColor.color) + ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, emptyColor.color) return } val increasePerPixel = (sectionEnd - sectionStart / 4) var valueAtPixel = sectionStart for (i in (0 until width)) { ScreenDrawing.texturedRect( - matrices, x + i, y, 1, 8, + context, x + i, y, 1, 8, texture.image, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2, if (valueAtPixel < progress) fillColor.color else emptyColor.color ) @@ -55,11 +56,11 @@ open class WBar( } } - override fun paint(matrices: MatrixStack, x: Int, y: Int, mouseX: Int, mouseY: Int) { + override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) { var i = 0 while (i < width - 4) { drawSection( - matrices, + context, if (i == 0) left else middle, x + i, y, (width - (i + 4)).coerceAtMost(4), @@ -67,7 +68,7 @@ open class WBar( ) i += 4 } - drawSection(matrices, right, x + width - 4, y, 4, (width - 4) * total / width, total) + drawSection(context, right, x + width - 4, y, 4, (width - 4) * total / width, total) RenderSystem.setShaderColor(1F, 1F, 1F, 1F) } } diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt index 4c669df..62889bd 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt @@ -9,8 +9,8 @@ import io.github.cottonmc.cotton.gui.widget.WWidget import io.github.cottonmc.cotton.gui.widget.data.Insets import io.github.cottonmc.cotton.gui.widget.icon.Icon import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon +import net.minecraft.client.gui.DrawContext import net.minecraft.client.item.TooltipContext -import net.minecraft.client.util.math.MatrixStack import net.minecraft.item.Items import net.minecraft.text.Text import moe.nea.firmament.gui.WTightScrollPanel @@ -27,9 +27,9 @@ object PetsPage : ProfilePage { for ((i, pet) in profileViewer.member.pets.withIndex()) { val stack = SBItemStack(pet.itemId, PetData(pet.tier, pet.type.name, pet.exp)).asItemStack() it.add(object : WItem(stack) { - override fun paint(matrices: MatrixStack?, x: Int, y: Int, mouseX: Int, mouseY: Int) { - BackgroundPainter.SLOT.paintBackground(matrices, x, y, this) - super.paint(matrices, x, y, mouseX, mouseY) + override fun paint(context: DrawContext?, x: Int, y: Int, mouseX: Int, mouseY: Int) { + BackgroundPainter.SLOT.paintBackground(context, x, y, this) + super.paint(context, x, y, mouseX, mouseY) } override fun addTooltip(tooltip: TooltipBuilder) { diff --git a/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt b/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt index 69e0384..827835a 100644 --- a/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt +++ b/src/main/kotlin/moe/nea/firmament/hud/RepoDownloadProgress.kt @@ -25,6 +25,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Insets import net.minecraft.client.util.math.MatrixStack import kotlin.math.roundToInt import kotlin.math.sin +import net.minecraft.client.gui.DrawContext val Insets.vertical get() = bottom + top @@ -49,8 +50,8 @@ class ProgressBar( } - override fun paint(matrices: MatrixStack, x: Int, y: Int, mouseX: Int, mouseY: Int) { - ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF808080.toInt()) + override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) { + ScreenDrawing.coloredRect(context, x, y, width, height, 0xFF808080.toInt()) val (l, prog) = synchronized(this) { label to (progress to total) } @@ -58,7 +59,7 @@ class ProgressBar( if (t == null) { ScreenDrawing.coloredRect( - matrices, + context, (x + (1 + sin(System.currentTimeMillis().toDouble() / 1000)) * width * 3 / 4 / 2).roundToInt(), y, width / 4, @@ -66,10 +67,10 @@ class ProgressBar( 0xFF00FF00.toInt() ) } else { - ScreenDrawing.coloredRect(matrices, x, y, width * p / t, height, 0xFF00FF00.toInt()) + ScreenDrawing.coloredRect(context, x, y, width * p / t, height, 0xFF00FF00.toInt()) } ScreenDrawing.drawString( - matrices, + context, if (t != null) "$l ($p/$t)" else l, HorizontalAlignment.CENTER, x + insets.left, diff --git a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt index 32186be..deaaeb9 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt @@ -23,22 +23,22 @@ import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer import me.shedaniel.rei.api.client.gui.widgets.Tooltip import me.shedaniel.rei.api.client.gui.widgets.TooltipContext import me.shedaniel.rei.api.common.entry.EntryStack -import net.minecraft.client.util.math.MatrixStack +import net.minecraft.client.gui.DrawContext import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry object NEUItemEntryRenderer : EntryRenderer { override fun render( entry: EntryStack, - matrices: MatrixStack, + context: DrawContext, bounds: Rectangle, mouseX: Int, mouseY: Int, delta: Float ) { - matrices.push() - matrices.translate(0F, 0F, 100F) - entry.asItemEntry().render(matrices, bounds, mouseX, mouseY, delta) - matrices.pop() + context.matrices.push() + context.matrices.translate(0F, 0F, 100F) + entry.asItemEntry().render(context, bounds, mouseX, mouseY, delta) + context.matrices.pop() } override fun getTooltip(entry: EntryStack, tooltipContext: TooltipContext): Tooltip? { -- cgit