Remove mod file scan data deduplicator
This has no effect on newer FML versions since fields are now records
This commit is contained in:
parent
87d1aad3d1
commit
c0eaf29cb5
|
|
@ -1,89 +0,0 @@
|
|||
package org.embeddedt.modernfix.forge.classloading;
|
||||
|
||||
import com.google.common.collect.Interner;
|
||||
import com.google.common.collect.Interners;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||
import net.minecraftforge.forgespi.locating.IModFile;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModFileScanDataDeduplicator {
|
||||
private final Interner<Type> typeInterner = Interners.newStrongInterner();
|
||||
|
||||
private final Function<Type, Type> internerFn = type -> type != null ? typeInterner.intern(type) : null;
|
||||
|
||||
private static Field classClazzField, parentField, interfacesField, annotationClazzField, annotationTypeField;
|
||||
private static final boolean reflectionSuccessful;
|
||||
|
||||
static {
|
||||
boolean success = false;
|
||||
try {
|
||||
classClazzField = ModFileScanData.ClassData.class.getDeclaredField("clazz");
|
||||
classClazzField.setAccessible(true);
|
||||
parentField = ModFileScanData.ClassData.class.getDeclaredField("parent");
|
||||
parentField.setAccessible(true);
|
||||
interfacesField = ModFileScanData.ClassData.class.getDeclaredField("interfaces");
|
||||
interfacesField.setAccessible(true);
|
||||
annotationClazzField = ModFileScanData.AnnotationData.class.getDeclaredField("clazz");
|
||||
annotationClazzField.setAccessible(true);
|
||||
annotationTypeField = ModFileScanData.AnnotationData.class.getDeclaredField("annotationType");
|
||||
annotationTypeField.setAccessible(true);
|
||||
success = true;
|
||||
} catch(ReflectiveOperationException | RuntimeException e) {
|
||||
}
|
||||
reflectionSuccessful = success;
|
||||
}
|
||||
|
||||
ModFileScanDataDeduplicator() {
|
||||
}
|
||||
|
||||
private void runDeduplication() {
|
||||
ModList.get().forEachModFile(this::deduplicateFile);
|
||||
}
|
||||
|
||||
private void deduplicateFile(IModFile file) {
|
||||
ModFileScanData data = file.getScanResult();
|
||||
if(data != null) {
|
||||
data.getClasses().forEach(this::deduplicateClass);
|
||||
data.getAnnotations().forEach(this::deduplicateAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
private void deduplicateClass(ModFileScanData.ClassData data) {
|
||||
try {
|
||||
Type type = (Type)classClazzField.get(data);
|
||||
type = internerFn.apply(type);
|
||||
classClazzField.set(data, type);
|
||||
type = (Type)parentField.get(data);
|
||||
type = internerFn.apply(type);
|
||||
parentField.set(data, type);
|
||||
Set<Type> types = (Set<Type>)interfacesField.get(data);
|
||||
types = types.stream().map(internerFn).collect(Collectors.toSet());
|
||||
interfacesField.set(data, types);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void deduplicateAnnotation(ModFileScanData.AnnotationData data) {
|
||||
try {
|
||||
Type type = (Type)annotationClazzField.get(data);
|
||||
type = internerFn.apply(type);
|
||||
annotationClazzField.set(data, type);
|
||||
type = (Type)annotationTypeField.get(data);
|
||||
type = internerFn.apply(type);
|
||||
annotationTypeField.set(data, type);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deduplicate() {
|
||||
if(!reflectionSuccessful)
|
||||
return;
|
||||
new ModFileScanDataDeduplicator().runDeduplication();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@ import org.embeddedt.modernfix.ModernFix;
|
|||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.entity.EntityDataIDSyncHandler;
|
||||
import org.embeddedt.modernfix.forge.ModernFixConfig;
|
||||
import org.embeddedt.modernfix.forge.classloading.ModFileScanDataDeduplicator;
|
||||
import org.embeddedt.modernfix.forge.config.ConfigFixer;
|
||||
import org.embeddedt.modernfix.forge.config.NightConfigFixer;
|
||||
import org.embeddedt.modernfix.forge.packet.PacketHandler;
|
||||
|
|
@ -51,7 +50,6 @@ public class ModernFixForge {
|
|||
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModernFixConfig.COMMON_CONFIG);
|
||||
PacketHandler.register();
|
||||
ModFileScanDataDeduplicator.deduplicate();
|
||||
ConfigFixer.replaceConfigHandlers();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user