Skip to content

Commit 57f0e93

Browse files
committed
Finish mod discoverer refactoring for now
1 parent 0d3e4ec commit 57f0e93

7 files changed

Lines changed: 64 additions & 59 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
2+
3+
import java.nio.file.Path;
4+
5+
public class DefaultModCandidate extends ModCandidate {
6+
public DefaultModCandidate(String modName, Path file, Path original) {
7+
super(modName, modName, file, original);
8+
}
9+
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/DefaultModEntry.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/ModEntry.java renamed to src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/ModCandidate.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
import java.nio.file.Path;
44

5-
public abstract class ModEntry {
5+
public abstract class ModCandidate {
66
public final String modName;
77
public final String modId;
88

99
public final Path file;
1010
public final Path original;
1111

12-
protected ModEntry(String modName, String modId, Path file, Path original) {
12+
protected ModCandidate(String modName, String modId, Path file, Path original) {
1313
this.modName = modName;
1414
this.modId = modId;
1515
this.file = file;
1616
this.original = original;
1717
}
18-
19-
abstract String getType();
2018
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/context/v1/ModRemapperV1Context.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.SoftLockFixer;
1414
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.visitor.MRAApplyVisitor;
1515
import net.fabricmc.loader.api.FabricLoader;
16+
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
1617
import net.fabricmc.tinyremapper.TinyRemapper;
1718

1819
import java.io.IOException;
@@ -93,7 +94,17 @@ public void afterRemap() {
9394

9495
@Override
9596
public void discoverMods(boolean remapClassEdits) {
96-
this.modDiscoverer.init(remappers, remapClassEdits, this);
97+
Map<Path, Path> modPaths = this.modDiscoverer.init(remappers, remapClassEdits, this);
98+
99+
for (Path path : modPaths.keySet()) {
100+
mappingsRegistry.addModMappings(path);
101+
}
102+
103+
mappingsRegistry.generateModMappings();
104+
105+
this.remapMods(modPaths);
106+
107+
modPaths.values().forEach(FabricLauncherBase.getLauncher()::addToClassPath);
97108
}
98109

99110
private static final String v0EntrypointName = "mod-remapper-api:modremapper";

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/context/v1/V1ModDiscoverer.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import fr.catcore.modremapperapi.utils.Constants;
44
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.ModRemapper;
5-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.DefaultModEntry;
6-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModEntry;
5+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.DefaultModCandidate;
6+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModCandidate;
77
import io.github.fabriccompatibiltylayers.modremappingapi.impl.compatibility.V0ModRemapper;
88
import io.github.fabriccompatibiltylayers.modremappingapi.impl.discover.BaseModDiscoverer;
99
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.CacheUtils;
1010
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.FileUtils;
1111
import net.fabricmc.loader.api.FabricLoader;
12-
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
1312
import org.jetbrains.annotations.NotNull;
1413

1514
import java.io.IOException;
@@ -36,7 +35,7 @@ public Map<Path, Path> init(List<ModRemapper> modRemappers, boolean remapClassEd
3635
}
3736
}
3837

39-
List<ModEntry> mods = new ArrayList<>();
38+
List<ModCandidate> mods = new ArrayList<>();
4039

4140
for (String jarFolder : modFolders) {
4241
Path mcSubFolder = FabricLoader.getInstance().getGameDir().resolve(jarFolder);
@@ -77,30 +76,20 @@ public Map<Path, Path> init(List<ModRemapper> modRemappers, boolean remapClassEd
7776
modPaths = excludeClassEdits(modPaths, mainTempDir, context.getMappingsRegistry());
7877
}
7978

80-
for (Path path : modPaths.keySet()) {
81-
context.getMappingsRegistry().addModMappings(path);
82-
}
83-
84-
context.getMappingsRegistry().generateModMappings();
85-
86-
context.remapMods(modPaths);
87-
88-
modPaths.values().forEach(FabricLauncherBase.getLauncher()::addToClassPath);
89-
9079
return modPaths;
9180
}
9281

93-
private void handleV0Excluded(List<ModEntry> mods) throws IOException, URISyntaxException {
94-
for (ModEntry modEntry : mods) {
95-
if (excluded.containsKey(modEntry.modId)) {
96-
if (Files.isDirectory(modEntry.file)) {
97-
for (String excluded : excluded.get(modEntry.modId)) {
98-
if (Files.deleteIfExists(modEntry.file.resolve(excluded))) {
99-
Constants.MAIN_LOGGER.debug("File deleted: " + modEntry.file.resolve(excluded));
82+
private void handleV0Excluded(List<ModCandidate> mods) throws IOException, URISyntaxException {
83+
for (ModCandidate modCandidate : mods) {
84+
if (excluded.containsKey(modCandidate.modId)) {
85+
if (Files.isDirectory(modCandidate.file)) {
86+
for (String excluded : excluded.get(modCandidate.modId)) {
87+
if (Files.deleteIfExists(modCandidate.file.resolve(excluded))) {
88+
Constants.MAIN_LOGGER.debug("File deleted: " + modCandidate.file.resolve(excluded));
10089
}
10190
}
10291
} else {
103-
FileUtils.removeEntriesFromZip(modEntry.file, excluded.get(modEntry.modId));
92+
FileUtils.removeEntriesFromZip(modCandidate.file, excluded.get(modCandidate.modId));
10493
}
10594
}
10695
}
@@ -112,12 +101,22 @@ public boolean isValidFileName(String fileName) {
112101
}
113102

114103
@Override
115-
public boolean allowDirectories() {
104+
public boolean allowDirectoryMods() {
116105
return true;
117106
}
118107

119108
@Override
120-
public Optional<ModEntry> discoverFolderMod(Path folder, Path destinationFolder) throws IOException {
109+
public boolean searchRecursively() {
110+
return false;
111+
}
112+
113+
@Override
114+
public boolean isValidDirectoryName(String directoryName) {
115+
return false;
116+
}
117+
118+
@Override
119+
public Optional<ModCandidate> discoverFolderMod(Path folder, Path destinationFolder) throws IOException {
121120
String name = folder.getFileName().toString().replace(" ", "_");
122121
Path destination = destinationFolder.resolve(name + ".zip");
123122

@@ -137,7 +136,7 @@ public Optional<ModEntry> discoverFolderMod(Path folder, Path destinationFolder)
137136

138137
if (hasClasses[0]) {
139138
return Optional.of(
140-
new DefaultModEntry(
139+
new DefaultModCandidate(
141140
name,
142141
destination,
143142
folder
@@ -149,7 +148,7 @@ public Optional<ModEntry> discoverFolderMod(Path folder, Path destinationFolder)
149148
}
150149

151150
@Override
152-
public Optional<ModEntry> discoverFileMod(Path file, Path destinationFolder) throws IOException {
151+
public Optional<ModCandidate> discoverFileMod(Path file, Path destinationFolder) throws IOException {
153152
String fileName = file.getFileName().toString().replace(" ", "_");
154153
String modName = fileName.replace(".jar", "").replace(".zip", "");
155154

@@ -167,7 +166,7 @@ public Optional<ModEntry> discoverFileMod(Path file, Path destinationFolder) thr
167166

168167
if (found) {
169168
return Optional.of(
170-
new DefaultModEntry(
169+
new DefaultModCandidate(
171170
modName,
172171
destinationFolder.resolve(fileName),
173172
file

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/discover/BaseModDiscoverer.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.impl.discover;
22

3-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModEntry;
3+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModCandidate;
44
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry;
55
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.FileUtils;
66
import org.spongepowered.include.com.google.common.collect.ImmutableList;
@@ -15,22 +15,28 @@
1515

1616
public abstract class BaseModDiscoverer {
1717
public abstract boolean isValidFileName(String fileName);
18-
public abstract boolean allowDirectories();
19-
public abstract Optional<ModEntry> discoverFolderMod(Path folder, Path destinationFolder) throws IOException;
20-
public abstract Optional<ModEntry> discoverFileMod(Path file, Path destinationFolder) throws IOException;
18+
public abstract boolean allowDirectoryMods();
19+
public abstract boolean searchRecursively();
20+
public abstract boolean isValidDirectoryName(String directoryName);
21+
public abstract Optional<ModCandidate> discoverFolderMod(Path folder, Path destinationFolder) throws IOException;
22+
public abstract Optional<ModCandidate> discoverFileMod(Path file, Path destinationFolder) throws IOException;
2123

22-
public List<ModEntry> discoverMods(Path folder, Path destination) throws IOException {
23-
List<ModEntry> mods = new ArrayList<>();
24+
public List<ModCandidate> discoverMods(Path folder, Path destination) throws IOException {
25+
List<ModCandidate> mods = new ArrayList<>();
2426

2527
if (!Files.isDirectory(folder)) return ImmutableList.of();
2628

2729
try (DirectoryStream<Path> stream = Files.newDirectoryStream(folder)) {
2830
for (Path path : stream) {
2931
String name = path.getFileName().toString();
3032

31-
if (Files.isDirectory(path) && allowDirectories()) {
32-
discoverFolderMod(path, destination)
33-
.ifPresent(mods::add);
33+
if (Files.isDirectory(path)) {
34+
if (searchRecursively() && isValidDirectoryName(name)) {
35+
mods.addAll(discoverMods(folder.resolve(name), destination.resolve(name)));
36+
} else if (allowDirectoryMods()) {
37+
discoverFolderMod(path, destination)
38+
.ifPresent(mods::add);
39+
}
3440
} else if (Files.exists(path) && isValidFileName(name)) {
3541
discoverFileMod(path, destination)
3642
.ifPresent(mods::add);

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/remapper/SoftLockFixer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ public static void preloadClasses() {
6868
"fr.catcore.modremapperapi.remapping.VisitorInfos$MethodNamed",
6969
"fr.catcore.modremapperapi.remapping.VisitorInfos$MethodValue",
7070
"fr.catcore.modremapperapi.remapping.VisitorInfos$Type",
71-
"io.github.fabriccompatibiltylayers.modremappingapi.impl.DefaultModEntry",
7271
"io.github.fabriccompatibiltylayers.modremappingapi.impl.DefaultModRemapper",
73-
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModDiscoverer",
74-
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModDiscoverer$1",
75-
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModEntry",
7672
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.resource.RefmapJson",
7773
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.visitor.MixinPostApplyVisitor",
7874
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.asm.MRAClassVisitor",

0 commit comments

Comments
 (0)