From 1fae124089bf5067a2386c7f275e226814195a25 Mon Sep 17 00:00:00 2001 From: Space Walker Date: Fri, 13 Dec 2024 12:23:51 +0100 Subject: [PATCH] only merge jars if remapping occurred --- .../AbstractMappedMinecraftProvider.java | 19 +++++++++++++++++- .../mapped/IntermediaryMinecraftProvider.java | 20 ++++++++++++------- .../mapped/NamedMinecraftProvider.java | 20 ++++++++++++------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java index e55c9928d..49b85b63d 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java @@ -85,7 +85,7 @@ public List 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); @@ -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 = getRemappedJars(); + final List 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, List minecraftJars) { + return !areOutputsValid(remappedJars) || context.refreshOutputs() || !hasBackupJars(minecraftJars); + } + private boolean areOutputsValid(List remappedJars) { for (RemappedJars remappedJar : remappedJars) { if (!getMavenHelper(remappedJar.type()).exists(null)) { diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java index 74c70c2e9..f1fe3f6b9 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java @@ -80,18 +80,24 @@ public LegacyMergedImpl(Project project, LegacyMergedMinecraftProvider minecraft public List provide(ProvideContext context) throws Exception { final List 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); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java index 4cb1b9db4..39e589377 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java @@ -87,18 +87,24 @@ public List provide(ProvideContext context) throws Exception { final ProvideContext childContext = context.withApplyDependencies(false); final List 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); }