Skip to content

Commit

Permalink
Implement support for split datagen (MC 1.21.4+)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Nov 24, 2024
1 parent 703cf83 commit 66bff83
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/java/net/neoforged/moddevgradle/dsl/RunModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,21 @@ public void client() {
getType().set("client");
}

/**
* Equivalent to setting {@code type = "clientData"}.
*
* <p>Should only be used for Minecraft versions starting from 1.21.4.
* (The first snapshot that supports this is 24w45a).
*/
public void clientData() {
getType().set("clientData");
}

/**
* Equivalent to setting {@code type = "data"}.
*
* <p>Should only be used for Minecraft versions up to 1.21.3 included.
* (The last snapshot that supports this is 24w44a).
*/
public void data() {
getType().set("data");
Expand All @@ -170,6 +183,16 @@ public void server() {
getType().set("server");
}

/**
* Equivalent to setting {@code type = "serverData"}.
*
* <p>Should only be used for Minecraft versions starting from 1.21.4.
* (The first snapshot that supports this is 24w45a).
*/
public void serverData() {
getType().set("serverData");
}

/**
* Equivalent to setting {@code ideName = ""}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
spec.shouldResolveConsistentlyWith(runtimeClasspathConfig.get());
spec.attributes(attributes -> {
attributes.attributeProvider(MinecraftDistribution.ATTRIBUTE, type.map(t -> {
var name = t.equals("client") || t.equals("data") ? MinecraftDistribution.CLIENT : MinecraftDistribution.SERVER;
var name = t.equals("client") || t.equals("data") || t.equals("clientData") ? MinecraftDistribution.CLIENT : MinecraftDistribution.SERVER;
return project.getObjects().named(MinecraftDistribution.class, name);
}));
setNamedAttribute(project, attributes, Usage.USAGE_ATTRIBUTE, Usage.JAVA_RUNTIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ private UserDevConfig getSimulatedUserDevConfigForVanilla() {
"server", new UserDevRunType(
true, "net.minecraft.server.Main", commonArgs, List.of(), false, true, false, false, Map.of(), Map.of()
),
// TODO: find a way to check for Minecraft version?
"data", new UserDevRunType(
true, "net.minecraft.data.Main", commonArgs, List.of(), false, false, true, false, Map.of(), Map.of()
),
"clientData", new UserDevRunType(
true, "net.minecraft.client.data.Main", commonArgs, List.of(), false, false, true, false, Map.of(), Map.of()
),
"serverData", new UserDevRunType(
true, "net.minecraft.data.Main", commonArgs, List.of(), false, false, true, false, Map.of(), Map.of()
)
));
}
Expand Down

0 comments on commit 66bff83

Please sign in to comment.