Skip to content

Commit

Permalink
Develop beta 41 (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD authored Apr 6, 2024
2 parents e40dcef + 63bd0ff commit a59dbd2
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 83 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ dependencies {
shade(group = "io.github.steelwoolmc", name = "mixin-transmogrifier", version = versionMixinTransmog)
adapterData(group = "org.sinytra.adapter", name = "adapter", version = versionAdapter)

annotationProcessor(group = "net.fabricmc", name = "sponge-mixin", version = versionMixin)
compileOnly(group = "net.fabricmc", name = "sponge-mixin", version = versionMixin)
annotationProcessor(group = "org.sinytra", name = "sponge-mixin", version = versionMixin)
compileOnly(group = "org.sinytra", name = "sponge-mixin", version = versionMixin)
implementation(jarJar("io.github.llamalad7:mixinextras-forge:${mixinextrasVersion}")!!) {
jarJar.ranged(this, "[${mixinextrasVersion},)")
}
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=true

# Versions
versionConnector=1.0.0-beta.40
versionAdapter=1.11.32-1.20.1-20240314.234555
versionAdapterDefinition=1.11.34
versionConnector=1.0.0-beta.41
versionAdapter=1.11.39-1.20.1-20240406.124555
versionAdapterDefinition=1.11.39

versionMc=1.20.1
versionForge=47.1.3
versionForgeAutoRenamingTool=1.0.11
versionFabricLoader=2.7.2+0.15.3+1.20.1
versionAccessWidener=2.1.0
versionFabricApi=0.92.0+1.11.2+1.20.1
versionMixin=0.12.5+mixin.0.8.5
versionMixinTransmog=0.4.3+1.20.1
versionFabricApi=0.92.0+1.11.5+1.20.1
versionMixin=0.12.10+mixin.0.8.5
versionMixinTransmog=0.4.5+1.20.1

# Publishing
curseForgeId=890127
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.su5ed.sinytra.connector.locator;

import com.electronwill.nightconfig.core.file.FileConfig;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.mojang.logging.LogUtils;
Expand All @@ -8,6 +9,7 @@
import dev.su5ed.sinytra.connector.loader.ConnectorEarlyLoader;
import dev.su5ed.sinytra.connector.loader.ConnectorLoaderModMetadata;
import dev.su5ed.sinytra.connector.transformer.jar.JarTransformer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.impl.metadata.NestedJarEntry;
import net.minecraftforge.fml.loading.ClasspathLocatorUtils;
import net.minecraftforge.fml.loading.EarlyLoadingException;
Expand All @@ -19,6 +21,7 @@
import net.minecraftforge.fml.loading.moddiscovery.AbstractJarFileModProvider;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModJarMetadata;
import net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper;
import net.minecraftforge.fml.loading.progress.StartupNotificationManager;
import net.minecraftforge.forgespi.language.IModInfo;
import net.minecraftforge.forgespi.locating.IDependencyLocator;
Expand Down Expand Up @@ -60,6 +63,7 @@
public class ConnectorLocator extends AbstractJarFileModProvider implements IDependencyLocator {
private static final String NAME = "connector_locator";
private static final String SUFFIX = ".jar";
private static final String PLACEHOLDER_PROPERTY = "connector:placeholder";

private static final Logger LOGGER = LogUtils.getLogger();
private static final MethodHandle MJM_INIT = uncheck(() -> MethodHandles.privateLookupIn(ModJarMetadata.class, MethodHandles.lookup()).findConstructor(ModJarMetadata.class, MethodType.methodType(void.class)));
Expand All @@ -86,58 +90,65 @@ public List<IModFile> scanMods(Iterable<IModFile> loadedMods) {
return List.of();
}

private List<IModFile> locateFabricMods(Iterable<IModFile> loadedMods) {
private List<IModFile> locateFabricMods(Iterable<IModFile> discoveredMods) {
LOGGER.debug(SCAN, "Scanning mods dir {} for mods", FMLPaths.MODSDIR.get());
Path tempDir = ConnectorUtil.CONNECTOR_FOLDER.resolve("temp");
// Get all existing mod ids
Collection<SimpleModInfo> loadedModInfos = StreamSupport.stream(loadedMods.spliterator(), false)
Collection<SimpleModInfo> loadedModInfos = StreamSupport.stream(discoveredMods.spliterator(), false)
.flatMap(modFile -> Optional.ofNullable(modFile.getModFileInfo()).stream())
.flatMap(modFileInfo -> {
IModFile modFile = modFileInfo.getFile();
List<IModInfo> modInfos = modFileInfo.getMods();
// Ignore placeholder mods
if (modFileInfo.getFileProperties().containsKey(PLACEHOLDER_PROPERTY)) {
// Set mod version to 0.0 to prioritize the Fabric mod when FML resolves duplicates
modInfos.forEach(mod -> mod.getVersion().parseVersion("0.0"));
return Stream.empty();
}
if (!modInfos.isEmpty()) {
return modInfos.stream().map(modInfo -> new SimpleModInfo(modInfo.getModId(), modInfo.getVersion(), false, modFile));
}
String version = modFileInfo.getFile().getSecureJar().moduleDataProvider().descriptor().version().map(ModuleDescriptor.Version::toString).orElse("0.0");
return Stream.of(new SimpleModInfo(modFileInfo.moduleName(), new DefaultArtifactVersion(version), true, modFile));
})
.toList();
Collection<IModFile> loadedModFiles = loadedModInfos.stream().map(SimpleModInfo::origin).toList();
Collection<String> loadedModIds = loadedModInfos.stream().filter(mod -> !mod.library()).map(SimpleModInfo::modid).collect(Collectors.toUnmodifiableSet());
// Discover fabric mod jars
List<Path> excluded = ModDirTransformerDiscoverer.allExcluded();
List<JarTransformer.TransformableJar> discoveredJars = Stream.of(scanModsDir(excluded), scanClasspath(), scanFromArguments(excluded)).flatMap(s -> s)
.map(rethrowFunction(p -> cacheTransformableJar(p.toFile())))
.filter(jar -> {
String modid = jar.modPath().metadata().modMetadata().getId();
return !shouldIgnoreMod(modid, loadedModIds);
ConnectorLoaderModMetadata metadata = jar.modPath().metadata().modMetadata();
return !shouldIgnoreMod(metadata, loadedModIds);
})
.toList();
Multimap<JarTransformer.TransformableJar, JarTransformer.TransformableJar> parentToChildren = HashMultimap.create();
// Discover fabric nested mod jars
List<JarTransformer.TransformableJar> discoveredNestedJars = discoveredJars.stream()
.flatMap(jar -> {
ConnectorLoaderModMetadata metadata = jar.modPath().metadata().modMetadata();
return shouldIgnoreMod(metadata.getId(), loadedModIds) ? Stream.empty() : discoverNestedJarsRecursive(tempDir, jar, metadata.getJars(), parentToChildren, loadedModIds);
return shouldIgnoreMod(metadata, loadedModIds) ? Stream.empty() : discoverNestedJarsRecursive(tempDir, jar, metadata.getJars(), parentToChildren, loadedModIds);
})
.toList();
// Collect mods that are (likely) going to be excluded by FML's UniqueModListBuilder. Exclude them from global split package filtering
Collection<? super IModFile> ignoredModFiles = new ArrayList<>();
// Remove mods loaded by FML
List<JarTransformer.TransformableJar> uniqueJars = handleDuplicateMods(discoveredJars, discoveredNestedJars, loadedModInfos, ignoredModFiles);
// Ensure we have all required dependencies before transforming
List<JarTransformer.TransformableJar> candidates = DependencyResolver.resolveDependencies(uniqueJars, parentToChildren, loadedMods);
List<JarTransformer.TransformableJar> candidates = DependencyResolver.resolveDependencies(uniqueJars, parentToChildren, loadedModFiles);
// Get renamer library classpath
List<Path> renameLibs = StreamSupport.stream(loadedMods.spliterator(), false).map(modFile -> modFile.getSecureJar().getRootPath()).toList();
List<Path> renameLibs = loadedModFiles.stream().map(modFile -> modFile.getSecureJar().getRootPath()).toList();
// Run jar transformations (or get existing outputs from cache)
List<JarTransformer.FabricModPath> transformed = JarTransformer.transform(candidates, renameLibs, loadedMods);
List<JarTransformer.FabricModPath> transformed = JarTransformer.transform(candidates, renameLibs, loadedModFiles);
// Skip last step to save time if an error occured during transformation
if (ConnectorEarlyLoader.hasEncounteredException()) {
StartupNotificationManager.addModMessage("JAR TRANSFORMATION ERROR");
LOGGER.error("Cancelling jar discovery due to previous error");
return List.of();
}
// Deal with split packages (thanks modules)
List<SplitPackageMerger.FilteredModPath> moduleSafeJars = SplitPackageMerger.mergeSplitPackages(transformed, loadedMods, ignoredModFiles);
List<SplitPackageMerger.FilteredModPath> moduleSafeJars = SplitPackageMerger.mergeSplitPackages(transformed, loadedModFiles, ignoredModFiles);

List<IModFile> modFiles = new ArrayList<>(moduleSafeJars.stream().map(this::createConnectorModFile).toList());
// Create mod file for generated adapter mixins jar
Expand All @@ -154,9 +165,9 @@ private Stream<Path> scanModsDir(List<Path> excluded) {

private Stream<Path> filterPaths(Stream<Path> stream, List<Path> excluded) {
return stream
.filter(p -> !excluded.contains(p) && StringUtils.toLowerCase(p.getFileName().toString()).endsWith(SUFFIX))
.sorted(Comparator.comparing(path -> StringUtils.toLowerCase(path.getFileName().toString())))
.filter(ConnectorLocator::isFabricModJar);
.filter(p -> !excluded.contains(p) && StringUtils.toLowerCase(p.getFileName().toString()).endsWith(SUFFIX))
.sorted(Comparator.comparing(path -> StringUtils.toLowerCase(path.getFileName().toString())))
.filter(ConnectorLocator::isFabricModJar);
}

private Stream<Path> scanClasspath() {
Expand Down Expand Up @@ -190,7 +201,8 @@ private Stream<Path> scanFromArguments(List<Path> excluded) {
Arrays.stream(paths).filter(s -> !s.isBlank()).map(Path::of).forEach(path -> {
if (Files.isDirectory(path)) {
uncheck(() -> Files.list(path)).forEach(files::add);
} else {
}
else {
files.add(path);
}
});
Expand All @@ -216,7 +228,8 @@ private IModFile createModOrThrow(Path... paths) {
private static boolean isFabricModJar(Path path) {
SecureJar secureJar = SecureJar.from(path);
String name = secureJar.name();
if (secureJar.moduleDataProvider().findFile(ConnectorUtil.MODS_TOML).isPresent()) {
Path modsToml = secureJar.getPath(ConnectorUtil.MODS_TOML);
if (Files.exists(modsToml) && !containsPlaceholder(modsToml)) {
LOGGER.debug(SCAN, "Skipping jar {} as it contains a mods.toml file", path);
return false;
}
Expand All @@ -228,6 +241,21 @@ private static boolean isFabricModJar(Path path) {
return false;
}

private static boolean containsPlaceholder(Path modsTomlPath) {
try {
FileConfig fileConfig = FileConfig.of(modsTomlPath);
fileConfig.load();
fileConfig.close();
NightConfigWrapper config = new NightConfigWrapper(fileConfig);
return config.<Map<String, Object>>getConfigElement("properties")
.map(map -> map.containsKey(PLACEHOLDER_PROPERTY))
.orElse(false);
} catch (Throwable t) {
LOGGER.error("Error reading placeholder information from {}", modsTomlPath, t);
return false;
}
}

private static Stream<JarTransformer.TransformableJar> discoverNestedJarsRecursive(Path tempDir, JarTransformer.TransformableJar parent, Collection<NestedJarEntry> jars, Multimap<JarTransformer.TransformableJar, JarTransformer.TransformableJar> parentToChildren, Collection<String> loadedModIds) {
SecureJar secureJar = SecureJar.from(parent.input().toPath());
return jars.stream()
Expand All @@ -236,7 +264,7 @@ private static Stream<JarTransformer.TransformableJar> discoverNestedJarsRecursi
.flatMap(path -> {
JarTransformer.TransformableJar jar = uncheck(() -> prepareNestedJar(tempDir, secureJar.getPrimaryPath().getFileName().toString(), path));
ConnectorLoaderModMetadata metadata = jar.modPath().metadata().modMetadata();
if (shouldIgnoreMod(metadata.getId(), loadedModIds)) {
if (shouldIgnoreMod(metadata, loadedModIds)) {
return Stream.empty();
}
parentToChildren.put(parent, jar);
Expand Down Expand Up @@ -289,7 +317,9 @@ private static List<JarTransformer.TransformableJar> handleDuplicateMods(List<Ja
.toList();
}

private static boolean shouldIgnoreMod(String id, Collection<String> loadedModIds) {
private static boolean shouldIgnoreMod(ConnectorLoaderModMetadata metadata, Collection<String> loadedModIds) {
if (!metadata.loadsInEnvironment(FabricLoader.getInstance().getEnvironmentType())) return true;
String id = metadata.getId();
return ConnectorUtil.DISABLED_MODS.contains(id) || loadedModIds.contains(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Parses Fabric mod JSON metadata into TOML format at runtime.
*/
public final class ConnectorModMetadataParser {
private static final String DEFAULT_LICENSE = "All Rights Reserved";
// From ModInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.mojang.logging.LogUtils;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.apache.commons.lang3.RandomStringUtils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,7 +56,7 @@ public final class EmbeddedDependencies {
// Return a random string to still write an input file, so that once we have a proper version available we refresh the cache
return RandomStringUtils.randomAlphabetic(5);
}
return ver;
return ver + "," + FMLEnvironment.dist.name().toLowerCase();
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ConnectorLoaderService implements ITransformationService {
private static final String AUTHLIB_MODULE = "authlib";
private static final Logger LOGGER = LogUtils.getLogger();

static {
// Enable frame expansion fixes on our mixin fork
System.setProperty("mixin.env.fixFrameExpansion", "true");
}

@Override
public String name() {
return NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ static void apply(Map<String, ModFileInfo> configToModMap) {
config.decorate(FabricUtil.KEY_MOD_ID, mod.moduleName());
if (!mod.getMods().isEmpty()) {
String modid = mod.getMods().get(0).getModId();
int compat = ConnectorEarlyLoader.isConnectorMod(modid) ? FabricLoaderImpl.INSTANCE.getModContainer(modid)
.map(m -> getMixinCompat(m.getMetadata()))
.orElse(FabricUtil.COMPATIBILITY_0_10_0)
: FabricUtil.COMPATIBILITY_0_10_0;
int compat;
if (ConnectorEarlyLoader.isConnectorMod(modid)) {
compat = FabricLoaderImpl.INSTANCE.getModContainer(modid)
.map(m -> getMixinCompat(m.getMetadata()))
.orElse(FabricUtil.COMPATIBILITY_0_10_0);
config.decorate(FabricUtil.KEY_FIX_FRAME_EXPANSION, true);
} else {
compat = FabricUtil.COMPATIBILITY_0_10_0;
}
config.decorate(FabricUtil.KEY_COMPATIBILITY, compat);
}
}
Expand Down
Loading

0 comments on commit a59dbd2

Please sign in to comment.