Skip to content

Commit

Permalink
1.21 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed May 29, 2024
1 parent 4125382 commit 646c7ba
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 32 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -111,15 +111,14 @@ repositories {
forRepository { maven("https://thedarkcolour.github.io/KotlinForForge/") }
filter { includeGroup("thedarkcolour") }
}

maven("https://maven.neoforged.net/releases/")
}

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") {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ plugins {
}

extensions.configure<StonecutterSettings> {
kotlinController(true)
centralScript("build.gradle.kts")
kotlinController = true
centralScript = "build.gradle.kts"
shared {
fun mc(mcVersion: String, name: String = mcVersion, loaders: Iterable<String>) {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,7 @@ private OptionDescription description(ConfigField<List<T>> 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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
/*? } */
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
12 changes: 2 additions & 10 deletions src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class AutogenConfigTest {
public static final ConfigClassHandler<AutogenConfigTest> 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)
Expand Down
3 changes: 2 additions & 1 deletion src/testmod/java/dev/isxander/yacl3/test/GuiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/testmod/kotlin/dev/isxander/yacl3/test/DslTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions versions/1.20.1-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=fabric
mcVersion=1.20.1

java.version=17

Expand Down
1 change: 1 addition & 0 deletions versions/1.20.1-forge/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=forge
mcVersion=1.20.1

java.version=17

Expand Down
1 change: 1 addition & 0 deletions versions/1.20.4-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=fabric
mcVersion=1.20.4

java.version=17

Expand Down
1 change: 1 addition & 0 deletions versions/1.20.4-neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=neoforge
mcVersion=1.20.4

java.version=17

Expand Down
1 change: 1 addition & 0 deletions versions/1.20.6-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=fabric
mcVersion=1.20.6

java.version=21

Expand Down
1 change: 1 addition & 0 deletions versions/1.20.6-neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
loom.platform=neoforge
mcVersion=1.20.6

java.version=21

Expand Down
8 changes: 8 additions & 0 deletions versions/1.21-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -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-

0 comments on commit 646c7ba

Please sign in to comment.