From facf644adf852e144bdc7e1a7b8cf4da591ff3ac Mon Sep 17 00:00:00 2001 From: Lucy Poulton Date: Tue, 14 May 2024 18:51:04 +0100 Subject: [PATCH] update: Minecraft 1.20.6 (#24) --- .github/workflows/release.yml | 2 +- api/build.gradle.kts | 7 +-- .../com/noxcrew/sheeplib/mixin/GuiMixin.java | 27 +++++------ .../mixin/NoxesiumCompatGuiMixin.java | 41 ----------------- .../sheeplib/mixin/PlayerTabOverlayMixin.java | 35 --------------- .../sheeplib/mixin/SubtitleOverlayMixin.java | 32 ------------- .../com/noxcrew/sheeplib/DialogContainer.kt | 35 +++++---------- .../noxcrew/sheeplib/SheepLibMixinPlugin.kt | 45 ------------------- api/src/main/resources/sheeplib.mixins.json | 8 +--- build.gradle.kts | 2 +- .../main/kotlin/sheeplib.fabric.gradle.kts | 2 +- gradle/libs.versions.toml | 15 +++---- gradle/wrapper/gradle-wrapper.properties | 2 +- 13 files changed, 37 insertions(+), 216 deletions(-) delete mode 100644 api/src/main/java/com/noxcrew/sheeplib/mixin/NoxesiumCompatGuiMixin.java delete mode 100644 api/src/main/java/com/noxcrew/sheeplib/mixin/PlayerTabOverlayMixin.java delete mode 100644 api/src/main/java/com/noxcrew/sheeplib/mixin/SubtitleOverlayMixin.java delete mode 100644 api/src/main/kotlin/com/noxcrew/sheeplib/SheepLibMixinPlugin.kt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8bb5c16..d66b0f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@v3 with: - java-version: 17 + java-version: 21 distribution: temurin - name: Gradle Wrapper Validation diff --git a/api/build.gradle.kts b/api/build.gradle.kts index df331ac..946bfde 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -47,12 +47,7 @@ tasks { } } -repositories { - maven("https://maven.noxcrew.com/public") -} - dependencies { - compileOnly("org.jetbrains:annotations:24.0.1") - modCompileOnly(libs.noxesium) { isTransitive = false } + compileOnlyApi("org.jetbrains:annotations:24.0.1") testImplementation(kotlin("test")) } diff --git a/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java b/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java index 70aeeb6..2fcca68 100644 --- a/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java +++ b/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java @@ -1,30 +1,27 @@ package com.noxcrew.sheeplib.mixin; -import com.mojang.blaze3d.platform.Window; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.noxcrew.sheeplib.DialogContainer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.world.scores.Scoreboard; +import net.minecraft.client.gui.LayeredDraw; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; /** - * Renders the [DialogContainerScreen]. + * Adds the {@link DialogContainer} as a render layer. */ @Mixin(Gui.class) public class GuiMixin { - @SuppressWarnings("InvalidInjectorMethodSignature") - @Inject( - method = "render", + @ModifyExpressionValue( + method="", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/gui/components/ChatComponent;render(Lnet/minecraft/client/gui/GuiGraphics;III)V" - ), - locals = LocalCapture.CAPTURE_FAILHARD) - public void render(GuiGraphics guiGraphics, float f, CallbackInfo ci, Window window, Scoreboard scoreboard, int o, int q) { - DialogContainer.INSTANCE.render(guiGraphics, o, q, 0); + target = "Lnet/minecraft/client/gui/LayeredDraw;add(Lnet/minecraft/client/gui/LayeredDraw$Layer;)Lnet/minecraft/client/gui/LayeredDraw;", + ordinal = 11 + ) + ) + public LayeredDraw addRenderLayer(LayeredDraw original) { + return original.add(DialogContainer.INSTANCE); } + } diff --git a/api/src/main/java/com/noxcrew/sheeplib/mixin/NoxesiumCompatGuiMixin.java b/api/src/main/java/com/noxcrew/sheeplib/mixin/NoxesiumCompatGuiMixin.java deleted file mode 100644 index 4cc98b1..0000000 --- a/api/src/main/java/com/noxcrew/sheeplib/mixin/NoxesiumCompatGuiMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.noxcrew.sheeplib.mixin; - -import com.noxcrew.noxesium.NoxesiumMod; -import com.noxcrew.sheeplib.DialogContainer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.util.Mth; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Noxesium has a setting to completely override the vanilla GUI rendering code - * to improve performance, which is great, but breaks SheepLib dialog rendering. - * This mixin just renders dialogs before Noxesium works its magic. - */ -@Mixin(value = Gui.class, priority = 800) -public class NoxesiumCompatGuiMixin { - @Shadow - @Final - private Minecraft minecraft; - - @Inject( - method = "render", - at = @At("HEAD") - ) - public void render(GuiGraphics guiGraphics, float f, CallbackInfo ci) { - if (NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches()) return; - - // FIXME: render order is completely off here. not sure if that's my fault or a noxesium thing - final var window = this.minecraft.getWindow(); - - final var mouseX = Mth.floor(minecraft.mouseHandler.xpos() * (double) window.getGuiScaledWidth() / (double) window.getScreenWidth()); - final var mouseY = Mth.floor(minecraft.mouseHandler.ypos() * (double) window.getGuiScaledHeight() / (double) window.getScreenHeight()); - DialogContainer.INSTANCE.render(guiGraphics, mouseX, mouseY, 0); - } -} diff --git a/api/src/main/java/com/noxcrew/sheeplib/mixin/PlayerTabOverlayMixin.java b/api/src/main/java/com/noxcrew/sheeplib/mixin/PlayerTabOverlayMixin.java deleted file mode 100644 index c9ceafa..0000000 --- a/api/src/main/java/com/noxcrew/sheeplib/mixin/PlayerTabOverlayMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.noxcrew.sheeplib.mixin; - -import com.noxcrew.sheeplib.DialogContainer; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.PlayerTabOverlay; -import net.minecraft.world.scores.Objective; -import net.minecraft.world.scores.Scoreboard; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Increases the player tab overlay's Z-axis to render on top of SheepLib dialogs. - */ -@Mixin(PlayerTabOverlay.class) -public class PlayerTabOverlayMixin { - - @Inject( - method = "render", - at = @At("HEAD") - ) - public void pushPose(GuiGraphics guiGraphics, int i, Scoreboard scoreboard, Objective objective, CallbackInfo ci) { - guiGraphics.pose().pushPose(); - guiGraphics.pose().translate(0.0, 0.0, DialogContainer.zIndexUse$sheeplib()); - } - - @Inject( - method = "render", - at = @At("TAIL") - ) - public void popPose(GuiGraphics guiGraphics, int i, Scoreboard scoreboard, Objective objective, CallbackInfo ci) { - guiGraphics.pose().popPose(); - } -} diff --git a/api/src/main/java/com/noxcrew/sheeplib/mixin/SubtitleOverlayMixin.java b/api/src/main/java/com/noxcrew/sheeplib/mixin/SubtitleOverlayMixin.java deleted file mode 100644 index af5a9ab..0000000 --- a/api/src/main/java/com/noxcrew/sheeplib/mixin/SubtitleOverlayMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.noxcrew.sheeplib.mixin; - -import com.noxcrew.sheeplib.DialogContainer; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.SubtitleOverlay; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Increases the subtitle overlay's Z-axis to render on top of SheepLib dialogs. - */ -@Mixin(SubtitleOverlay.class) -public class SubtitleOverlayMixin { - @Inject( - method = "render", - at = @At("HEAD") - ) - public void pushPose(GuiGraphics guiGraphics, CallbackInfo ci) { - guiGraphics.pose().pushPose(); - guiGraphics.pose().translate(0.0, 0.0, DialogContainer.zIndexUse$sheeplib()); - } - - @Inject( - method = "render", - at = @At("TAIL") - ) - public void popPose(GuiGraphics guiGraphics, CallbackInfo ci) { - guiGraphics.pose().popPose(); - } -} diff --git a/api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt b/api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt index f5261ac..6e2ae37 100644 --- a/api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt +++ b/api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt @@ -6,6 +6,7 @@ import kotlinx.atomicfu.update import net.minecraft.ChatFormatting import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.gui.LayeredDraw import net.minecraft.client.gui.components.Renderable import net.minecraft.client.gui.components.events.ContainerEventHandler import net.minecraft.client.gui.components.events.GuiEventListener @@ -19,7 +20,7 @@ import kotlin.reflect.jvm.jvmName /** * The container for all open dialogs. */ -public object DialogContainer : Renderable, ContainerEventHandler, NarratableEntry { +public object DialogContainer : LayeredDraw.Layer, ContainerEventHandler, NarratableEntry { private val minecraft = Minecraft.getInstance() private val logger = LoggerFactory.getLogger("SheepLib") @@ -33,27 +34,21 @@ public object DialogContainer : Renderable, ContainerEventHandler, NarratableEnt /** Whether the container is currently being dragged. */ private var isDragging: Boolean = false - /** The step to offset each dialog by in the Z-axis. */ - private const val Z_STEP_PER_DIALOG = 5f + override fun render(guiGraphics: GuiGraphics, f: Float) { + val cursorIsActive = minecraft?.screen is ChatScreen - /** - * The amount to offset the initial Z co-ordinate by, for all dialogs. - * This is needed to sit on top of the vanilla chat window. - */ - private const val Z_INITIAL_OFFSET = 100f + val childX = if (cursorIsActive) minecraft.mouseHandler.xpos() / minecraft.window.guiScale else -1 + val childY = if (cursorIsActive) minecraft.mouseHandler.ypos() / minecraft.window.guiScale else -1 - /** Renders widgets. */ - override fun render(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) { - val cursorIsActive = minecraft?.screen is ChatScreen + val children = children.value - val childX = if (cursorIsActive) i else -1 - val childY = if (cursorIsActive) j else -1 + // Share the Z space evenly between dialogs.. + val zOffsetPerDialog = LayeredDraw.Z_SEPARATION / children.size guiGraphics.pose().pushPose() - guiGraphics.pose().translate(0f, 0f, Z_INITIAL_OFFSET) - children.value.forEach { - guiGraphics.pose().translate(0f, 0f, Z_STEP_PER_DIALOG) - (it as Renderable).render(guiGraphics, childX, childY, f) + children.forEach { + (it as Renderable).render(guiGraphics, childX.toInt(), childY.toInt(), f) + guiGraphics.pose().translate(0f, 0f, zOffsetPerDialog) } guiGraphics.pose().popPose() } @@ -150,10 +145,4 @@ public object DialogContainer : Renderable, ContainerEventHandler, NarratableEnt /** Unused. */ override fun narrationPriority(): NarratableEntry.NarrationPriority = NarratableEntry.NarrationPriority.NONE - /** - * The total amount of space in the Z axis that the dialogs have used, - * assuming each dialog spans across no more than [Z_STEP_PER_DIALOG]. - */ - @JvmStatic - internal fun zIndexUse() = Z_INITIAL_OFFSET + ((children.value.size + 1) * Z_STEP_PER_DIALOG) } diff --git a/api/src/main/kotlin/com/noxcrew/sheeplib/SheepLibMixinPlugin.kt b/api/src/main/kotlin/com/noxcrew/sheeplib/SheepLibMixinPlugin.kt deleted file mode 100644 index 4454080..0000000 --- a/api/src/main/kotlin/com/noxcrew/sheeplib/SheepLibMixinPlugin.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.noxcrew.sheeplib - -import net.fabricmc.loader.api.FabricLoader -import net.fabricmc.loader.api.Version -import org.objectweb.asm.tree.ClassNode -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin -import org.spongepowered.asm.mixin.extensibility.IMixinInfo -import kotlin.jvm.optionals.getOrNull - -internal class SheepLibMixinPlugin : IMixinConfigPlugin { - - private val isUsingNoxesium by lazy { - FabricLoader.getInstance() - .getModContainer("noxesium") - .getOrNull() - ?.let { it.metadata.version > Version.parse("1.1.0") } - ?: false - } - override fun shouldApplyMixin(targetClassName: String?, mixinClassName: String?): Boolean = when (mixinClassName) { - "com.noxcrew.sheeplib.mixin.NoxesiumCompatGuiMixin" -> isUsingNoxesium - else -> true - } - - override fun onLoad(mixinPackage: String?): Unit = Unit - - override fun getRefMapperConfig(): String? = null - - override fun acceptTargets(myTargets: MutableSet?, otherTargets: MutableSet?): Unit = Unit - - override fun getMixins(): List? = null - - override fun preApply( - targetClassName: String?, - targetClass: ClassNode?, - mixinClassName: String?, - mixinInfo: IMixinInfo? - ): Unit = Unit - - override fun postApply( - targetClassName: String?, - targetClass: ClassNode?, - mixinClassName: String?, - mixinInfo: IMixinInfo? - ): Unit = Unit -} diff --git a/api/src/main/resources/sheeplib.mixins.json b/api/src/main/resources/sheeplib.mixins.json index 79b0714..929c405 100644 --- a/api/src/main/resources/sheeplib.mixins.json +++ b/api/src/main/resources/sheeplib.mixins.json @@ -3,10 +3,6 @@ "client": [ "ChatScreenMixin", "GuiMixin", - "NoxesiumCompatGuiMixin", - "PlayerTabOverlayMixin", - "StringWidgetMixin", - "SubtitleOverlayMixin" - ], - "plugin": "com.noxcrew.sheeplib.SheepLibMixinPlugin" + "StringWidgetMixin" + ] } diff --git a/build.gradle.kts b/build.gradle.kts index 39c60bf..ebfe996 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ import org.gradle.accessors.dm.LibrariesForLibs -val VERSION = "1.3.2" +val VERSION = "1.3.3-SNAPSHOT" allprojects { group = "com.noxcrew.sheeplib" diff --git a/buildSrc/src/main/kotlin/sheeplib.fabric.gradle.kts b/buildSrc/src/main/kotlin/sheeplib.fabric.gradle.kts index db61321..6af1aef 100644 --- a/buildSrc/src/main/kotlin/sheeplib.fabric.gradle.kts +++ b/buildSrc/src/main/kotlin/sheeplib.fabric.gradle.kts @@ -11,7 +11,7 @@ internal val Project.libs get() = project.extensions.getByName("libs") as Librar kotlin { explicitApi() - jvmToolchain(17) + jvmToolchain(21) } tasks { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cdccea0..f61b5fd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,12 @@ [versions] -minecraft = "1.20.4" -fabric-loader = "0.15.0" -fabric-api = "0.91.1+1.20.4" # for the test mod only -fabric-loom = "1.4-SNAPSHOT" +minecraft = "1.20.6" +fabric-loader = "0.15.10" +fabric-api = "0.98.0+1.20.6" # for the test mod only +fabric-loom = "1.6-SNAPSHOT" -kotlin = "1.9.0" -fabric-kotlin = "1.10.0+kotlin.1.9.0" +kotlin = "1.9.23" +fabric-kotlin = "1.10.19+kotlin.1.9.23" coroutines = "1.7.3" -noxesium = "1.2.0" jb-annotations = "24.0.1" @@ -23,8 +22,6 @@ kotlin-gradle = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", kotlin-jvm = { group = "org.jetbrains.kotlin", name = "jvm", version.ref = "kotlin" } kotlin-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version.ref = "coroutines" } -noxesium = { group = "com.noxcrew.noxesium", name = "fabric", version.ref = "noxesium" } - guava = { group = "com.google.guava", name = "guava" } # version from minecraftLibraries jb-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jb-annotations" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e09..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME