Skip to content

Commit a1f8472

Browse files
committed
port: to 1.21.6 (25w21a)
- fixed popup widget related bugs: - allowed clicking off of popup widget - fix requiring to double click after previously closing colour widget - tick the underlayed screen in popupscreen
1 parent d407367 commit a1f8472

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+604
-140
lines changed

build.gradle.kts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ modstitch {
9797
}
9898
}
9999

100+
mixin.useLegacyMixinAp = false
101+
100102
accessWidenerPath = rootProject.file("src/main/resources/yacl.accesswidener")
101103
}
104+
105+
// do not validate
106+
tasks.getByName("validateAccessWidener").enabled = false
102107
}
103108

104109
moddevgradle {
@@ -140,27 +145,27 @@ modstitch {
140145
}
141146

142147
stonecutter {
143-
consts(
144-
"fabric" to modstitch.isLoom,
145-
"neoforge" to modstitch.isModDevGradleRegular,
146-
"forge" to modstitch.isModDevGradleLegacy,
147-
"forgelike" to modstitch.isModDevGradle,
148-
)
149-
150-
dependencies(
151-
"fapi" to (findProperty("deps.fabricApi")?.toString() ?: "0.0.0"),
152-
)
148+
constants {
149+
put("fabric", modstitch.isLoom)
150+
put("neoforge", modstitch.isModDevGradleRegular)
151+
put("forge", modstitch.isModDevGradleLegacy)
152+
put("forgelike", modstitch.isModDevGradle)
153+
}
154+
155+
dependencies {
156+
put("fapi", (findProperty("deps.fabricApi")?.toString() ?: "0.0.0"))
157+
}
153158
}
154159

155160
dependencies {
156161
fun Dependency?.jij() = this?.also(::modstitchJiJ)
157162

158163
prop("deps.mixinExtras") {
159164
when {
160-
isFabric -> modstitchImplementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:$it")!!).jij()
165+
isFabric -> modstitchImplementation("io.github.llamalad7:mixinextras-fabric:$it").jij()
161166
isNeoforge -> implementation("io.github.llamalad7:mixinextras-neoforge:$it").jij()
162167
isForge -> {
163-
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$it")!!)
168+
compileOnly("io.github.llamalad7:mixinextras-common:$it")
164169
implementation("io.github.llamalad7:mixinextras-forge:$it").jij()
165170
}
166171
else -> error("Unknown loader")

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pluginManagement {
1313
}
1414

1515
plugins {
16-
id("dev.kikugie.stonecutter") version "0.7-alpha.5"
16+
id("dev.kikugie.stonecutter") version "0.7-alpha.16"
1717
}
1818

1919
stonecutter {

src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dev.isxander.yacl3.config;
22

33
import com.google.gson.*;
4+
import dev.isxander.yacl3.config.util.CodecSerializerAdapter;
45
import dev.isxander.yacl3.config.v2.impl.serializer.GsonConfigSerializer;
56
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
67
import dev.isxander.yacl3.impl.utils.YACLConstants;
78
import net.minecraft.core.RegistryAccess;
89
import net.minecraft.core.registries.BuiltInRegistries;
910
import net.minecraft.network.chat.Component;
11+
import net.minecraft.network.chat.ComponentSerialization;
1012
import net.minecraft.network.chat.Style;
1113
import net.minecraft.world.item.Item;
1214

@@ -68,7 +70,7 @@ public GsonConfigInstance(Class<T> configClass, Path path, GsonBuilder builder)
6870
this.path = path;
6971
this.gson = builder
7072
.setExclusionStrategies(new ConfigExclusionStrategy())
71-
.registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter(RegistryAccess.EMPTY))
73+
.registerTypeHierarchyAdapter(Component.class, new CodecSerializerAdapter<>(ComponentSerialization.CODEC))
7274
.registerTypeHierarchyAdapter(Style.class, new GsonConfigSerializer.StyleTypeAdapter())
7375
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
7476
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter())
@@ -163,7 +165,7 @@ public static class Builder<T> {
163165
private UnaryOperator<GsonBuilder> gsonBuilder = builder -> builder
164166
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
165167
.serializeNulls()
166-
.registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter(RegistryAccess.EMPTY))
168+
.registerTypeHierarchyAdapter(Component.class, new CodecSerializerAdapter<>(ComponentSerialization.CODEC))
167169
.registerTypeHierarchyAdapter(Style.class, new GsonConfigSerializer.StyleTypeAdapter())
168170
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
169171
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.isxander.yacl3.config.util;
2+
3+
import com.google.gson.*;
4+
import com.mojang.serialization.Codec;
5+
import com.mojang.serialization.JsonOps;
6+
7+
import java.lang.reflect.Type;
8+
9+
public class CodecSerializerAdapter<T> implements JsonSerializer<T>, JsonDeserializer<T> {
10+
private final Codec<T> codec;
11+
12+
public CodecSerializerAdapter(Codec<T> codec) {
13+
this.codec = codec;
14+
}
15+
16+
@Override
17+
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
18+
return codec.encodeStart(JsonOps.INSTANCE, src).getOrThrow();
19+
}
20+
21+
@Override
22+
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
23+
return codec.parse(JsonOps.INSTANCE, json).getOrThrow();
24+
}
25+
}

src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.*;
44
import com.mojang.serialization.JsonOps;
5+
import dev.isxander.yacl3.config.util.CodecSerializerAdapter;
56
import dev.isxander.yacl3.config.v2.api.*;
67
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
78
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
@@ -10,6 +11,7 @@
1011
import net.minecraft.core.RegistryAccess;
1112
import net.minecraft.core.registries.BuiltInRegistries;
1213
import net.minecraft.network.chat.Component;
14+
import net.minecraft.network.chat.ComponentSerialization;
1315
import net.minecraft.network.chat.Style;
1416
import net.minecraft.world.item.Item;
1517
import org.jetbrains.annotations.ApiStatus;
@@ -219,7 +221,7 @@ public static class Builder<T> implements GsonConfigSerializerBuilder<T> {
219221
private UnaryOperator<GsonBuilder> gsonBuilder = builder -> builder
220222
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
221223
.serializeNulls()
222-
.registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter(RegistryAccess.EMPTY))
224+
.registerTypeHierarchyAdapter(Component.class, new CodecSerializerAdapter<>(ComponentSerialization.CODEC))
223225
.registerTypeHierarchyAdapter(Style.class, new StyleTypeAdapter())
224226
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
225227
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter())

src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.blaze3d.vertex.VertexConsumer;
44
import dev.isxander.yacl3.api.utils.Dimension;
5+
import dev.isxander.yacl3.gui.render.ColorGradientRenderState;
56
import dev.isxander.yacl3.gui.utils.GuiUtils;
67
import dev.isxander.yacl3.gui.utils.YACLRenderHelper;
78
import net.minecraft.client.Minecraft;
@@ -89,43 +90,24 @@ protected void drawOutline(GuiGraphics graphics, int x1, int y1, int x2, int y2,
8990
graphics.fill(x1, y1, x1 + width, y2, color);
9091
}
9192

92-
protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int startColor, int endColor, VertexConsumer consumer) {
93-
//Fills a gradient, left to right
94-
//Uses practically the same method as the GuiGraphics class, but with the x/y moved
95-
//Has a custom "z" value in case needed for later
96-
Matrix4f matrix4f = graphics.pose().last().pose();
97-
98-
consumer.addVertex(matrix4f, x1, y1, 0).setColor(startColor);
99-
consumer.addVertex(matrix4f, x1, y2, 0).setColor(startColor);
100-
consumer.addVertex(matrix4f, x2, y2, 0).setColor(endColor);
101-
consumer.addVertex(matrix4f, x2, y1, 0).setColor(endColor);
102-
}
103-
104-
10593
protected void drawRainbowGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2) {
10694
//Draws a rainbow gradient, left to right
107-
int[] colors = new int[] {Color.red.getRGB(), Color.yellow.getRGB(), Color.green.getRGB(),
108-
Color.cyan.getRGB(), Color.blue.getRGB(), Color.magenta.getRGB(), Color.red.getRGB()}; //all the colors in the gradient
95+
int[] colors = new int[] {0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF0000}; //all the colors in the gradient
10996
int width = x2 - x1;
11097
int maxColors = colors.length - 1;
11198

112-
GuiUtils.drawSpecial(graphics, bufferSource -> {
113-
VertexConsumer consumer = bufferSource.getBuffer(RenderType.gui());
114-
115-
for (int color = 0; color < maxColors; color++) {
116-
//First checks if the final color is being rendered, if true -> uses x2 int instead of x1
117-
//if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
118-
//the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
119-
//The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
120-
fillSidewaysGradient(
121-
graphics,
122-
x1 + (width / maxColors * color), y1,
123-
color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
124-
colors[color], colors[color + 1],
125-
consumer
126-
);
127-
}
128-
});
99+
for (int color = 0; color < maxColors; color++) {
100+
//First checks if the final color is being rendered, if true -> uses x2 int instead of x1
101+
//if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
102+
//the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
103+
//The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
104+
ColorGradientRenderState.createHorizontal(
105+
graphics,
106+
x1 + (width / maxColors * color), y1,
107+
color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
108+
colors[color], colors[color + 1]
109+
).submit(graphics);
110+
}
129111

130112
}
131113

src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ protected int scrollBarY() {
7070
}
7171
*///?}
7272

73+
//? if >=1.21.6 {
74+
75+
/*@Override
76+
public int maxScrollAmount() {
77+
return super.maxScrollAmount() + 5;
78+
}
79+
*///?}
80+
7381
@Override
7482
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
7583
if (usingScrollbar) {

src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del
6565
if (nameWidth > getWidth()) {
6666
renderScrollingString(graphics, font, description.name(), getX(), y, getX() + getWidth(), y + font.lineHeight, -1);
6767
} else {
68-
graphics.drawString(font, description.name(), getX(), y, 0xFFFFFF);
68+
graphics.drawString(font, description.name(), getX(), y, 0xFFFFFFFF);
6969
}
7070

7171
y += 5 + font.lineHeight;
@@ -86,7 +86,7 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del
8686

8787
descriptionY = y;
8888
for (var line : wrappedText) {
89-
graphics.drawString(font, line, getX(), y, 0xFFFFFF);
89+
graphics.drawString(font, line, getX(), y, 0xFFFFFFFF);
9090
y += font.lineHeight;
9191
}
9292

src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.isxander.yacl3.gui;
22

3-
import com.mojang.blaze3d.vertex.PoseStack;
3+
import dev.isxander.yacl3.gui.utils.GuiUtils;
44
import net.minecraft.client.Minecraft;
55
import net.minecraft.client.gui.Font;
66
import net.minecraft.client.gui.GuiGraphics;
@@ -23,12 +23,11 @@ public TextScaledButtonWidget(Screen screen, int x, int y, int width, int height
2323
@Override
2424
public void renderString(GuiGraphics graphics, Font textRenderer, int color) {
2525
Font font = Minecraft.getInstance().font;
26-
PoseStack pose = graphics.pose();
2726

28-
pose.pushPose();
29-
pose.translate(((this.getX() + this.width / 2f) - font.width(getMessage()) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0);
30-
pose.scale(textScale, textScale, 1);
27+
GuiUtils.pushPose(graphics);
28+
GuiUtils.translate2D(graphics, ((this.getX() + this.width / 2f) - font.width(getMessage()) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale);
29+
GuiUtils.scale2D(graphics, textScale, textScale);
3130
graphics.drawString(font, getMessage(), 0, 0, color | Mth.ceil(this.alpha * 255.0F) << 24, true);
32-
pose.popPose();
31+
GuiUtils.popPose(graphics);
3332
}
3433
}

src/main/java/dev/isxander/yacl3/gui/YACLScreen.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,23 @@ public static void renderMultilineTooltip(GuiGraphics graphics, Font font, Multi
266266
int drawX = x + 12;
267267
int drawY = y - 12;
268268

269-
graphics.pose().pushPose();
269+
GuiUtils.pushPose(graphics);
270270
TooltipRenderUtil.renderTooltipBackground(
271271
graphics,
272272
drawX,
273273
drawY,
274274
maxWidth,
275-
height,
276-
400
275+
height
276+
//? if <1.21.6
277+
,400
277278
//? if >=1.21.2
278279
,null
279280
);
280-
graphics.pose().translate(0.0, 0.0, 400.0);
281+
GuiUtils.translateZ(graphics, 400);
281282

282283
text.renderLeftAligned(graphics, drawX, drawY, lineHeight, -1);
283284

284-
graphics.pose().popPose();
285+
GuiUtils.popPose(graphics);
285286
}
286287
}
287288

@@ -383,17 +384,17 @@ public void renderBackground(GuiGraphics graphics) {
383384
GuiUtils.blitGuiTex(graphics, DARKER_BG, rightPaneDim.left(), rightPaneDim.top(), rightPaneDim.right() + 2, rightPaneDim.bottom() + 2, rightPaneDim.width() + 2, rightPaneDim.height() + 2, 32, 32);
384385

385386
// top separator for right pane
386-
graphics.pose().pushPose();
387-
graphics.pose().translate(0, 0, 10);
387+
GuiUtils.pushPose(graphics);
388+
GuiUtils.translateZ(graphics, 10);
388389
GuiUtils.blitGuiTex(graphics, CreateWorldScreen.HEADER_SEPARATOR, rightPaneDim.left() - 1, rightPaneDim.top() - 2, 0.0F, 0.0F, rightPaneDim.width() + 1, 2, 32, 2);
389-
graphics.pose().popPose();
390+
GuiUtils.popPose(graphics);
390391

391392
// left separator for right pane
392-
graphics.pose().pushPose();
393-
graphics.pose().translate(rightPaneDim.left(), rightPaneDim.top() - 1, 0);
394-
graphics.pose().rotateAround(Axis.ZP.rotationDegrees(90), 0, 0, 1);
393+
GuiUtils.pushPose(graphics);
394+
GuiUtils.translate2D(graphics, rightPaneDim.left(), rightPaneDim.top() - 1);
395+
GuiUtils.rotate2D(graphics, 90);
395396
GuiUtils.blitGuiTex(graphics, CreateWorldScreen.FOOTER_SEPARATOR, 0, 0, 0f, 0f, rightPaneDim.height() + 1, 2, 32, 2);
396-
graphics.pose().popPose();
397+
GuiUtils.popPose(graphics);
397398
}
398399

399400
@Override

0 commit comments

Comments
 (0)