Skip to content

Commit

Permalink
only merge jars if remapping occurred
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Dec 13, 2024
1 parent da01aec commit 1fae124
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public List<MinecraftJar> provide(ProvideContext context) throws Exception {
throw new IllegalStateException("No remapped jars provided");
}

if (!areOutputsValid(remappedJars) || context.refreshOutputs() || !hasBackupJars(minecraftJars)) {
if (shouldRemapInputs(context, remappedJars, minecraftJars)) {
try {
remapInputs(remappedJars, context.configContext());
createBackupJars(minecraftJars);
Expand Down Expand Up @@ -193,6 +193,23 @@ protected String getDependencyNotation(MinecraftJar.Type type) {
return "net.minecraft:%s:%s".formatted(getName(type), getVersion());
}

protected boolean shouldRemapInputs(ProvideContext context) {
final List<RemappedJars> remappedJars = getRemappedJars();
final List<MinecraftJar> minecraftJars = remappedJars.stream()
.map(RemappedJars::outputJar)
.toList();

if (remappedJars.isEmpty()) {
throw new IllegalStateException("No remapped jars provided");
}

return shouldRemapInputs(context, remappedJars, minecraftJars);
}

private boolean shouldRemapInputs(ProvideContext context, List<RemappedJars> remappedJars, List<MinecraftJar> minecraftJars) {
return !areOutputsValid(remappedJars) || context.refreshOutputs() || !hasBackupJars(minecraftJars);
}

private boolean areOutputsValid(List<RemappedJars> remappedJars) {
for (RemappedJars remappedJar : remappedJars) {
if (!getMavenHelper(remappedJar.type()).exists(null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,24 @@ public LegacyMergedImpl(Project project, LegacyMergedMinecraftProvider minecraft
public List<MinecraftJar> provide(ProvideContext context) throws Exception {
final List<MinecraftJar> minecraftJars = List.of(getMergedJar());

// this check must be done before the client and server impls are provided
// because the merging only needs to happen if the remapping step is run
final boolean mergeJars = client.shouldRemapInputs(context) || server.shouldRemapInputs(context);

// Map the client and server jars separately
server.provide(context);
client.provide(context);

// then merge them
MergedMinecraftProvider.mergeJars(
client.getEnvOnlyJar().toFile(),
server.getEnvOnlyJar().toFile(),
getMergedJar().toFile()
);
if (mergeJars) {
// then merge them
MergedMinecraftProvider.mergeJars(
client.getEnvOnlyJar().toFile(),
server.getEnvOnlyJar().toFile(),
getMergedJar().toFile()
);
}

if (!hasBackupJars(minecraftJars)) {
if (mergeJars || !hasBackupJars(minecraftJars)) {
createBackupJars(minecraftJars);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,24 @@ public List<MinecraftJar> provide(ProvideContext context) throws Exception {
final ProvideContext childContext = context.withApplyDependencies(false);
final List<MinecraftJar> minecraftJars = List.of(getMergedJar());

// this check must be done before the client and server impls are provided
// because the merging only needs to happen if the remapping step is run
final boolean mergeJars = client.shouldRemapInputs(childContext) || server.shouldRemapInputs(childContext);

// Map the client and server jars separately
server.provide(childContext);
client.provide(childContext);

// then merge them
MergedMinecraftProvider.mergeJars(
client.getEnvOnlyJar().toFile(),
server.getEnvOnlyJar().toFile(),
getMergedJar().toFile()
);
if (mergeJars) {
// then merge them
MergedMinecraftProvider.mergeJars(
client.getEnvOnlyJar().toFile(),
server.getEnvOnlyJar().toFile(),
getMergedJar().toFile()
);
}

if (!hasBackupJars(minecraftJars)) {
if (mergeJars || !hasBackupJars(minecraftJars)) {
createBackupJars(minecraftJars);
}

Expand Down

0 comments on commit 1fae124

Please sign in to comment.