Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate mixin confs in non-main source sets. Add forge source set #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ mcGitVersion {
setCommitVersion("570c0cbf0cdc15b8348a862a519d3399a943af9", "0.0")
}

//sourceSets {
sourceSets {
forge {
compileClasspath = sourceSets.main.compileClasspath
runtimeClasspath = sourceSets.main.runtimeClasspath
}
// create("gametest") {
// compileClasspath += configurations.compileClasspath
// compileClasspath += configurations.testCompileClasspath
Expand All @@ -43,7 +47,7 @@ mcGitVersion {
// runtimeClasspath += configurations.testRuntimeClasspath
// runtimeClasspath += sourceSets.main.output
// }
//}
}

tasks.register("generatePackageInfo") {
group = "filegen"
Expand All @@ -67,12 +71,30 @@ mixinGen {
defaultCompatibilityLevel = "JAVA_17"
defaultMinVersion = "0.8"

config("core") {
config(sourceSets.main, "core") {
it.required = true
it.conformVisibility = true
it.injectorsDefaultRequire = 1
it.configurationPlugin = "io.github.opencubicchunks.cubicchunks.mixin.ASMConfigPlugin"
}
config(sourceSets.main, "access") {
it.required = true
it.conformVisibility = true
it.injectorsDefaultRequire = 1
}

config(sourceSets.forge, "forge") {
it.required = true
it.conformVisibility = true
it.injectorsDefaultRequire = 1
it.configurationPlugin = "io.github.opencubicchunks.cubicchunks.mixin.ASMConfigPlugin"
}

config(sourceSets.test, "test") {
it.required = true
it.conformVisibility = true
it.injectorsDefaultRequire = 1
}
/*
config("levelgen") {
required = true
Expand Down Expand Up @@ -163,7 +185,7 @@ runs {
jvmArguments args
// systemProperty 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
modSource project.sourceSets.forge
dependencies {
runtime project.configurations.libraries
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Note: this intentionally only contains the parts that I actually use
@SuppressWarnings("unused") public class MixinGenExtension {

private final Map<String, Action<MixinConfig>> configs = new HashMap<>();
private final Map<SourceSet, Map<String, Action<MixinConfig>>> configsBySourceSet = new HashMap<>();

private String filePattern = "mixin.%s.json";
private String defaultRefmap = "mixin.refmap.json";
Expand Down Expand Up @@ -80,8 +80,8 @@ public void setDefaultMinVersion(String defaultMinVersion) {
this.defaultMinVersion = defaultMinVersion;
}

public void config(String name, Action<MixinConfig> configure) {
configs.put(name, configure);
public void config(SourceSet sourceSet, String name, Action<MixinConfig> configure) {
configsBySourceSet.computeIfAbsent(sourceSet, s -> new HashMap<>()).put(name, configure);
}

public static class MixinConfig {
Expand Down Expand Up @@ -171,72 +171,84 @@ public void setMixinPriority(Integer mixinPriority) {
}

void generateFiles(JavaPluginConvention convention) throws IOException {
SourceSet main = convention.getSourceSets().getByName("main");
Set<File> resourcesSet = main.getResources().getSrcDirs();
Path resources = resourcesSet.iterator().next().getCanonicalFile().toPath();
for (String name : configs.keySet()) {
MixinConfig config = new MixinConfig();
Action<MixinConfig> configure = configs.get(name);
if (defaultPackagePrefix != null) {
config.packageName = defaultPackagePrefix + "." + name;
convention.getSourceSets().forEach(sourceSet -> {
Map<String, Action<MixinConfig>> configs = configsBySourceSet.get(sourceSet);
if (configs == null) {
throw new RuntimeException("No mixin config was registered for source set " + sourceSet);
}
if (defaultRefmap != null) {
config.refmap = defaultRefmap;
}
if (defaultCompatibilityLevel != null) {
config.compatibilityLevel = defaultCompatibilityLevel;
}
if (defaultMinVersion != null) {
config.minVersion = defaultMinVersion;
}
configure.execute(config);

String fileName = String.format(filePattern, name);

try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(resources.resolve(fileName)))) {
writer.setIndent(" ");
writer.beginObject();
if (config.required != null) {
writer.name("required").value(config.required);
}
if (config.packageName != null) {
writer.name("package").value(config.packageName);
}
if (config.refmap != null) {
writer.name("refmap").value(config.refmap);
}
if (config.configurationPlugin != null) {
writer.name("plugin").value(config.configurationPlugin);
}
if (config.compatibilityLevel != null) {
writer.name("compatibilityLevel").value(config.compatibilityLevel);
Set<File> resourcesSet = sourceSet.getResources().getSrcDirs();
Path resources;
try {
resources = resourcesSet.iterator().next().getCanonicalFile().toPath();
} catch (IOException e) {
throw new RuntimeException(e);
}
for (String name : configs.keySet()) {
MixinConfig config = new MixinConfig();
Action<MixinConfig> configure = configs.get(name);
if (defaultPackagePrefix != null) {
config.packageName = defaultPackagePrefix + "." + name;
}
if (config.minVersion != null) {
writer.name("minVersion").value(config.minVersion);
if (defaultRefmap != null) {
config.refmap = defaultRefmap;
}
if (config.mixinPriority != null) {
writer.name("mixinPriority").value(config.mixinPriority);
if (defaultCompatibilityLevel != null) {
config.compatibilityLevel = defaultCompatibilityLevel;
}
if (config.injectorsDefaultRequire != null) {
writer.name("injectors").beginObject();
writer.name("defaultRequire").value(config.injectorsDefaultRequire);
writer.endObject();
if (defaultMinVersion != null) {
config.minVersion = defaultMinVersion;
}
if (config.conformVisibility != null) {
writer.name("overwrites").beginObject();
writer.name("conformVisibility").value(config.conformVisibility);
configure.execute(config);

String fileName = String.format(filePattern, name);

try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(resources.resolve(fileName)))) {
writer.setIndent(" ");
writer.beginObject();
if (config.required != null) {
writer.name("required").value(config.required);
}
if (config.packageName != null) {
writer.name("package").value(config.packageName);
}
if (config.refmap != null) {
writer.name("refmap").value(config.refmap);
}
if (config.configurationPlugin != null) {
writer.name("plugin").value(config.configurationPlugin);
}
if (config.compatibilityLevel != null) {
writer.name("compatibilityLevel").value(config.compatibilityLevel);
}
if (config.minVersion != null) {
writer.name("minVersion").value(config.minVersion);
}
if (config.mixinPriority != null) {
writer.name("mixinPriority").value(config.mixinPriority);
}
if (config.injectorsDefaultRequire != null) {
writer.name("injectors").beginObject();
writer.name("defaultRequire").value(config.injectorsDefaultRequire);
writer.endObject();
}
if (config.conformVisibility != null) {
writer.name("overwrites").beginObject();
writer.name("conformVisibility").value(config.conformVisibility);
writer.endObject();
}
writeMixins(convention, sourceSet, name, config, writer);

writer.endObject();
} catch (IOException e) {
throw new RuntimeException(e);
}
writeMixins(convention, name, config, writer);

writer.endObject();
}
}

});
}

private void writeMixins(JavaPluginConvention convention, String name, MixinConfig config, JsonWriter writer) throws IOException {
Set<Path> classes = getMixinClasses(config, convention.getSourceSets().getByName("main").getAllJava());
private void writeMixins(JavaPluginConvention convention, SourceSet sourceSet, String name, MixinConfig config, JsonWriter writer) throws IOException {
Set<Path> classes = getMixinClasses(config, sourceSet.getAllJava());

Set<Path> commonSet = new HashSet<>();
Set<Path> clientSet = new HashSet<>();
Expand Down
17 changes: 17 additions & 0 deletions src/forge/resources/cubicchunks.mixins.forge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"required": true,
"package": "io.github.opencubicchunks.cubicchunks.mixin.forge",
"refmap": "CubicChunks-refmap.json",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"conformVisibility": true
},
"mixins": [
],
"client": [],
"server": []
}
1 change: 1 addition & 0 deletions src/main/resources/cubicchunks.mixins.access.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"conformVisibility": true
},
"mixins": [
"common.DistanceManagerAccess",
"common.TicketTypeAccess"
],
"client": [],
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/cubicchunks.mixins.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"mixins": [
"common.client.multiplayer.MixinClientLevel",
"common.server.MixinMinecraftServer",
"common.server.level.MixinChunkTaskPriorityQueue",
"common.server.level.MixinChunkTaskPriorityQueueSorter",
"common.server.level.MixinChunkTicketTracker",
Expand All @@ -24,17 +25,17 @@
"common.server.level.MixinServerLevel",
"common.server.level.MixinServerPlayer",
"common.server.level.MixinTickingTracker",
"common.server.MixinMinecraftServer",
"common.world.level.MixinLevel",
"common.world.level.MixinLevelReader",
"common.world.level.chunk.MixinChunkAccess",
"common.world.level.chunk.MixinChunkSource",
"common.world.level.chunk.MixinImposterProtoChunk",
"common.world.level.chunk.MixinLevelChunk",
"common.world.level.cube.MixinCubeAccess",
"common.world.level.cube.MixinImposterProtoCube",
"common.world.level.cube.MixinLevelCube",
"common.world.level.cube.MixinLevelCube$BoundTickingBlockEntity",
"common.world.level.cube.MixinLevelCube$RebindableTickingBlockEntityWrapper",
"common.world.level.chunk.MixinChunkSource",
"common.world.level.MixinLevel",
"common.world.level.MixinLevelReader",
"common.world.level.cube.MixinProtoCube"
],
"client": [],
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/cubicchunks.mixins.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"required": true,
"package": "io.github.opencubicchunks.cubicchunks.mixin.test",
"refmap": "CubicChunks-refmap.json",
"plugin": "io.github.opencubicchunks.cubicchunks.mixin.ASMConfigPlugin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"injectors": {
Expand Down
Loading