Skip to content

Commit 60b4f59

Browse files
committed
backport to 1.20.1
1 parent 3f1b19b commit 60b4f59

File tree

19 files changed

+99
-43
lines changed

19 files changed

+99
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.2.0
2+
3+
- Backport to 1.20.1
4+
15
# 1.1.2
26
- Fix YACL bindings incorrectly using the current value as the default
37

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ loom {
4848

4949
tasks {
5050
withType<JavaCompile> {
51-
options.release = 21
51+
options.release = minecraftVersion.javaVersion()
5252
}
5353

5454
withType<RemapJarTask> {
@@ -84,8 +84,8 @@ tasks {
8484
java {
8585
withSourcesJar()
8686

87-
sourceCompatibility = JavaVersion.VERSION_21
88-
targetCompatibility = JavaVersion.VERSION_21
87+
sourceCompatibility = JavaVersion.toVersion(minecraftVersion.javaVersion())
88+
targetCompatibility = JavaVersion.toVersion(minecraftVersion.javaVersion())
8989
}
9090

9191
val buildAndCollect = tasks.register<Copy>("buildAndCollect") {

gradle.properties

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
org.gradle.jvmargs=-Xmx4G
22

3-
fabric_versions=1.21.1
3+
fabric_versions=1.20.1, 1.21.1
44
neoforge_versions=1.21.1
55

6-
mod_version=1.1.2
6+
mod_version=1.2.0
77
mod_group=com.bawnorton
88
mod_id=configurable
99
mod_name=Configurable
1010
mod_description=Config library that allows decentralised settings in a mod
1111

1212
modrinth_project_id=lGffrQ3O
13-
curseforge_project_id=1092048
14-
15-
yacl_version=3.5.0+1.21
13+
curseforge_project_id=1092048

src/main/java/com/bawnorton/configurable/ap/ConfigurableProcessor.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.lang.model.element.TypeElement;
2626
import javax.lang.model.util.Elements;
2727
import javax.lang.model.util.Types;
28+
import javax.tools.Diagnostic;
2829
import javax.tools.FileObject;
2930
import javax.tools.StandardLocation;
3031
import org.jetbrains.annotations.NotNull;
@@ -38,7 +39,11 @@
3839
import java.util.Set;
3940

4041
@SupportedAnnotationTypes("com.bawnorton.configurable.Configurable")
41-
@SupportedSourceVersion(SourceVersion.RELEASE_21)
42+
//? if >=1.21 {
43+
/*@SupportedSourceVersion(SourceVersion.RELEASE_21)
44+
*///?} else {
45+
@SupportedSourceVersion(SourceVersion.RELEASE_17)
46+
//?}
4247
public final class ConfigurableProcessor extends AbstractProcessor {
4348
private final Gson gson = new GsonBuilder()
4449
.setFieldNamingStrategy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
@@ -88,19 +93,19 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
8893
sourceSet = null;
8994
}
9095
} catch (IOException e) {
91-
messager.printError("Cannot determine source set");
96+
messager.printMessage(Diagnostic.Kind.ERROR, "Cannot determine source set");
9297
throw new RuntimeException(e);
9398
}
9499

95100
SourceProvider sourceProvider = SourceProviders.getSourceProvider(filer, buildPath);
96101
if(sourceProvider == null) {
97-
messager.printError("Cannot determine source provider");
102+
messager.printMessage(Diagnostic.Kind.ERROR,"Cannot determine source provider");
98103
throw new RuntimeException();
99104
}
100105

101106
String configName = sourceProvider.getName();
102107
ConfigurableSettings settings = generateSettings(sourceSet, configName, buildPath);
103-
messager.printNote("Found config name: \"%s\" for source set \"%s\"".formatted(settings.name(), settings.sourceSet()));
108+
messager.printMessage(Diagnostic.Kind.NOTE, "Found config name: \"%s\" for source set \"%s\"".formatted(settings.name(), settings.sourceSet()));
104109

105110
ConfigLoaderGenerator loaderGenerator = new ConfigLoaderGenerator(filer, types, messager, settings);
106111
ConfigGenerator configGenerator = new ConfigGenerator(filer, types, messager, settings);
@@ -115,7 +120,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
115120
screenFactoryGenerator.generateYaclScreenFactory(roots, configGenerator::getExternalReference);
116121
}
117122
} catch (IOException e) {
118-
messager.printError("Could not generate config classes");
123+
messager.printMessage(Diagnostic.Kind.ERROR,"Could not generate config classes");
119124
throw new RuntimeException(e);
120125
}
121126

@@ -166,7 +171,7 @@ private void generateSettingsFile(ConfigurableSettings settings, Path buildPath)
166171
out.write(gson.toJson(settings).getBytes());
167172
}
168173
} catch (IOException e) {
169-
messager.printError("Could not write settings file");
174+
messager.printMessage(Diagnostic.Kind.ERROR,"Could not write settings file");
170175
throw new RuntimeException(e);
171176
}
172177
}

src/main/java/com/bawnorton/configurable/ap/generator/ConfigGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.processing.Messager;
88
import javax.lang.model.element.Element;
99
import javax.lang.model.util.Types;
10+
import javax.tools.Diagnostic;
1011
import javax.tools.JavaFileObject;
1112
import java.io.IOException;
1213
import java.io.PrintWriter;
@@ -147,7 +148,7 @@ private void addClampedConstraint(ConfigurableHolder holder, Element element, St
147148
double min = holder.min();
148149
double max = holder.max();
149150
if (min > max) {
150-
messager.printError("min must be smaller than or equal to the max", element);
151+
messager.printMessage(Diagnostic.Kind.ERROR, "min must be smaller than or equal to the max", element);
151152
}
152153
constraintSet.append(".addClamped(%s, %s)".formatted(min, max));
153154
}

src/main/java/com/bawnorton/configurable/ap/generator/ConfigLoaderGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ private void parseNested(List<String> stack, JsonObject nestedJson, Config confi
9696
for(String key : keys) {
9797
JsonElement element = nestedJson.get(key);
9898
if(element.isJsonObject()) {
99-
stack.addLast(key);
99+
stack.add(key);
100100
parseNested(stack, element.getAsJsonObject(), config);
101-
stack.removeLast();
101+
stack.remove(stack.size() - 1);
102102
} else if (element.isJsonNull()) {
103103
parseReference(key, null, stack, config);
104104
} else if (element.isJsonPrimitive()) {

src/main/java/com/bawnorton/configurable/ap/generator/ConfigScreenFactoryGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.lang.model.type.DeclaredType;
1717
import javax.lang.model.util.Elements;
1818
import javax.lang.model.util.Types;
19+
import javax.tools.Diagnostic;
1920
import javax.tools.JavaFileObject;
2021
import org.jetbrains.annotations.NotNull;
2122
import java.io.IOException;
@@ -257,15 +258,15 @@ private YaclRoot createYaclImpl(List<ConfigurableElement> roots, Function<Config
257258
yield new YaclOptionController.Item();
258259
}
259260
}
260-
messager.printError("Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
261+
messager.printMessage(Diagnostic.Kind.ERROR, "Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
261262
throw new RuntimeException();
262263
}
263264
case ARRAY -> new YaclOptionController.CyclingList(
264265
formatter,
265266
externalRef
266267
);
267268
default -> {
268-
messager.printError("Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
269+
messager.printMessage(Diagnostic.Kind.ERROR, "Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
269270
throw new RuntimeException();
270271
}
271272
};

src/main/java/com/bawnorton/configurable/ap/tree/ConfigurableTree.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.lang.model.element.Element;
77
import javax.lang.model.element.Modifier;
88
import javax.lang.model.type.TypeKind;
9+
import javax.tools.Diagnostic;
910
import java.util.ArrayList;
1011
import java.util.Comparator;
1112
import java.util.HashSet;
@@ -98,25 +99,25 @@ private ConfigurableElement createConfigurableElement(Element element) {
9899
getAnnotationMirror(element, Configurable.class.getCanonicalName())
99100
);
100101
if (annotation == null) {
101-
messager.printError("Element \"%s\" does not have Configurable annotation".formatted(element.getSimpleName()), element);
102+
messager.printMessage(Diagnostic.Kind.ERROR, "Element \"%s\" does not have Configurable annotation".formatted(element.getSimpleName()), element);
102103
throw new RuntimeException();
103104
}
104105

105106
Set<Modifier> modifiers = element.getModifiers();
106107
if(element.getKind().isField()) {
107108
if(modifiers.contains(Modifier.FINAL)) {
108-
messager.printError("Configurable field \"%s\" cannot be final".formatted(element.getSimpleName()), element);
109+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" cannot be final".formatted(element.getSimpleName()), element);
109110
throw new RuntimeException();
110111
} else if (!modifiers.contains(Modifier.STATIC)) {
111-
messager.printError("Configurable field \"%s\" must be static".formatted(element.getSimpleName()), element);
112+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" must be static".formatted(element.getSimpleName()), element);
112113
throw new RuntimeException();
113114
} else if(annotation.yacl().collapsed()) {
114-
messager.printError("Configurable field \"%s\" cannot be collapsed, only classes allowed".formatted(element.getSimpleName()), element);
115+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" cannot be collapsed, only classes allowed".formatted(element.getSimpleName()), element);
115116
throw new RuntimeException();
116117
}
117118
} else if (element.getKind().isClass()) {
118119
if(modifiers.contains(Modifier.PRIVATE)) {
119-
messager.printError("Configurable class \"%s\" cannot be private".formatted(element.getSimpleName()), element);
120+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable class \"%s\" cannot be private".formatted(element.getSimpleName()), element);
120121
throw new RuntimeException();
121122
}
122123
}
@@ -129,7 +130,7 @@ private ConfigurableElement createConfigurableElement(Element element) {
129130
.toList();
130131

131132
if (element.getKind().isClass() && children.isEmpty()) {
132-
messager.printError("Configurable class \"%s\" must have at least one Configurable field or class".formatted(element.getSimpleName()), element);
133+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable class \"%s\" must have at least one Configurable field or class".formatted(element.getSimpleName()), element);
133134
throw new RuntimeException();
134135
}
135136

@@ -144,7 +145,7 @@ private ConfigurableElement createConfigurableElement(Element element) {
144145
.equals("org.spongepowered.asm.mixin.Mixin"))
145146
.findFirst()
146147
.ifPresent(mirror -> {
147-
messager.printError("Configurable element \"%s\" must be outside a mixin class".formatted(element.getSimpleName()), element);
148+
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable element \"%s\" must be outside a mixin class".formatted(element.getSimpleName()), element);
148149
throw new RuntimeException();
149150
});
150151
}

src/main/java/com/bawnorton/configurable/ap/yacl/YaclDescriptionImage.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ protected String getSpec(int depth) {
3030
if(customOwner != null && customMethod != null) {
3131
return "customImage(%s)".formatted(getCustomImageSpec());
3232
}
33+
//? if >=1.21 {
34+
/*String id = "Identifier.of(\"%s\")".formatted(image.value());
35+
*///?} else {
36+
String id = "new Identifier(\"%s\")".formatted(image.value());
37+
//?}
3338
return switch (image.type()) {
3439
case RESOURCE -> {
3540
if(!image.path().isEmpty()) {
36-
yield "image(Path.of(\"%s\"), Identifier.of(\"%s\"))".formatted(
41+
yield "image(Path.of(\"%s\"), %s)".formatted(
3742
image.path(),
38-
image.value()
43+
id
3944
);
4045
}
4146

4247
int textureWidth = image.textureWidth() == 0 ? image.width() : image.textureWidth();
4348
int textureHeight = image.textureHeight() == 0 ? image.height() : image.textureHeight();
4449

45-
yield "image(Identifier.of(\"%s\"), %sF, %sF, %s, %s, %s, %s)".formatted(
46-
image.value(),
50+
yield "image(%s, %sF, %sF, %s, %s, %s, %s)".formatted(
51+
id,
4752
image.u(),
4853
image.v(),
4954
image.width(),
@@ -54,13 +59,13 @@ protected String getSpec(int depth) {
5459
}
5560
case WEBP -> {
5661
if(!image.path().isEmpty()) {
57-
yield "webpImage(Path.of(\"%s\"), Identifier.of(\"%s\"))".formatted(
62+
yield "webpImage(Path.of(\"%s\"), %s)".formatted(
5863
image.path(),
59-
image.value()
64+
id
6065
);
6166
}
6267

63-
yield "webpImage(Identifier.of(\"%s\"))".formatted(image.value());
68+
yield "webpImage(%s)".formatted(id);
6469
}
6570
};
6671
}

src/main/java/com/bawnorton/configurable/client/mixin/ModMenuMixin.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020

2121
@Mixin(value = ModMenu.class, remap = false)
2222
public abstract class ModMenuMixin {
23-
@Shadow @Final private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
23+
//? if >=1.21 {
24+
/*@Shadow @Final private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
2425
2526
@Shadow @Final private static List<ModMenuApi> apiImplementations;
27+
*///?} else {
28+
@Shadow private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
29+
30+
@Shadow private static List<Map<String, ConfigScreenFactory<?>>> delayedScreenFactoryProviders;
31+
//?}
32+
2633

2734
@Inject(
2835
method = "onInitializeClient",
@@ -49,7 +56,11 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
4956

5057
ModMenuApi api = apiGetter.apply(wrapper);
5158
configScreenFactories.put(name, api.getModConfigScreenFactory());
52-
apiImplementations.add(api);
59+
//? if >=1.21 {
60+
/*apiImplementations.add(api);
61+
*///?} else {
62+
delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories());
63+
//?}
5364
}));
5465
}
5566
}

0 commit comments

Comments
 (0)