aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisxander <xander@isxander.dev>2023-11-22 17:00:22 +0000
committerisxander <xander@isxander.dev>2023-11-22 17:00:22 +0000
commitc8ab29d1d6111ba581b0f0bcb0a6d0c852161edb (patch)
treeff7b25f06aef45bdb93e6f4743e20a6b2c78ee0c
parent4cdfa58b27d790786cbb2f17aa8f4635ea9d5a2d (diff)
downloadYetAnotherConfigLib-c8ab29d1d6111ba581b0f0bcb0a6d0c852161edb.tar.gz
YetAnotherConfigLib-c8ab29d1d6111ba581b0f0bcb0a6d0c852161edb.tar.bz2
YetAnotherConfigLib-c8ab29d1d6111ba581b0f0bcb0a6d0c852161edb.zip
Update to 1.20.3-pre2, temp disable forge projects
-rw-r--r--build.gradle.kts2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java9
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java18
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java65
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java8
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/YACLTooltip.java20
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java3
-rw-r--r--common/src/main/resources/yacl.accesswidener1
-rw-r--r--gradle.properties2
-rw-r--r--gradle/libs.versions.toml8
-rw-r--r--test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java2
12 files changed, 71 insertions, 71 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 9b54b7d..10626a0 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -13,7 +13,7 @@ architectury {
minecraft = libs.versions.minecraft.get()
}
-version = "3.3.0-beta.1+1.20.2"
+version = "3.3.0+1.20.3"
val isBeta = "beta" in version.toString()
val changelogText = rootProject.file("changelogs/${project.version}.md").takeIf { it.exists() }?.readText() ?: "No changelog provided."
diff --git a/common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java b/common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java
index deff6d7..4e7c931 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java
@@ -1,6 +1,7 @@
package dev.isxander.yacl3.config;
import com.google.gson.*;
+import dev.isxander.yacl3.config.v2.impl.serializer.GsonConfigSerializer;
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
import dev.isxander.yacl3.impl.utils.YACLConstants;
import net.minecraft.core.registries.BuiltInRegistries;
@@ -66,8 +67,8 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> {
this.path = path;
this.gson = builder
.setExclusionStrategies(new ConfigExclusionStrategy())
- .registerTypeHierarchyAdapter(Component.class, new Component.Serializer())
- .registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
+ .registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter())
+ .registerTypeHierarchyAdapter(Style.class, new GsonConfigSerializer.StyleTypeAdapter())
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter())
.serializeNulls()
@@ -161,8 +162,8 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> {
private UnaryOperator<GsonBuilder> gsonBuilder = builder -> builder
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.serializeNulls()
- .registerTypeHierarchyAdapter(Component.class, new Component.Serializer())
- .registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
+ .registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter())
+ .registerTypeHierarchyAdapter(Style.class, new GsonConfigSerializer.StyleTypeAdapter())
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter());
diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
index a60bcb1..1edd28a 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
@@ -1,12 +1,14 @@
package dev.isxander.yacl3.config.v2.impl.serializer;
import com.google.gson.*;
+import com.mojang.serialization.JsonOps;
import dev.isxander.yacl3.config.GsonConfigInstance;
import dev.isxander.yacl3.config.v2.api.*;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
import dev.isxander.yacl3.impl.utils.YACLConstants;
import dev.isxander.yacl3.platform.YACLPlatform;
+import net.minecraft.commands.ParserUtils;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
@@ -173,6 +175,18 @@ public class GsonConfigSerializer<T> extends ConfigSerializer<T> {
config.load();
}
+ public static class StyleTypeAdapter implements JsonSerializer<Style>, JsonDeserializer<Style> {
+ @Override
+ public Style deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ return Style.Serializer.CODEC.parse(JsonOps.INSTANCE, json).result().orElse(Style.EMPTY);
+ }
+
+ @Override
+ public JsonElement serialize(Style src, Type typeOfSrc, JsonSerializationContext context) {
+ return Style.Serializer.CODEC.encodeStart(JsonOps.INSTANCE, src).result().orElse(JsonNull.INSTANCE);
+ }
+ }
+
public static class ColorTypeAdapter implements JsonSerializer<Color>, JsonDeserializer<Color> {
@Override
public Color deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
@@ -205,8 +219,8 @@ public class GsonConfigSerializer<T> extends ConfigSerializer<T> {
private UnaryOperator<GsonBuilder> gsonBuilder = builder -> builder
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.serializeNulls()
- .registerTypeHierarchyAdapter(Component.class, new Component.Serializer())
- .registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
+ .registerTypeHierarchyAdapter(Component.class, new Component.SerializerAdapter())
+ .registerTypeHierarchyAdapter(Style.class, new StyleTypeAdapter())
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
.registerTypeHierarchyAdapter(Item.class, new ItemTypeAdapter())
.setPrettyPrinting();
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
index a36bd5e..91cda1f 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
@@ -14,17 +14,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> implements LayoutElement {
- protected int x, y;
-
private double smoothScrollAmount = getScrollAmount();
private boolean returnSmoothAmount = false;
private final boolean doSmoothScrolling;
public ElementListWidgetExt(Minecraft client, int x, int y, int width, int height, boolean smoothScrolling) {
- super(client, width, height, y, y + height, 22);
- this.x = this.x0 = x;
- this.y = y;
- this.x1 = this.x0 + width;
+ super(client, x, y, width, height);
this.doSmoothScrolling = smoothScrolling;
setRenderBackground(true);
setRenderHeader(false, 0);
@@ -40,17 +35,17 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
@Override
protected int getScrollbarPosition() {
// default implementation does not respect left/right
- return this.x1 - 2;
+ return this.getX() + this.getWidth() - 2;
}
@Override
- public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
+ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount());
returnSmoothAmount = true;
- graphics.enableScissor(x0, y0, x1, y1);
+ graphics.enableScissor(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight());
- super.render(graphics, mouseX, mouseY, delta);
+ super.renderWidget(graphics, mouseX, mouseY, delta);
graphics.disableScissor();
@@ -58,12 +53,10 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
}
public void updateDimensions(ScreenRectangle rectangle) {
- this.x0 = rectangle.left();
- this.y0 = rectangle.top();
- this.x1 = rectangle.right();
- this.y1 = rectangle.bottom();
- this.width = rectangle.width();
- this.height = rectangle.height();
+ this.setX(rectangle.left());
+ this.setY(rectangle.top());
+ this.setWidth(rectangle.width());
+ this.setHeight(rectangle.height());
}
/**
@@ -87,10 +80,10 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
protected E getEntryAtPosition(double x, double y) {
y += getScrollAmount();
- if (x < this.x0 || x > this.x1)
+ if (x < this.getX() || x > this.getX() + this.getWidth())
return null;
- int currentY = this.y0 - headerHeight + 4;
+ int currentY = this.getY() - headerHeight + 4;
for (E entry : children()) {
if (y >= currentY && y <= currentY + entry.getItemHeight()) {
return entry;
@@ -124,7 +117,7 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
@Override
protected int getRowTop(int index) {
- int integer = y0 + 4 - (int) this.getScrollAmount() + headerHeight;
+ int integer = getY() + 4 - (int) this.getScrollAmount() + headerHeight;
for (int i = 0; i < children().size() && i < index; i++)
integer += children().get(i).getItemHeight();
return integer;
@@ -141,7 +134,7 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
int top = this.getRowTop(i);
int bottom = top + entry.getItemHeight();
int entryHeight = entry.getItemHeight() - 4;
- if (bottom >= this.y0 && top <= this.y1) {
+ if (bottom >= this.getY() && top <= this.getY() + this.getHeight()) {
this.renderItem(graphics, mouseX, mouseY, delta, i, left, top, right, entryHeight);
}
}
@@ -150,38 +143,6 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
/* END cloth config code */
@Override
- public void setX(int i) {
- this.x = x0 = i;
- this.x1 = x0 + width;
- }
-
- @Override
- public void setY(int i) {
- this.y = y0 = i;
- this.y1 = y0 + height;
- }
-
- @Override
- public int getX() {
- return x;
- }
-
- @Override
- public int getY() {
- return y;
- }
-
- @Override
- public int getWidth() {
- return width;
- }
-
- @Override
- public int getHeight() {
- return height;
- }
-
- @Override
public void visitWidgets(Consumer<AbstractWidget> consumer) {
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
index 666c3c8..e8b4eb6 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java
@@ -31,7 +31,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
private DescriptionWithName lastHoveredOption;
public OptionListWidget(YACLScreen screen, ConfigCategory category, Minecraft client, int x, int y, int width, int height, Consumer<DescriptionWithName> hoverEvent) {
- super(client, x, y, width, height, true);
+ super(client, width, height, x, y, true);
this.yaclScreen = screen;
this.category = category;
this.hoverEvent = hoverEvent;
@@ -183,7 +183,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
@Override
protected int getScrollbarPosition() {
- return x1 - (int)(width * 0.05f);
+ return getX() + getWidth() - (int)(width * 0.05f);
}
public void recacheViewableChildren() {
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java
index 396f20b..143512f 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java
@@ -6,6 +6,7 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
public class TooltipButtonWidget extends Button {
@@ -15,11 +16,12 @@ public class TooltipButtonWidget extends Button {
super(x, y, width, height, message, onPress, DEFAULT_NARRATION);
this.screen = screen;
if (tooltip != null)
- setTooltip(Tooltip.create(tooltip));
+ setTooltip(new YACLTooltip(tooltip, this));
}
+ @Nullable
@Override
- protected @NotNull ClientTooltipPositioner createTooltipPositioner() {
- return new YACLTooltipPositioner(this);
+ public Tooltip getTooltip() {
+ return super.getTooltip();
}
}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/YACLTooltip.java b/common/src/main/java/dev/isxander/yacl3/gui/YACLTooltip.java
new file mode 100644
index 0000000..966b8a8
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl3/gui/YACLTooltip.java
@@ -0,0 +1,20 @@
+package dev.isxander.yacl3.gui;
+
+import net.minecraft.client.gui.components.Tooltip;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
+import net.minecraft.network.chat.Component;
+
+public class YACLTooltip extends Tooltip {
+ private final net.minecraft.client.gui.components.AbstractWidget widget;
+
+ public YACLTooltip(Component tooltip, net.minecraft.client.gui.components.AbstractWidget widget) {
+ super(tooltip, tooltip);
+ this.widget = widget;
+ }
+
+ @Override
+ protected ClientTooltipPositioner createTooltipPositioner(boolean bl, boolean bl2, ScreenRectangle screenRectangle) {
+ return new YACLTooltipPositioner(widget);
+ }
+}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
index 195f6d7..e79d9eb 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
@@ -7,6 +7,7 @@ import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.chat.contents.PlainTextContents;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -120,7 +121,7 @@ public final class ConfigCategoryImpl implements ConfigCategory {
MutableComponent concatenatedTooltip = Component.empty();
boolean first = true;
for (Component line : tooltipLines) {
- if (line.getContents() == ComponentContents.EMPTY)
+ if (line.getContents() == PlainTextContents.EMPTY)
continue;
if (!first) concatenatedTooltip.append("\n");
diff --git a/common/src/main/resources/yacl.accesswidener b/common/src/main/resources/yacl.accesswidener
index 286b6ab..7c0e2ca 100644
--- a/common/src/main/resources/yacl.accesswidener
+++ b/common/src/main/resources/yacl.accesswidener
@@ -9,3 +9,4 @@ accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar width
accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabManager Lnet/minecraft/client/gui/components/tabs/TabManager;
accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabs Lcom/google/common/collect/ImmutableList;
accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabButtons Lcom/google/common/collect/ImmutableList;
+accessible method net/minecraft/client/gui/components/Tooltip <init> (Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/Component;)V
diff --git a/gradle.properties b/gradle.properties
index bbff8b8..30a4ee4 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -8,4 +8,4 @@ modrinthId=yacl
curseforgeId=667299
githubProject=isXander/YetAnotherConfigLib
-loaders=fabric,forge
+loaders=fabric
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index df3326b..19f5382 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -10,9 +10,9 @@ github_release = "2.4.+"
machete = "2.+"
grgit = "5.0.+"
-minecraft = "1.20.2"
-quilt_mappings = "3"
-fabric_loader = "0.14.22"
+minecraft = "1.20.3-pre2"
+quilt_mappings = "0"
+fabric_loader = "0.14.23"
# Common Dependencies
mixin_extras = "0.2.0"
@@ -20,7 +20,7 @@ twelvemonkeys_imageio = "3.10.0"
quilt_parsers = "0.2.1"
# Fabric-like Dependencies
-fabric_api = "0.90.4+1.20.2"
+fabric_api = "0.90.11+1.20.3"
# Forge Dependencies
forge = "1.20.2-48.0.33"
diff --git a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
index ec16e2e..0c56caa 100644
--- a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
+++ b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
@@ -284,7 +284,7 @@ public class GuiTest {
.name(Component.literal("Options that aren't really options"))
.option(ButtonOption.createBuilder()
.name(Component.literal("Button \"Option\""))
- .action((screen, opt) -> SystemToast.add(Minecraft.getInstance().getToasts(), SystemToast.SystemToastIds.TUTORIAL_HINT, Component.literal("Button Pressed"), Component.literal("Button option was invoked!")))
+ .action((screen, opt) -> SystemToast.add(Minecraft.getInstance().getToasts(), SystemToast.SystemToastId.PERIODIC_NOTIFICATION, Component.literal("Button Pressed"), Component.literal("Button option was invoked!")))
.build())
.option(LabelOption.create(
Component.empty()