mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-01 21:17:46 -05:00
@@ -74,7 +74,7 @@ public class LoomGradlePlugin implements BootstrappedPlugin {
|
||||
project.getLogger().lifecycle("You are using an unstable version of Architectury Loom! Please report any issues found!");
|
||||
}
|
||||
|
||||
refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies() || "true".equals(System.getProperty("loom.refresh"));
|
||||
refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies() || Boolean.getBoolean("loom.refresh");
|
||||
|
||||
if (refreshDeps) {
|
||||
project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower.");
|
||||
|
||||
@@ -49,4 +49,10 @@ public interface LayeredMappingSpecBuilder {
|
||||
LayeredMappingSpecBuilder parchment(Object object, Action<ParchmentMappingsSpecBuilder> action);
|
||||
|
||||
LayeredMappingSpecBuilder crane(Object object);
|
||||
|
||||
/**
|
||||
* Add a signatureFix layer. Reads the @extras/record_signatures.json" file in a jar file such as yarn.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
LayeredMappingSpecBuilder signatureFix(Object object);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.ParchmentMappingsSpecBuilder;
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.crane.CraneMappingsSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.extras.signatures.SignatureFixesSpec;
|
||||
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.ParchmentMappingsSpecBuilderImpl;
|
||||
@@ -75,6 +76,11 @@ public class LayeredMappingSpecBuilderImpl implements LayeredMappingSpecBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayeredMappingSpecBuilder signatureFix(Object object) {
|
||||
return addLayer(new SignatureFixesSpec(FileSpec.create(object)));
|
||||
}
|
||||
|
||||
public LayeredMappingSpec build() {
|
||||
List<MappingsSpec<?>> builtLayers = new LinkedList<>();
|
||||
// Intermediary is always the base layer
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -55,6 +57,7 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
@@ -84,29 +87,51 @@ public class LayeredMappingsDependency extends AbstractModuleDependency implemen
|
||||
if (!Files.exists(mappingsFile) || LoomGradlePlugin.refreshDeps) {
|
||||
try {
|
||||
var processor = new LayeredMappingsProcessor(layeredMappingSpec);
|
||||
MemoryMappingTree mappings = processor.getMappings(mappingContext);
|
||||
List<MappingLayer> layers = processor.resolveLayers(mappingContext);
|
||||
|
||||
try (Writer writer = new StringWriter()) {
|
||||
Tiny2Writer tiny2Writer = new Tiny2Writer(writer, false);
|
||||
Files.deleteIfExists(mappingsFile);
|
||||
|
||||
MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingsNamespace.NAMED.toString()));
|
||||
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true);
|
||||
mappings.accept(nsSwitch);
|
||||
|
||||
Files.deleteIfExists(mappingsFile);
|
||||
|
||||
ZipUtil.pack(new ZipEntrySource[] {
|
||||
new ByteSource("mappings/mappings.tiny", writer.toString().getBytes(StandardCharsets.UTF_8))
|
||||
}, mappingsFile.toFile());
|
||||
}
|
||||
writeMapping(processor, layers, mappingsFile);
|
||||
writeSignatureFixes(processor, layers, mappingsFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to resolve Mojang mappings", e);
|
||||
throw new RuntimeException("Failed to resolve layered mappings", e);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.singleton(mappingsFile.toFile());
|
||||
}
|
||||
|
||||
private void writeMapping(LayeredMappingsProcessor processor, List<MappingLayer> layers, Path mappingsFile) throws IOException {
|
||||
MemoryMappingTree mappings = processor.getMappings(layers);
|
||||
|
||||
try (Writer writer = new StringWriter()) {
|
||||
Tiny2Writer tiny2Writer = new Tiny2Writer(writer, false);
|
||||
|
||||
MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingsNamespace.NAMED.toString()));
|
||||
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true);
|
||||
mappings.accept(nsSwitch);
|
||||
|
||||
ZipUtil.pack(new ZipEntrySource[] {
|
||||
new ByteSource("mappings/mappings.tiny", writer.toString().getBytes(StandardCharsets.UTF_8))
|
||||
}, mappingsFile.toFile());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSignatureFixes(LayeredMappingsProcessor processor, List<MappingLayer> layers, Path mappingsFile) throws IOException {
|
||||
Map<String, String> signatureFixes = processor.getSignatureFixes(layers);
|
||||
|
||||
if (signatureFixes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] data = LoomGradlePlugin.OBJECT_MAPPER.writeValueAsString(signatureFixes).getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
ZipUtil.addEntry(
|
||||
mappingsFile.toFile(),
|
||||
new ByteSource("extras/record_signatures.json", data)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<File> resolve(boolean transitive) {
|
||||
return resolve();
|
||||
|
||||
@@ -26,12 +26,19 @@ package net.fabricmc.loom.configuration.providers.mappings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.extras.signatures.SignatureFixesLayer;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
@@ -42,9 +49,8 @@ public class LayeredMappingsProcessor {
|
||||
this.layeredMappingSpec = spec;
|
||||
}
|
||||
|
||||
public MemoryMappingTree getMappings(MappingContext context) throws IOException {
|
||||
MemoryMappingTree mappingTree = new MemoryMappingTree();
|
||||
|
||||
public List<MappingLayer> resolveLayers(MappingContext context) {
|
||||
List<MappingLayer> layers = new LinkedList<>();
|
||||
List<Class<? extends MappingLayer>> visitedLayers = new ArrayList<>();
|
||||
|
||||
for (MappingsSpec<?> spec : layeredMappingSpec.layers()) {
|
||||
@@ -56,8 +62,17 @@ public class LayeredMappingsProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
layers.add(layer);
|
||||
visitedLayers.add(layer.getClass());
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(layers);
|
||||
}
|
||||
|
||||
public MemoryMappingTree getMappings(List<MappingLayer> layers) throws IOException {
|
||||
MemoryMappingTree mappingTree = new MemoryMappingTree();
|
||||
|
||||
for (MappingLayer layer : layers) {
|
||||
// We have to rebuild a new tree to work on when a layer doesnt merge into layered
|
||||
boolean rebuild = layer.getSourceNamespace() != MappingsNamespace.NAMED;
|
||||
MemoryMappingTree workingTree;
|
||||
@@ -90,4 +105,21 @@ public class LayeredMappingsProcessor {
|
||||
|
||||
return mappingTree;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> getSignatureFixes(List<MappingLayer> layers) {
|
||||
Map<String, String> signatureFixes = new HashMap<>();
|
||||
|
||||
for (MappingLayer layer : layers) {
|
||||
if (layer instanceof SignatureFixesLayer signatureFixesLayer) {
|
||||
signatureFixes.putAll(signatureFixesLayer.getSignatureFixes());
|
||||
}
|
||||
}
|
||||
|
||||
if (signatureFixes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Collections.unmodifiableMap(signatureFixes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.fabricmc.loom.configuration.providers.mappings;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -41,6 +42,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -50,6 +52,7 @@ import com.google.gson.JsonObject;
|
||||
import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zeroturnaround.zip.FileSource;
|
||||
import org.zeroturnaround.zip.ZipEntrySource;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
@@ -109,6 +112,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
private UnpickMetadata unpickMetadata;
|
||||
private MemoryMappingTree mappingTree;
|
||||
private MemoryMappingTree mappingTreeWithSrg;
|
||||
private Map<String, String> signatureFixes;
|
||||
|
||||
public MappingsProviderImpl(Project project) {
|
||||
super(project);
|
||||
@@ -141,7 +145,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath(), postPopulationScheduler);
|
||||
} else {
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(mappingsJar.toPath(), (ClassLoader) null)) {
|
||||
extractUnpickDefinitions(fileSystem, unpickDefinitions);
|
||||
extractExtras(fileSystem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +303,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(yarnJar, (ClassLoader) null)) {
|
||||
extractMappings(fileSystem, baseTinyMappings);
|
||||
extractUnpickDefinitions(fileSystem, unpickDefinitions);
|
||||
extractExtras(fileSystem);
|
||||
}
|
||||
|
||||
if (areMappingsMergedV2(baseTinyMappings)) {
|
||||
@@ -388,7 +392,12 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
Files.copy(jar.getPath("mappings/mappings.tiny"), extractTo, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void extractUnpickDefinitions(FileSystem jar, Path extractTo) throws IOException {
|
||||
private void extractExtras(FileSystem jar) throws IOException {
|
||||
extractUnpickDefinitions(jar);
|
||||
extractSignatureFixes(jar);
|
||||
}
|
||||
|
||||
private void extractUnpickDefinitions(FileSystem jar) throws IOException {
|
||||
Path unpickPath = jar.getPath("extras/definitions.unpick");
|
||||
Path unpickMetadataPath = jar.getPath("extras/unpick.json");
|
||||
|
||||
@@ -396,12 +405,25 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
return;
|
||||
}
|
||||
|
||||
Files.copy(unpickPath, extractTo, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.copy(unpickPath, unpickDefinitions, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
unpickMetadata = parseUnpickMetadata(unpickMetadataPath);
|
||||
hasUnpickDefinitions = true;
|
||||
}
|
||||
|
||||
private void extractSignatureFixes(FileSystem jar) throws IOException {
|
||||
Path recordSignaturesJsonPath = jar.getPath("extras/record_signatures.json");
|
||||
|
||||
if (!Files.exists(recordSignaturesJsonPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (Reader reader = Files.newBufferedReader(recordSignaturesJsonPath, StandardCharsets.UTF_8)) {
|
||||
//noinspection unchecked
|
||||
signatureFixes = LoomGradlePlugin.OBJECT_MAPPER.readValue(reader, Map.class);
|
||||
}
|
||||
}
|
||||
|
||||
private UnpickMetadata parseUnpickMetadata(Path input) throws IOException {
|
||||
JsonObject jsonObject = LoomGradlePlugin.GSON.fromJson(Files.readString(input), JsonObject.class);
|
||||
|
||||
@@ -599,6 +621,11 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
return hasUnpickDefinitions;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> getSignatureFixes() {
|
||||
return signatureFixes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File intermediaryTinyFile() {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.mappings.extras.signatures;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface SignatureFixesLayer {
|
||||
Map<String, String> getSignatureFixes();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.mappings.extras.signatures;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
|
||||
import net.fabricmc.mappingio.MappingVisitor;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public record SignatureFixesLayerImpl(Path mappingsFile) implements MappingLayer, SignatureFixesLayer {
|
||||
private static final String SIGNATURE_FIXES_PATH = "extras/record_signatures.json";
|
||||
|
||||
@Override
|
||||
public void visit(MappingVisitor mappingVisitor) throws IOException {
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getSignatureFixes() {
|
||||
try (var zipFile = new ZipFile(mappingsFile().toFile())) {
|
||||
ZipEntry zipFileEntry = zipFile.getEntry(SIGNATURE_FIXES_PATH);
|
||||
Objects.requireNonNull(zipFileEntry, "Could not find %s in file".formatted(SIGNATURE_FIXES_PATH));
|
||||
|
||||
try (var reader = new InputStreamReader(zipFile.getInputStream(zipFileEntry))) {
|
||||
//noinspection unchecked
|
||||
return LoomGradlePlugin.OBJECT_MAPPER.readValue(reader, Map.class);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to extract signature fixes", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.mappings.extras.signatures;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public record SignatureFixesSpec(FileSpec fileSpec) implements MappingsSpec<SignatureFixesLayerImpl> {
|
||||
@Override
|
||||
public SignatureFixesLayerImpl createLayer(MappingContext context) {
|
||||
return new SignatureFixesLayerImpl(fileSpec.get(context));
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,13 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
@@ -41,10 +45,13 @@ import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.NonClassCopyMode;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import dev.architectury.tinyremapper.api.TrClass;
|
||||
import org.apache.commons.lang3.mutable.Mutable;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.gradle.api.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
@@ -230,8 +237,8 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
Info vanilla = new Info(vanillaAssets, input, outputMapped, outputIntermediary, outputSrg);
|
||||
Info forge = getExtension().isForgeAndNotOfficial() ? new Info(forgeAssets, inputForge, forgeOutputMapped, forgeOutputIntermediary, forgeOutputSrg) : null;
|
||||
|
||||
Pair<TinyRemapper, Mutable<MemoryMappingTree>> pair = TinyRemapperHelper.getTinyRemapper(getProject(), true);
|
||||
TinyRemapper remapper = remapperArray[0] = pair.getKey();
|
||||
Triple<TinyRemapper, Mutable<MemoryMappingTree>, List<TinyRemapper.ApplyVisitorProvider>> pair = TinyRemapperHelper.getTinyRemapper(getProject(), true, builder -> { });
|
||||
TinyRemapper remapper = remapperArray[0] = pair.getLeft();
|
||||
|
||||
assetsOut(input, vanillaAssets);
|
||||
|
||||
@@ -239,7 +246,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
assetsOut(inputForge, forgeAssets);
|
||||
}
|
||||
|
||||
remap(remapper, pair.getValue(), vanilla, forge, MappingsNamespace.OFFICIAL.toString());
|
||||
remap(remapper, pair.getMiddle(), pair.getRight(), vanilla, forge, MappingsNamespace.OFFICIAL.toString());
|
||||
}
|
||||
|
||||
public static class Info {
|
||||
@@ -258,7 +265,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public void remap(TinyRemapper remapper, Mutable<MemoryMappingTree> mappings, Info vanilla, @Nullable Info forge, String fromM) throws IOException {
|
||||
public void remap(TinyRemapper remapper, Mutable<MemoryMappingTree> mappings, List<TinyRemapper.ApplyVisitorProvider> postApply, Info vanilla, @Nullable Info forge, String fromM) throws IOException {
|
||||
Set<String> classNames = getExtension().isForge() ? InnerClassRemapper.readClassNames(vanilla.input) : null;
|
||||
|
||||
for (String toM : getExtension().isForge() ? Arrays.asList(MappingsNamespace.INTERMEDIARY.toString(), MappingsNamespace.SRG.toString(), MappingsNamespace.NAMED.toString()) : Arrays.asList(MappingsNamespace.INTERMEDIARY.toString(), MappingsNamespace.NAMED.toString())) {
|
||||
@@ -267,6 +274,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
InputTag vanillaTag = remapper.createInputTag();
|
||||
InputTag forgeTag = remapper.createInputTag();
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
final boolean fixSignatures = getExtension().getMappingsProvider().getSignatureFixes() != null;
|
||||
getProject().getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
|
||||
remapper.readInputs(vanillaTag, vanilla.input);
|
||||
@@ -277,6 +285,55 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
|
||||
remapper.replaceMappings(getMappings(classNames, fromM, toM, mappings));
|
||||
if (!MappingsNamespace.INTERMEDIARY.toString().equals(toM)) mappings.setValue(null);
|
||||
postApply.clear();
|
||||
|
||||
// Bit ugly but whatever, the whole issue is a bit ugly :)
|
||||
AtomicReference<Map<String, String>> remappedSignatures = new AtomicReference<>();
|
||||
if (fixSignatures) {
|
||||
postApply.add(new TinyRemapper.ApplyVisitorProvider() {
|
||||
@Override
|
||||
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
|
||||
return new ClassVisitor(Constants.ASM_VERSION, next) {
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
Map<String, String> signatureFixes = Objects.requireNonNull(remappedSignatures.get(), "Could not get remapped signatures");
|
||||
|
||||
if (signature == null) {
|
||||
signature = signatureFixes.getOrDefault(name, null);
|
||||
|
||||
if (signature != null) {
|
||||
getProject().getLogger().info("Replaced signature for {} with {}", name, signature);
|
||||
}
|
||||
}
|
||||
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
if (MappingsNamespace.INTERMEDIARY.toString().equals(toM)) {
|
||||
// No need to remap, as these are already intermediary
|
||||
remappedSignatures.set(getExtension().getMappingsProvider().getSignatureFixes());
|
||||
} else {
|
||||
// Remap the sig fixes from intermediary to the target namespace
|
||||
final Map<String, String> remapped = new HashMap<>();
|
||||
final TinyRemapper sigTinyRemapper = TinyRemapperHelper.getTinyRemapper(getProject(), fromM, toM);
|
||||
final Remapper sigAsmRemapper = sigTinyRemapper.getRemapper();
|
||||
|
||||
// Remap the class names and the signatures using a new tiny remapper instance.
|
||||
for (Map.Entry<String, String> entry : getExtension().getMappingsProvider().getSignatureFixes().entrySet()) {
|
||||
remapped.put(
|
||||
sigAsmRemapper.map(entry.getKey()),
|
||||
sigAsmRemapper.mapSignature(entry.getValue(), false)
|
||||
);
|
||||
}
|
||||
|
||||
sigTinyRemapper.finish();
|
||||
remappedSignatures.set(remapped);
|
||||
}
|
||||
}
|
||||
|
||||
OutputRemappingHandler.remap(remapper, vanilla.assets, output, null, vanillaTag);
|
||||
|
||||
if (forge != null) {
|
||||
|
||||
@@ -27,7 +27,10 @@ package net.fabricmc.loom.util;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -37,6 +40,7 @@ import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.apache.commons.lang3.mutable.Mutable;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
@@ -63,13 +67,13 @@ public final class TinyRemapperHelper {
|
||||
}
|
||||
|
||||
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM) throws IOException {
|
||||
return getTinyRemapper(project, fromM, toM, false);
|
||||
return getTinyRemapper(project, fromM, toM, false, (builder) -> { });
|
||||
}
|
||||
|
||||
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM, boolean fixRecords) throws IOException {
|
||||
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer) throws IOException {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
TinyRemapper remapper = _getTinyRemapper(project, fixRecords).getKey();
|
||||
TinyRemapper remapper = _getTinyRemapper(project, fixRecords, builderConsumer).getLeft();
|
||||
remapper.replaceMappings(ImmutableSet.of(
|
||||
TinyRemapperHelper.create((fromM.equals("srg") || toM.equals("srg")) && extension.isForge() ? extension.getMappingsProvider().getMappingsWithSrg() : extension.getMappingsProvider().getMappings(), fromM, toM, true),
|
||||
out -> TinyRemapperHelper.JSR_TO_JETBRAINS.forEach(out::acceptClass)
|
||||
@@ -77,9 +81,10 @@ public final class TinyRemapperHelper {
|
||||
return remapper;
|
||||
}
|
||||
|
||||
public static Pair<TinyRemapper, Mutable<MemoryMappingTree>> _getTinyRemapper(Project project, boolean fixRecords) throws IOException {
|
||||
public static Triple<TinyRemapper, Mutable<MemoryMappingTree>, List<TinyRemapper.ApplyVisitorProvider>> _getTinyRemapper(Project project, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer) throws IOException {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
Mutable<MemoryMappingTree> mappings = new MutableObject<>();
|
||||
List<TinyRemapper.ApplyVisitorProvider> postApply = new ArrayList<>();
|
||||
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
|
||||
.renameInvalidLocals(true)
|
||||
@@ -97,22 +102,30 @@ public final class TinyRemapperHelper {
|
||||
builder.fixPackageAccess(true);
|
||||
}
|
||||
|
||||
TinyRemapper remapper = builder.invalidLvNamePattern(MC_LV_PATTERN)
|
||||
.extraPreApplyVisitor((cls, next) -> {
|
||||
if (fixRecords && !cls.isRecord() && "java/lang/Record".equals(cls.getSuperName()) && mappings.getValue() != null) {
|
||||
return new RecordComponentFixVisitor(next, mappings.getValue(), mappings.getValue().getNamespaceId(MappingsNamespace.INTERMEDIARY.toString()));
|
||||
}
|
||||
builder.invalidLvNamePattern(MC_LV_PATTERN);
|
||||
builder.extraPreApplyVisitor((cls, next) -> {
|
||||
if (fixRecords && !cls.isRecord() && "java/lang/Record".equals(cls.getSuperName()) && mappings.getValue() != null) {
|
||||
return new RecordComponentFixVisitor(next, mappings.getValue(), mappings.getValue().getNamespaceId(MappingsNamespace.INTERMEDIARY.toString()));
|
||||
}
|
||||
|
||||
return next;
|
||||
})
|
||||
.build();
|
||||
return Pair.of(remapper, mappings);
|
||||
return next;
|
||||
});
|
||||
builder.extraPostApplyVisitor((trClass, classVisitor) -> {
|
||||
for (TinyRemapper.ApplyVisitorProvider provider : postApply) {
|
||||
classVisitor = provider.insertApplyVisitor(trClass, classVisitor);
|
||||
}
|
||||
|
||||
return classVisitor;
|
||||
});
|
||||
|
||||
builderConsumer.accept(builder);
|
||||
return Triple.of(builder.build(), mappings, postApply);
|
||||
}
|
||||
|
||||
public static Pair<TinyRemapper, Mutable<MemoryMappingTree>> getTinyRemapper(Project project, boolean fixRecords) throws IOException {
|
||||
Pair<TinyRemapper, Mutable<MemoryMappingTree>> remapper = _getTinyRemapper(project, fixRecords);
|
||||
remapper.getKey().readClassPath(getMinecraftDependencies(project));
|
||||
remapper.getKey().prepareClasses();
|
||||
public static Triple<TinyRemapper, Mutable<MemoryMappingTree>, List<TinyRemapper.ApplyVisitorProvider>> getTinyRemapper(Project project, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer) throws IOException {
|
||||
Triple<TinyRemapper, Mutable<MemoryMappingTree>, List<TinyRemapper.ApplyVisitorProvider>> remapper = _getTinyRemapper(project, fixRecords, builderConsumer);
|
||||
remapper.getLeft().readClassPath(getMinecraftDependencies(project));
|
||||
remapper.getLeft().prepareClasses();
|
||||
return remapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ package net.fabricmc.loom.test
|
||||
|
||||
class LoomTestConstants {
|
||||
public final static String DEFAULT_GRADLE = "7.0.1"
|
||||
public final static String PRE_RELEASE_GRADLE = "7.3-20210906222431+0000"
|
||||
public final static String PRE_RELEASE_GRADLE = "7.4-20210926222420+0000"
|
||||
|
||||
public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE]
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay
|
||||
MemoryMappingTree getLayeredMappings(MappingsSpec<? extends MappingLayer>... specs) {
|
||||
LayeredMappingSpec spec = new LayeredMappingSpec(specs.toList())
|
||||
LayeredMappingsProcessor processor = new LayeredMappingsProcessor(spec)
|
||||
return processor.getMappings(mappingContext)
|
||||
return processor.getMappings(processor.resolveLayers(mappingContext))
|
||||
}
|
||||
|
||||
String getTiny(MemoryMappingTree mappingTree) {
|
||||
|
||||
@@ -10,12 +10,16 @@ archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/main/resources/modid.accesswidener")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
//modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
minecraft_version=21w37a
|
||||
yarn_mappings=21w37a+build.5
|
||||
minecraft_version=21w38a
|
||||
yarn_mappings=21w38a+build.9
|
||||
loader_version=0.11.7
|
||||
fabric_version=0.37.1+1.17
|
||||
fabric_version=0.40.4+1.18
|
||||
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.example
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package net.fabricmc.example.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.world.chunk.PalettedContainer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
System.out.println("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
||||
@Mixin(PalettedContainer.class)
|
||||
public abstract class ExampleMixin<T> {
|
||||
@Shadow
|
||||
private volatile PalettedContainer.Data<T> data;
|
||||
}
|
||||
@@ -32,5 +32,6 @@
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
},
|
||||
"accessWidener" : "modid.accesswidener"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
accessWidener v1 named
|
||||
|
||||
accessible class net/minecraft/world/chunk/PalettedContainer$Data
|
||||
Reference in New Issue
Block a user