Fix MojangMappingsSpec having the same hash version for each mc version.

I dont think this would be a real cause for concern as the jar would have had the mc version in it anyway.
dev/0.11
modmuss50 2021-07-21 22:29:23 +01:00
parent d32acb3370
commit 61fa4d9fb6
7 changed files with 57 additions and 13 deletions

View File

@ -75,9 +75,7 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
JarProcessorManager getJarProcessorManager();
default MinecraftProviderImpl getMinecraftProvider() {
return getDependencyManager().getProvider(MinecraftProviderImpl.class);
}
MinecraftProviderImpl getMinecraftProvider();
default MappingsProviderImpl getMappingsProvider() {
return getDependencyManager().getProvider(MappingsProviderImpl.class);

View File

@ -30,15 +30,21 @@ import java.util.List;
import org.gradle.api.Action;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec;
import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec;
import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpecBuilder;
public class LayeredMappingSpecBuilder {
private final List<MappingsSpec<?>> layers = new LinkedList<>();
private final MinecraftProvider minecraftProvider;
public LayeredMappingSpecBuilder(MinecraftProvider minecraftProvider) {
this.minecraftProvider = minecraftProvider;
}
public LayeredMappingSpecBuilder officialMojangMappings() {
layers.add(new MojangMappingsSpec());
layers.add(new MojangMappingsSpec(minecraftProvider.minecraftVersion()));
return this;
}

View File

@ -28,7 +28,7 @@ import net.fabricmc.loom.configuration.providers.mappings.MappingContext;
import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta;
public record MojangMappingsSpec() implements MappingsSpec<MojangMappingLayer> {
public record MojangMappingsSpec(String minecraftVersion) implements MappingsSpec<MojangMappingLayer> {
// Keys in dependency manifest
private static final String MANIFEST_CLIENT_MAPPINGS = "client_mappings";
private static final String MANIFEST_SERVER_MAPPINGS = "server_mappings";

View File

@ -36,11 +36,12 @@ import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.BasePluginConvention;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
import net.fabricmc.loom.api.MixinApExtensionAPI;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder;
@ -113,7 +114,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
@Override
public Dependency layered(Action<LayeredMappingSpecBuilder> action) {
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder();
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(getMinecraftProvider());
action.execute(builder);
LayeredMappingSpec builtSpec = builder.build();
return new LayeredMappingsDependency(new GradleMappingContext(getProject(), "layers_" + builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion());
@ -182,6 +183,8 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected abstract MixinApExtension getMixinApExtension();
protected abstract MinecraftProvider getMinecraftProvider();
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends LoomGradleExtensionApiImpl {
private EnsureCompile() {
@ -203,5 +206,10 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected MixinApExtension getMixinApExtension() {
throw new RuntimeException("Yeah... something is really wrong");
}
@Override
protected MinecraftProvider getMinecraftProvider() {
throw new RuntimeException("Yeah... something is really wrong");
}
}
}

View File

@ -44,6 +44,7 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.InstallerData;
import net.fabricmc.loom.configuration.LoomDependencyManager;
import net.fabricmc.loom.configuration.processors.JarProcessorManager;
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implements LoomGradleExtension {
private final Project project;
@ -110,6 +111,11 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
return Objects.requireNonNull(jarProcessorManager, "Cannot get JarProcessorManager before it has been setup");
}
@Override
public MinecraftProviderImpl getMinecraftProvider() {
return getDependencyManager().getProvider(MinecraftProviderImpl.class);
}
@Override
public MappingSet getOrCreateSrcMappingCache(int id, Supplier<MappingSet> factory) {
return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get());

View File

@ -24,6 +24,7 @@
package net.fabricmc.loom.test.unit.layeredmappings
import net.fabricmc.loom.configuration.providers.MinecraftProvider
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder
import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec
@ -34,20 +35,41 @@ import org.gradle.util.ConfigureUtil
import spock.lang.Specification
class LayeredMappingSpecBuilderTest extends Specification {
MinecraftProvider mockMinecraftProvider = Mock(MinecraftProvider)
def "simple mojmap" () {
setup:
mockMinecraftProvider.minecraftVersion() >> "1.17"
when:
def spec = layered() {
officialMojangMappings()
}
def layers = spec.layers()
then:
spec.version == "layered+hash.961"
spec.version == "layered+hash.1506500"
layers.size() == 2
layers[0].class == IntermediaryMappingsSpec
layers[1].class == MojangMappingsSpec
}
def "simple mojmap alternative version" () {
setup:
mockMinecraftProvider.minecraftVersion() >> "1.17.1"
when:
def spec = layered() {
officialMojangMappings()
}
def layers = spec.layers()
then:
spec.version == "layered+hash.1446825415"
layers.size() == 2
layers[0].class == IntermediaryMappingsSpec
layers[1].class == MojangMappingsSpec
}
def "simple mojmap with parchment" () {
setup:
mockMinecraftProvider.minecraftVersion() >> "1.17"
when:
def spec = layered() {
officialMojangMappings()
@ -56,7 +78,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
def layers = spec.layers()
def parchment = layers[2] as ParchmentMappingsSpec
then:
spec.version == "layered+hash.863714404"
spec.version == "layered+hash.910386113"
layers.size() == 3
layers[0].class == IntermediaryMappingsSpec
layers[1].class == MojangMappingsSpec
@ -66,6 +88,8 @@ class LayeredMappingSpecBuilderTest extends Specification {
}
def "simple mojmap with parchment keep prefix" () {
setup:
mockMinecraftProvider.minecraftVersion() >> "1.17"
when:
def spec = layered() {
officialMojangMappings()
@ -76,7 +100,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
def layers = spec.layers()
def parchment = layers[2] as ParchmentMappingsSpec
then:
spec.version == "layered+hash.863714410"
spec.version == "layered+hash.910386119"
layers.size() == 3
layers[0].class == IntermediaryMappingsSpec
layers[1].class == MojangMappingsSpec
@ -86,6 +110,8 @@ class LayeredMappingSpecBuilderTest extends Specification {
}
def "simple mojmap with parchment keep prefix alternate hash" () {
setup:
mockMinecraftProvider.minecraftVersion() >> "1.17"
when:
def spec = layered() {
officialMojangMappings()
@ -96,7 +122,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
def layers = spec.layers()
def parchment = layers[2] as ParchmentMappingsSpec
then:
spec.version == "layered+hash.1144465487"
spec.version == "layered+hash.1097793778"
layers.size() == 3
layers[0].class == IntermediaryMappingsSpec
layers[1].class == MojangMappingsSpec
@ -111,7 +137,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
}
LayeredMappingSpec layeredAction(Action<LayeredMappingSpecBuilder> action) {
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder()
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(mockMinecraftProvider)
action.execute(builder)
return builder.build()
}

View File

@ -35,7 +35,7 @@ class MojangMappingLayerTest extends LayeredMappingsSpecification {
when:
def mappings = getLayeredMappings(
new IntermediaryMappingsSpec(),
new MojangMappingsSpec()
new MojangMappingsSpec("1.17")
)
def tiny = getTiny(mappings)
then: