From 646c7bac69dba476b3f9171568091eb23a86edaa Mon Sep 17 00:00:00 2001 From: isXander Date: Wed, 29 May 2024 22:42:46 +0100 Subject: [PATCH] 1.21 compat --- build.gradle.kts | 5 ++--- gradle.properties | 2 +- settings.gradle.kts | 9 ++++---- .../v2/api/autogen/SimpleOptionFactory.java | 5 +++-- .../config/v2/impl/autogen/ListGroupImpl.java | 3 ++- .../isxander/yacl3/gui/AbstractWidget.java | 8 +++++++ .../yacl3/gui/ElementListWidgetExt.java | 6 ++++- .../dev/isxander/yacl3/gui/YACLScreen.java | 12 ++-------- .../yacl3/gui/utils/ItemRegistryHelper.java | 5 +++-- .../yacl3/gui/utils/YACLRenderHelper.java | 8 +++---- .../isxander/yacl3/platform/YACLPlatform.java | 22 ++++++++++++++++++- .../yacl3/test/AutogenConfigTest.java | 2 +- .../java/dev/isxander/yacl3/test/GuiTest.java | 3 ++- .../kotlin/dev/isxander/yacl3/test/DslTest.kt | 3 ++- versions/1.20.1-fabric/gradle.properties | 1 + versions/1.20.1-forge/gradle.properties | 1 + versions/1.20.4-fabric/gradle.properties | 1 + versions/1.20.4-neoforge/gradle.properties | 1 + versions/1.20.6-fabric/gradle.properties | 1 + versions/1.20.6-neoforge/gradle.properties | 1 + versions/1.21-fabric/gradle.properties | 8 +++++++ 21 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 versions/1.21-fabric/gradle.properties diff --git a/build.gradle.kts b/build.gradle.kts index 26ef1775..13dceded 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ val isNeoforge = loader == "neoforge" val isForge = loader == "forge" val isForgeLike = isNeoforge || isForge -val mcVersion = stonecutter.current.version +val mcVersion = findProperty("mcVersion").toString() group = "dev.isxander" val versionWithoutMC = "3.4.4" @@ -111,7 +111,6 @@ repositories { forRepository { maven("https://thedarkcolour.github.io/KotlinForForge/") } filter { includeGroup("thedarkcolour") } } - maven("https://maven.neoforged.net/releases/") } @@ -119,7 +118,7 @@ dependencies { fun Dependency?.jij() = this?.let(::include) fun Dependency?.forgeRuntime() = this?.takeIf { isForgeLike }?.let { "forgeRuntimeLibrary"(it) } - minecraft("com.mojang:minecraft:${if (mcVersion.contains("beta")) "1.20.5-pre2" else mcVersion}") + minecraft("com.mojang:minecraft:$mcVersion") mappings(loom.layered { optionalProp("deps.quiltMappings") { diff --git a/gradle.properties b/gradle.properties index c2095c27..79fe14ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ modId=yet_another_config_lib_v3 modName=YetAnotherConfigLib modDescription=YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft. -deps.fabricLoader=0.15.9 +deps.fabricLoader=0.15.11 deps.imageio=3.10.0 deps.quiltParsers=0.2.1 deps.mixinExtras=0.3.5 diff --git a/settings.gradle.kts b/settings.gradle.kts index 6e841442..90271279 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,18 +17,19 @@ plugins { } extensions.configure { - kotlinController(true) - centralScript("build.gradle.kts") + kotlinController = true + centralScript = "build.gradle.kts" shared { fun mc(mcVersion: String, name: String = mcVersion, loaders: Iterable) { for (loader in loaders) { - vers("$name-$loader", mcVersion) + versions("$name-$loader") } } + mc("1.20.6", loaders = listOf("fabric", "neoforge")) mc("1.20.4", loaders = listOf("fabric", "neoforge")) + mc("1.21", loaders = listOf("fabric")) mc("1.20.1", loaders = listOf("fabric", "forge")) - mc("1.20.6", loaders = listOf("fabric", "neoforge")) } create(rootProject) } diff --git a/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java b/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java index f7d807f9..bbb878d5 100644 --- a/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java +++ b/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java @@ -9,6 +9,7 @@ import dev.isxander.yacl3.config.v2.impl.autogen.AutoGenUtils; import dev.isxander.yacl3.config.v2.impl.autogen.EmptyCustomImageFactory; import dev.isxander.yacl3.config.v2.impl.autogen.YACLAutoGenException; +import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.client.Minecraft; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; @@ -90,7 +91,7 @@ protected OptionDescription.Builder description(T value, A annotation, ConfigFie builder.customImage(imageFactory.createImage(value, field, storage).thenApply(Optional::of)); } else if (!imageOverride.value().isEmpty()) { String path = imageOverride.value(); - ResourceLocation imageLocation = new ResourceLocation(field.parent().id().getNamespace(), path); + ResourceLocation imageLocation = YACLPlatform.rl(field.parent().id().getNamespace(), path); String extension = path.substring(path.lastIndexOf('.') + 1); switch (extension) { @@ -105,7 +106,7 @@ protected OptionDescription.Builder description(T value, A annotation, ConfigFie } else { String imagePath = "textures/yacl3/" + field.parent().id().getPath() + "/" + field.access().name() + ".webp"; imagePath = imagePath.toLowerCase().replaceAll("[^a-z0-9/._:-]", "_"); - ResourceLocation imageLocation = new ResourceLocation(field.parent().id().getNamespace(), imagePath); + ResourceLocation imageLocation = YACLPlatform.rl(field.parent().id().getNamespace(), imagePath); if (Minecraft.getInstance().getResourceManager().getResource(imageLocation).isPresent()) { builder.webpImage(imageLocation); } diff --git a/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/ListGroupImpl.java b/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/ListGroupImpl.java index f78d4ba6..022d56ef 100644 --- a/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/ListGroupImpl.java +++ b/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/ListGroupImpl.java @@ -8,6 +8,7 @@ import dev.isxander.yacl3.config.v2.api.autogen.OptionFactory; import dev.isxander.yacl3.config.v2.api.autogen.OptionAccess; import dev.isxander.yacl3.config.v2.impl.FieldBackedBinding; +import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.client.Minecraft; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; @@ -56,7 +57,7 @@ private OptionDescription description(ConfigField> field) { String imagePath = "textures/yacl3/" + field.parent().id().getPath() + "/" + field.access().name() + ".webp"; imagePath = imagePath.toLowerCase().replaceAll("[^a-z0-9/._:-]", "_"); - ResourceLocation imageLocation = new ResourceLocation(field.parent().id().getNamespace(), imagePath); + ResourceLocation imageLocation = YACLPlatform.rl(field.parent().id().getNamespace(), imagePath); if (Minecraft.getInstance().getResourceManager().getResource(imageLocation).isPresent()) { builder.webpImage(imageLocation); } diff --git a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java index 1f7c29bb..e6ab3f17 100644 --- a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java +++ b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java @@ -94,10 +94,18 @@ protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2 //Has a custom "z" value in case needed for later VertexConsumer vertex = graphics.bufferSource().getBuffer(RenderType.gui()); Matrix4f matrix4f = graphics.pose().last().pose(); + + /*? if >1.20.6 {*//* + vertex.addVertex(matrix4f, x1, y1, 0).setColor(startColor); + vertex.addVertex(matrix4f, x1, y2, 0).setColor(startColor); + vertex.addVertex(matrix4f, x2, y2, 0).setColor(endColor); + vertex.addVertex(matrix4f, x2, y1, 0).setColor(endColor); + *//*? } else { */ vertex.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex(); vertex.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex(); vertex.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex(); vertex.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex(); + /*? } */ } diff --git a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java index 85b86bb0..be95caad 100644 --- a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java +++ b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java @@ -63,7 +63,11 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) resetSmoothScrolling(); } - smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount()); + smoothScrollAmount = Mth.lerp( + delta * 0.5, + smoothScrollAmount, + getScrollAmount() + ); returnSmoothAmount = true; diff --git a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java index 8152d181..4cf1cca4 100644 --- a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java @@ -15,6 +15,7 @@ import dev.isxander.yacl3.gui.tab.TabExt; import dev.isxander.yacl3.gui.utils.GuiUtils; import dev.isxander.yacl3.impl.utils.YACLConstants; +import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -278,10 +279,6 @@ public static void renderMultilineTooltip(GuiGraphics graphics, Font font, Multi int drawY = y - 12; graphics.pose().pushPose(); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder bufferBuilder = tesselator.getBuilder(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); TooltipRenderUtil.renderTooltipBackground( graphics, drawX, @@ -290,11 +287,6 @@ public static void renderMultilineTooltip(GuiGraphics graphics, Font font, Multi height, 400 ); - RenderSystem.enableDepthTest(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - BufferUploader.drawWithShader(bufferBuilder.end()); - RenderSystem.disableBlend(); graphics.pose().translate(0.0, 0.0, 400.0); text.renderLeftAligned(graphics, drawX, drawY, lineHeight, -1); @@ -305,7 +297,7 @@ public static void renderMultilineTooltip(GuiGraphics graphics, Font font, Multi public static class CategoryTab implements TabExt { /*? if >1.20.4 {*/ - private static final ResourceLocation DARKER_BG = new ResourceLocation("textures/gui/menu_list_background.png"); + private static final ResourceLocation DARKER_BG = YACLPlatform.mcRl("textures/gui/menu_list_background.png"); /*?}*/ private final YACLScreen screen; diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java b/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java index 3c4f03a0..bb6c6648 100644 --- a/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java +++ b/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java @@ -1,6 +1,7 @@ package dev.isxander.yacl3.gui.utils; +import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.ResourceLocationException; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -26,7 +27,7 @@ public final class ItemRegistryHelper { */ public static boolean isRegisteredItem(String identifier) { try { - ResourceLocation itemIdentifier = new ResourceLocation(identifier.toLowerCase()); + ResourceLocation itemIdentifier = YACLPlatform.parseRl(identifier.toLowerCase()); return BuiltInRegistries.ITEM.containsKey(itemIdentifier); } catch (ResourceLocationException e) { return false; @@ -43,7 +44,7 @@ public static boolean isRegisteredItem(String identifier) { */ public static Item getItemFromName(String identifier, Item defaultItem) { try { - ResourceLocation itemIdentifier = new ResourceLocation(identifier.toLowerCase()); + ResourceLocation itemIdentifier = YACLPlatform.parseRl(identifier.toLowerCase()); if (BuiltInRegistries.ITEM.containsKey(itemIdentifier)) { return BuiltInRegistries.ITEM.get(itemIdentifier); } diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java b/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java index b49557ba..b8293fba 100644 --- a/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java +++ b/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java @@ -8,10 +8,10 @@ public class YACLRenderHelper { /*? if >1.20.1 {*/ private static final net.minecraft.client.gui.components.WidgetSprites SPRITES = new net.minecraft.client.gui.components.WidgetSprites( - new ResourceLocation("widget/button"), // normal - new ResourceLocation("widget/button_disabled"), // disabled & !focused - new ResourceLocation("widget/button_highlighted"), // !disabled & focused - new ResourceLocation("widget/slider_highlighted") // disabled & focused + YACLPlatform.mcRl("widget/button"), // normal + YACLPlatform.mcRl("widget/button_disabled"), // disabled & !focused + YACLPlatform.mcRl("widget/button_highlighted"), // !disabled & focused + YACLPlatform.mcRl("widget/slider_highlighted") // disabled & focused ); /*?} else {*//* private static final ResourceLocation SLIDER_LOCATION = new ResourceLocation("textures/gui/slider.png"); diff --git a/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java b/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java index bfb05864..e3303244 100644 --- a/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java +++ b/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java @@ -14,8 +14,28 @@ import java.nio.file.Path; public final class YACLPlatform { + public static ResourceLocation parseRl(String rl) { + /*? if >1.20.6 {*//* + return ResourceLocation.parse(rl); + *//*?} else {*/ + return new ResourceLocation(rl); + /*?}*/ + } + public static ResourceLocation rl(String path) { - return new ResourceLocation("yet_another_config_lib_v3", path); + return rl("yet_another_config_lib_v3", path); + } + + public static ResourceLocation mcRl(String path) { + return rl("minecraft", path); + } + + public static ResourceLocation rl(String namespace, String path) { + /*? if >1.20.6 {*//* + return ResourceLocation.fromNamespaceAndPath(namespace, path); + *//*?} else {*/ + return new ResourceLocation(namespace, path); + /*?}*/ } public static Env getEnvironment() { diff --git a/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java b/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java index 9bb361e5..186d1922 100644 --- a/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java +++ b/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java @@ -24,7 +24,7 @@ public class AutogenConfigTest { public static final ConfigClassHandler INSTANCE = ConfigClassHandler.createBuilder(AutogenConfigTest.class) - .id(new ResourceLocation("yacl3-test", "config")) + .id(YACLPlatform.rl("yacl3-test", "config")) .serializer(config -> GsonConfigSerializerBuilder.create(config) .setPath(YACLPlatform.getConfigDir().resolve("yacl-test-v2.json5")) .setJson5(true) diff --git a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java index cdc1285a..07e0098e 100644 --- a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java +++ b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java @@ -14,6 +14,7 @@ import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController; import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController; import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController; +import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.GraphicsStatus; @@ -502,7 +503,7 @@ private static Screen getFullTestSuite(Screen parent) { } private static ResourceLocation imageSample(String name) { - return new ResourceLocation("yacl_test", "textures/images/" + name); + return YACLPlatform.rl("yacl_test", "textures/images/" + name); } private static boolean myBooleanOption = true; diff --git a/src/testmod/kotlin/dev/isxander/yacl3/test/DslTest.kt b/src/testmod/kotlin/dev/isxander/yacl3/test/DslTest.kt index 2efd9a4e..a3ed7cc7 100644 --- a/src/testmod/kotlin/dev/isxander/yacl3/test/DslTest.kt +++ b/src/testmod/kotlin/dev/isxander/yacl3/test/DslTest.kt @@ -4,6 +4,7 @@ import dev.isxander.yacl3.api.OptionFlag import dev.isxander.yacl3.api.controller.BooleanControllerBuilder import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder import dev.isxander.yacl3.dsl.* +import dev.isxander.yacl3.platform.YACLPlatform import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceLocation @@ -85,7 +86,7 @@ fun kotlinDslGui(parent: Screen?) = YetAnotherConfigLib("namespace") { addDefaultDescription(lines = 5) text { Component.translatable("somecustomkey") } - webpImage(ResourceLocation("namespace", "image.png")) + webpImage(YACLPlatform.rl("namespace", "image.png")) } // KProperties are cool! diff --git a/versions/1.20.1-fabric/gradle.properties b/versions/1.20.1-fabric/gradle.properties index abee1450..4bd5fcc8 100644 --- a/versions/1.20.1-fabric/gradle.properties +++ b/versions/1.20.1-fabric/gradle.properties @@ -1,4 +1,5 @@ loom.platform=fabric +mcVersion=1.20.1 java.version=17 diff --git a/versions/1.20.1-forge/gradle.properties b/versions/1.20.1-forge/gradle.properties index 64b9e33f..3d244071 100644 --- a/versions/1.20.1-forge/gradle.properties +++ b/versions/1.20.1-forge/gradle.properties @@ -1,4 +1,5 @@ loom.platform=forge +mcVersion=1.20.1 java.version=17 diff --git a/versions/1.20.4-fabric/gradle.properties b/versions/1.20.4-fabric/gradle.properties index 542f0faf..ecf8015f 100644 --- a/versions/1.20.4-fabric/gradle.properties +++ b/versions/1.20.4-fabric/gradle.properties @@ -1,4 +1,5 @@ loom.platform=fabric +mcVersion=1.20.4 java.version=17 diff --git a/versions/1.20.4-neoforge/gradle.properties b/versions/1.20.4-neoforge/gradle.properties index 6274b1a3..2ed01309 100644 --- a/versions/1.20.4-neoforge/gradle.properties +++ b/versions/1.20.4-neoforge/gradle.properties @@ -1,4 +1,5 @@ loom.platform=neoforge +mcVersion=1.20.4 java.version=17 diff --git a/versions/1.20.6-fabric/gradle.properties b/versions/1.20.6-fabric/gradle.properties index 5a65f6d0..00616288 100644 --- a/versions/1.20.6-fabric/gradle.properties +++ b/versions/1.20.6-fabric/gradle.properties @@ -1,4 +1,5 @@ loom.platform=fabric +mcVersion=1.20.6 java.version=21 diff --git a/versions/1.20.6-neoforge/gradle.properties b/versions/1.20.6-neoforge/gradle.properties index f354ca0f..2e9f1dfe 100644 --- a/versions/1.20.6-neoforge/gradle.properties +++ b/versions/1.20.6-neoforge/gradle.properties @@ -1,4 +1,5 @@ loom.platform=neoforge +mcVersion=1.20.6 java.version=21 diff --git a/versions/1.21-fabric/gradle.properties b/versions/1.21-fabric/gradle.properties new file mode 100644 index 00000000..678600ff --- /dev/null +++ b/versions/1.21-fabric/gradle.properties @@ -0,0 +1,8 @@ +loom.platform=fabric +mcVersion=1.21-pre1 + +java.version=21 + +deps.quiltMappings= +deps.fabricApi=0.99.2+1.21 +fmj.mcDep=~1.21-