Skip to content

Commit

Permalink
backport to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed Sep 21, 2024
1 parent 3f1b19b commit 60b4f59
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.0

- Backport to 1.20.1

# 1.1.2
- Fix YACL bindings incorrectly using the current value as the default

Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ loom {

tasks {
withType<JavaCompile> {
options.release = 21
options.release = minecraftVersion.javaVersion()
}

withType<RemapJarTask> {
Expand Down Expand Up @@ -84,8 +84,8 @@ tasks {
java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.toVersion(minecraftVersion.javaVersion())
targetCompatibility = JavaVersion.toVersion(minecraftVersion.javaVersion())
}

val buildAndCollect = tasks.register<Copy>("buildAndCollect") {
Expand Down
8 changes: 3 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
org.gradle.jvmargs=-Xmx4G

fabric_versions=1.21.1
fabric_versions=1.20.1, 1.21.1
neoforge_versions=1.21.1

mod_version=1.1.2
mod_version=1.2.0
mod_group=com.bawnorton
mod_id=configurable
mod_name=Configurable
mod_description=Config library that allows decentralised settings in a mod

modrinth_project_id=lGffrQ3O
curseforge_project_id=1092048

yacl_version=3.5.0+1.21
curseforge_project_id=1092048
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -38,7 +39,11 @@
import java.util.Set;

@SupportedAnnotationTypes("com.bawnorton.configurable.Configurable")
@SupportedSourceVersion(SourceVersion.RELEASE_21)
//? if >=1.21 {
/*@SupportedSourceVersion(SourceVersion.RELEASE_21)
*///?} else {
@SupportedSourceVersion(SourceVersion.RELEASE_17)
//?}
public final class ConfigurableProcessor extends AbstractProcessor {
private final Gson gson = new GsonBuilder()
.setFieldNamingStrategy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
Expand Down Expand Up @@ -88,19 +93,19 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
sourceSet = null;
}
} catch (IOException e) {
messager.printError("Cannot determine source set");
messager.printMessage(Diagnostic.Kind.ERROR, "Cannot determine source set");
throw new RuntimeException(e);
}

SourceProvider sourceProvider = SourceProviders.getSourceProvider(filer, buildPath);
if(sourceProvider == null) {
messager.printError("Cannot determine source provider");
messager.printMessage(Diagnostic.Kind.ERROR,"Cannot determine source provider");
throw new RuntimeException();
}

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

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

Expand Down Expand Up @@ -166,7 +171,7 @@ private void generateSettingsFile(ConfigurableSettings settings, Path buildPath)
out.write(gson.toJson(settings).getBytes());
}
} catch (IOException e) {
messager.printError("Could not write settings file");
messager.printMessage(Diagnostic.Kind.ERROR,"Could not write settings file");
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -147,7 +148,7 @@ private void addClampedConstraint(ConfigurableHolder holder, Element element, St
double min = holder.min();
double max = holder.max();
if (min > max) {
messager.printError("min must be smaller than or equal to the max", element);
messager.printMessage(Diagnostic.Kind.ERROR, "min must be smaller than or equal to the max", element);
}
constraintSet.append(".addClamped(%s, %s)".formatted(min, max));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ private void parseNested(List<String> stack, JsonObject nestedJson, Config confi
for(String key : keys) {
JsonElement element = nestedJson.get(key);
if(element.isJsonObject()) {
stack.addLast(key);
stack.add(key);
parseNested(stack, element.getAsJsonObject(), config);
stack.removeLast();
stack.remove(stack.size() - 1);
} else if (element.isJsonNull()) {
parseReference(key, null, stack, config);
} else if (element.isJsonPrimitive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.lang.model.type.DeclaredType;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
Expand Down Expand Up @@ -257,15 +258,15 @@ private YaclRoot createYaclImpl(List<ConfigurableElement> roots, Function<Config
yield new YaclOptionController.Item();
}
}
messager.printError("Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
messager.printMessage(Diagnostic.Kind.ERROR, "Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
throw new RuntimeException();
}
case ARRAY -> new YaclOptionController.CyclingList(
formatter,
externalRef
);
default -> {
messager.printError("Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
messager.printMessage(Diagnostic.Kind.ERROR, "Could not automatically create controller for type: %s".formatted(entry.getFullyQualifiedTypeName(types)), entry.element());
throw new RuntimeException();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import javax.lang.model.type.TypeKind;
import javax.tools.Diagnostic;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
Expand Down Expand Up @@ -98,25 +99,25 @@ private ConfigurableElement createConfigurableElement(Element element) {
getAnnotationMirror(element, Configurable.class.getCanonicalName())
);
if (annotation == null) {
messager.printError("Element \"%s\" does not have Configurable annotation".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Element \"%s\" does not have Configurable annotation".formatted(element.getSimpleName()), element);
throw new RuntimeException();
}

Set<Modifier> modifiers = element.getModifiers();
if(element.getKind().isField()) {
if(modifiers.contains(Modifier.FINAL)) {
messager.printError("Configurable field \"%s\" cannot be final".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" cannot be final".formatted(element.getSimpleName()), element);
throw new RuntimeException();
} else if (!modifiers.contains(Modifier.STATIC)) {
messager.printError("Configurable field \"%s\" must be static".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" must be static".formatted(element.getSimpleName()), element);
throw new RuntimeException();
} else if(annotation.yacl().collapsed()) {
messager.printError("Configurable field \"%s\" cannot be collapsed, only classes allowed".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable field \"%s\" cannot be collapsed, only classes allowed".formatted(element.getSimpleName()), element);
throw new RuntimeException();
}
} else if (element.getKind().isClass()) {
if(modifiers.contains(Modifier.PRIVATE)) {
messager.printError("Configurable class \"%s\" cannot be private".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable class \"%s\" cannot be private".formatted(element.getSimpleName()), element);
throw new RuntimeException();
}
}
Expand All @@ -129,7 +130,7 @@ private ConfigurableElement createConfigurableElement(Element element) {
.toList();

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

Expand All @@ -144,7 +145,7 @@ private ConfigurableElement createConfigurableElement(Element element) {
.equals("org.spongepowered.asm.mixin.Mixin"))
.findFirst()
.ifPresent(mirror -> {
messager.printError("Configurable element \"%s\" must be outside a mixin class".formatted(element.getSimpleName()), element);
messager.printMessage(Diagnostic.Kind.ERROR, "Configurable element \"%s\" must be outside a mixin class".formatted(element.getSimpleName()), element);
throw new RuntimeException();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@ protected String getSpec(int depth) {
if(customOwner != null && customMethod != null) {
return "customImage(%s)".formatted(getCustomImageSpec());
}
//? if >=1.21 {
/*String id = "Identifier.of(\"%s\")".formatted(image.value());
*///?} else {
String id = "new Identifier(\"%s\")".formatted(image.value());
//?}
return switch (image.type()) {
case RESOURCE -> {
if(!image.path().isEmpty()) {
yield "image(Path.of(\"%s\"), Identifier.of(\"%s\"))".formatted(
yield "image(Path.of(\"%s\"), %s)".formatted(
image.path(),
image.value()
id
);
}

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

yield "image(Identifier.of(\"%s\"), %sF, %sF, %s, %s, %s, %s)".formatted(
image.value(),
yield "image(%s, %sF, %sF, %s, %s, %s, %s)".formatted(
id,
image.u(),
image.v(),
image.width(),
Expand All @@ -54,13 +59,13 @@ protected String getSpec(int depth) {
}
case WEBP -> {
if(!image.path().isEmpty()) {
yield "webpImage(Path.of(\"%s\"), Identifier.of(\"%s\"))".formatted(
yield "webpImage(Path.of(\"%s\"), %s)".formatted(
image.path(),
image.value()
id
);
}

yield "webpImage(Identifier.of(\"%s\"))".formatted(image.value());
yield "webpImage(%s)".formatted(id);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@

@Mixin(value = ModMenu.class, remap = false)
public abstract class ModMenuMixin {
@Shadow @Final private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
//? if >=1.21 {
/*@Shadow @Final private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
@Shadow @Final private static List<ModMenuApi> apiImplementations;
*///?} else {
@Shadow private static Map<String, ConfigScreenFactory<?>> configScreenFactories;

@Shadow private static List<Map<String, ConfigScreenFactory<?>>> delayedScreenFactoryProviders;
//?}


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

ModMenuApi api = apiGetter.apply(wrapper);
configScreenFactories.put(name, api.getModConfigScreenFactory());
apiImplementations.add(api);
//? if >=1.21 {
/*apiImplementations.add(api);
*///?} else {
delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories());
//?}
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public class ItemTypeAdapter implements JsonSerializer<Item>, JsonDeserializer<I
public Item deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
String itemName = json.getAsString();
return Registries.ITEM.getOrEmpty(Identifier.of(itemName)).orElse(Items.AIR);
//? if <1.21 {
Identifier id = new Identifier(itemName);
//?} else {
/*Identifier id = Identifier.of(itemName);
*///?}
return Registries.ITEM.getOrEmpty(id).orElse(Items.AIR);
} catch (Exception e) {
ConfigurableMain.LOGGER.warn("Failed to parse item from json: \"%s\"".formatted(json));
return Items.AIR;
Expand All @@ -30,4 +35,4 @@ public Item deserialize(JsonElement json, Type typeOfT, JsonDeserializationConte
public JsonElement serialize(Item src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(Registries.ITEM.getId(src).toString());
}
}
}
1 change: 0 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"depends": {
"fabricloader": ">=0.15.0",
"minecraft": "${minecraft_dependency}",
"java": ">=21",
"fabric-api": "*"
},
"custom": {
Expand Down
2 changes: 1 addition & 1 deletion stonecutter.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("dev.kikugie.stonecutter")
}
stonecutter active "1.21.1-fabric-yarn" /* [SC] DO NOT EDIT */
stonecutter active "1.20.1-fabric-yarn" /* [SC] DO NOT EDIT */

stonecutter registerChiseled tasks.register("chiseledBuildAndCollect", stonecutter.chiseled) {
group = "project"
Expand Down
10 changes: 10 additions & 0 deletions versions/1.20.1-fabric-mojmap/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
loom.platform=fabric
mappings=mojmap

yarn_build=10
fabric_loader=0.16.2
minecraft_dependency=>=1.20.1
supported_versions=1.20.1

modmenu=7.2.2
yacl_version=3.5.0+1.20.1
10 changes: 10 additions & 0 deletions versions/1.20.1-fabric-yarn/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
loom.platform=fabric
mappings=yarn

yarn_build=10
fabric_loader=0.16.2
minecraft_dependency=>=1.20.1
supported_versions=1.20.1

modmenu=7.2.2
yacl_version=3.5.0+1.20.1
3 changes: 2 additions & 1 deletion versions/1.21.1-fabric-mojmap/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ fabric_loader=0.16.2
minecraft_dependency=>=1.21
supported_versions=1.21, 1.21.1

modmenu=11.0.2
modmenu=11.0.2
yacl_version=3.5.0+1.21
3 changes: 2 additions & 1 deletion versions/1.21.1-fabric-yarn/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ fabric_loader=0.16.2
minecraft_dependency=>=1.21
supported_versions=1.21, 1.21.1

modmenu=11.0.2
modmenu=11.0.2
yacl_version=3.5.0+1.21
4 changes: 3 additions & 1 deletion versions/1.21.1-neoforge-mojmap/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ mappings=mojmap
yarn_build=3
neoforge_loader=21.1.31
minecraft_dependency=>=1.21
supported_versions=1.21, 1.21.1
supported_versions=1.21, 1.21.1

yacl_version=3.5.0+1.21
Loading

0 comments on commit 60b4f59

Please sign in to comment.