Make mojang mappings stable by implementing a custom license supplier

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-06-20 18:47:13 +08:00
parent 9313da0824
commit 076cda371c
3 changed files with 35 additions and 11 deletions

View File

@@ -49,7 +49,7 @@ public record MojangMappingLayer(MinecraftVersionMeta.Download clientDownload,
MinecraftVersionMeta.Download serverDownload,
File workingDir,
Logger logger,
BooleanSupplier silenceLicense) implements MappingLayer {
MojangMappingsSpec.SilenceLicenseOption silenceLicense) implements MappingLayer {
@Override
public void visit(MappingVisitor mappingVisitor) throws IOException {
var clientMappings = new File(workingDir(), "client.txt");
@@ -57,7 +57,7 @@ public record MojangMappingLayer(MinecraftVersionMeta.Download clientDownload,
download(clientMappings, serverMappings);
if (!silenceLicense.getAsBoolean()) {
if (!silenceLicense.isSilent()) {
printMappingsLicense(clientMappings.toPath());
}

View File

@@ -24,21 +24,51 @@
package net.fabricmc.loom.configuration.providers.mappings.mojmap;
import java.util.function.BooleanSupplier;
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(BooleanSupplier silenceLicense) implements MappingsSpec<MojangMappingLayer> {
public record MojangMappingsSpec(SilenceLicenseOption silenceLicense) 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";
public MojangMappingsSpec(SilenceLicenseSupplier supplier) {
this(new SilenceLicenseOption(supplier));
}
public MojangMappingsSpec() {
this(() -> false);
}
@FunctionalInterface
public interface SilenceLicenseSupplier {
boolean isSilent();
}
public record SilenceLicenseOption(SilenceLicenseSupplier supplier) {
public boolean isSilent() {
return supplier.isSilent();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SilenceLicenseOption that)) return false;
return isSilent() == that.isSilent();
}
@Override
public int hashCode() {
return Boolean.hashCode(isSilent());
}
@Override
public String toString() {
return isSilent() + "";
}
}
@Override
public MojangMappingLayer createLayer(MappingContext context) {
MinecraftVersionMeta versionInfo = context.minecraftProvider().getVersionInfo();