Skip to content

Commit

Permalink
Remove AT Remapper since we don't need it in our dev env anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
KorewaLidesu committed Oct 20, 2023
1 parent d1f526a commit d007f18
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 248 deletions.
6 changes: 1 addition & 5 deletions src/main/java/logisticspipes/LogisticsPipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ public LogisticsPipes() { //TODO: remove throws
loadManifestValues(loader);

if (!LogisticsPipesCoreLoader.isCoremodLoaded()) {
if (LogisticsPipes.DEBUG) {
throw new RuntimeException("LogisticsPipes FMLLoadingPlugin wasn't loaded. If you are running MC from an IDE make sure to add '-Dfml.coreMods.load=logisticspipes.asm.LogisticsPipesCoreLoader' to the VM arguments. If you are running MC normal please report this as a bug at 'https://github.com/RS485/LogisticsPipes/issues'.");
} else {
throw new RuntimeException("LogisticsPipes FMLLoadingPlugin wasn't loaded. Your download seems to be corrupt/modified. Please redownload LP from our Jenkins [http://ci.rs485.network] and move it into your mods folder.");
}
throw new RuntimeException("LogisticsPipes FMLLoadingPlugin wasn't loaded. If you are running MC from an IDE make sure to add '-Dfml.coreMods.load=logisticspipes.asm.LogisticsPipesCoreLoader' to the VM arguments. If you are running MC normal please report this as a bug at 'https://github.com/JP-HellParadise/LogisticsPipes/issues'.");
}

try {
Expand Down
70 changes: 0 additions & 70 deletions src/main/java/logisticspipes/asm/LogisticsClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public LogisticsClassTransformer() {

@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
// if dev environment and transform on first class is launched, boot the AT remapper
if (LogisticsPipesCoreLoader.isDevelopmentEnvironment() && name.equals("net.minecraftforge.fml.common.Loader")) bootATRemapper();

Thread thread = Thread.currentThread();
if (thread.getName().equals("Minecraft main thread") || thread.getName().equals("main") || thread.getName().equals("Server thread")) { //Only clear when called from the main thread to avoid ConcurrentModificationException on start
clearNegativeInterfaceCache();
Expand All @@ -103,73 +100,6 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
return ParamProfiler.handleClass(bytes);
}

private void bootATRemapper() {
System.err.println("Fetching ModAccessTransformers");
final List<IClassTransformer> modATs = Launch.classLoader.getTransformers().stream().filter(transformer -> transformer instanceof ModAccessTransformer).collect(Collectors.toList());
System.err.println("Found " + modATs);
if (modATs.size() == 0) return;

System.err.println("Inserting missing ATs from classpath");
try {
readClasspathATs(modATs);
} catch (IllegalStateException e) {
System.err.println("Could not inject classpath FMLATs");
e.printStackTrace();
}

System.err.println("Booting Logistics Pipes ModAccessTransformerRemapper");
final ModAccessTransformerRemapper remapper;
try {
remapper = new ModAccessTransformerRemapper();
} catch (IllegalStateException e) {
System.err.println("Could not initialize ModAccessTransformerRemapper:");
e.printStackTrace();
return;
}

modATs.forEach(remapper::apply);
}

private void readClasspathATs(List<IClassTransformer> modATs) {
final Method readMapFile;
try {
readMapFile = AccessTransformer.class.getDeclaredMethod("readMapFile", String.class);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Could not find method readMapFile on AccessTransformer class", e);
}
final boolean wasAccessible = readMapFile.isAccessible();
if (!wasAccessible) readMapFile.setAccessible(true);
try {
readClasspathATsInner(path -> {
final IClassTransformer classTransformer = modATs.get(0);
try {
readMapFile.invoke(classTransformer, path);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Could not access readMapFile method of " + classTransformer);
}
});
} catch (IOException e) {
throw new IllegalArgumentException("IO Error when fetching FMLATs", e);
} finally {
if (!wasAccessible) readMapFile.setAccessible(false);
}
}

private void readClasspathATsInner(Consumer<String> readMapFile) throws IOException {
final Enumeration<URL> manifestEntries = Launch.classLoader.findResources("META-INF/MANIFEST.MF");
while (manifestEntries.hasMoreElements()) {
final String accessTransformer;
try (InputStream manifestInputStream = manifestEntries.nextElement().openStream()) {
final Manifest manifest = new Manifest(manifestInputStream);
accessTransformer = manifest.getMainAttributes().getValue(ModAccessTransformer.FMLAT);
}
final Enumeration<URL> atEntries = Launch.classLoader.findResources("META-INF/" + accessTransformer);
while (atEntries.hasMoreElements()) {
readMapFile.accept(atEntries.nextElement().toString());
}
}
}

private byte[] applyLPTransforms(String name, byte[] bytes) {
try {
if (name.equals("net.minecraft.tileentity.TileEntity")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LogisticsPipesCoreLoader implements IFMLLoadingPlugin {
private static boolean coremodLoaded = false;
private static boolean developmentEnvironment = false;

public LogisticsPipesCoreLoader() throws Exception {
public LogisticsPipesCoreLoader() {
Launch.classLoader.addTransformerExclusion("logisticspipes.asm.");
coremodLoaded = true;
}
Expand Down
172 changes: 0 additions & 172 deletions src/main/java/logisticspipes/asm/ModAccessTransformerRemapper.java

This file was deleted.

0 comments on commit d007f18

Please sign in to comment.