use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.
the class ForgeModContainer method modConstruction.
@Subscribe
public void modConstruction(FMLConstructionEvent evt) {
List<String> all = Lists.newArrayList();
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
Iterator<String> itr = all.iterator();
while (itr.hasNext()) {
String cls = itr.next();
if (!cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"))
itr.remove();
}
FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "Preloading CrashReport Classes");
//Sort it because I like pretty output ;)
Collections.sort(all);
for (String name : all) {
FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "\t" + name);
try {
Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
} catch (Exception e) {
e.printStackTrace();
}
}
NetworkRegistry.INSTANCE.register(this, this.getClass(), "*", evt.getASMHarvestedData());
ForgeNetworkHandler.registerChannel(this, evt.getSide());
ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.
the class ModAPIManager method registerDataTableAndParseAPI.
public void registerDataTableAndParseAPI(ASMDataTable dataTable) {
this.dataTable = dataTable;
Set<ASMData> apiList = dataTable.getAll("net.minecraftforge.fml.common.API");
apiContainers = Maps.newHashMap();
for (ASMData data : apiList) {
Map<String, Object> annotationInfo = data.getAnnotationInfo();
String apiPackage = data.getClassName().substring(0, data.getClassName().indexOf(".package-info"));
String providedAPI = (String) annotationInfo.get("provides");
String apiOwner = (String) annotationInfo.get("owner");
String apiVersion = (String) annotationInfo.get("apiVersion");
APIContainer container = apiContainers.get(providedAPI);
if (container == null) {
container = new APIContainer(providedAPI, apiVersion, data.getCandidate().getModContainer(), VersionParser.parseVersionReference(apiOwner));
apiContainers.put(providedAPI, container);
} else {
container.validate(providedAPI, apiOwner, apiVersion);
}
container.addOwnedPackage(apiPackage);
for (ModContainer mc : data.getCandidate().getContainedMods()) {
String embeddedIn = mc.getModId();
if (container.currentReferents.contains(embeddedIn)) {
continue;
}
FMLLog.fine("Found API %s (owned by %s providing %s) embedded in %s", apiPackage, apiOwner, providedAPI, embeddedIn);
if (!embeddedIn.equals(apiOwner)) {
container.addAPIReference(embeddedIn);
}
}
}
for (APIContainer container : apiContainers.values()) {
for (String pkg : container.packages) {
Set<ModCandidate> candidates = dataTable.getCandidatesFor(pkg);
for (ModCandidate candidate : candidates) {
List<String> candidateIds = Lists.transform(candidate.getContainedMods(), new ModIdFunction());
if (!candidateIds.contains(container.ownerMod.getLabel()) && !container.currentReferents.containsAll(candidateIds)) {
FMLLog.info("Found mod(s) %s containing declared API package %s (owned by %s) without associated API reference", candidateIds, pkg, container.ownerMod);
container.addAPIReferences(candidateIds);
}
}
}
if (apiContainers.containsKey(container.ownerMod.getLabel())) {
ArtifactVersion owner = container.ownerMod;
do {
APIContainer parent = apiContainers.get(owner.getLabel());
if (parent == container) {
FMLLog.finer("APIContainer %s is it's own parent. skipping", owner);
container.markSelfReferenced();
break;
}
FMLLog.finer("Removing upstream parent %s from %s", parent.ownerMod.getLabel(), container);
container.currentReferents.remove(parent.ownerMod.getLabel());
container.referredMods.remove(parent.ownerMod);
owner = parent.ownerMod;
} while (apiContainers.containsKey(owner.getLabel()));
}
FMLLog.fine("Creating API container dummy for API %s: owner: %s, dependents: %s", container.providedAPI, container.ownerMod, container.referredMods);
}
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.
the class ModAPITransformer method unpackInterfaces.
private Set<ASMData> unpackInterfaces(Set<ASMData> packedInterfaces) {
Set<ASMData> result = Sets.newHashSet();
for (ASMData data : packedInterfaces) {
@SuppressWarnings("unchecked") List<Map<String, Object>> packedList = (List<Map<String, Object>>) data.getAnnotationInfo().get("value");
for (Map<String, Object> packed : packedList) {
ASMData newData = data.copy(packed);
result.add(newData);
}
}
return result;
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.
the class ProxyInjector method inject.
public static void inject(ModContainer mod, ASMDataTable data, Side side, ILanguageAdapter languageAdapter) {
FMLLog.fine("Attempting to inject @SidedProxy classes into %s", mod.getModId());
SetMultimap<String, ASMData> modData = data.getAnnotationsFor(mod);
Set<ASMData> mods = modData.get(Mod.class.getName());
Set<ASMData> targets = modData.get(SidedProxy.class.getName());
ClassLoader mcl = Loader.instance().getModClassLoader();
for (ASMData targ : targets) {
try {
String amodid = (String) targ.getAnnotationInfo().get("modId");
if (Strings.isNullOrEmpty(amodid)) {
amodid = ASMDataTable.getOwnerModID(mods, targ);
if (Strings.isNullOrEmpty(amodid)) {
FMLLog.bigWarning("Could not determine owning mod for @SidedProxy on %s for mod %s", targ.getClassName(), mod.getModId());
continue;
}
}
if (!mod.getModId().equals(amodid)) {
FMLLog.fine("Skipping proxy injection for %s.%s since it is not for mod %s", targ.getClassName(), targ.getObjectName(), mod.getModId());
continue;
}
Class<?> proxyTarget = Class.forName(targ.getClassName(), true, mcl);
Field target = proxyTarget.getDeclaredField(targ.getObjectName());
if (target == null) {
// Impossible?
FMLLog.severe("Attempted to load a proxy type into %s.%s but the field was not found", targ.getClassName(), targ.getObjectName());
throw new LoaderException(String.format("Attempted to load a proxy type into %s.%s but the field was not found", targ.getClassName(), targ.getObjectName()));
}
target.setAccessible(true);
SidedProxy annotation = target.getAnnotation(SidedProxy.class);
String targetType = side.isClient() ? annotation.clientSide() : annotation.serverSide();
if (targetType.equals("")) {
targetType = targ.getClassName() + (side.isClient() ? "$ClientProxy" : "$ServerProxy");
}
Object proxy = Class.forName(targetType, true, mcl).newInstance();
if (languageAdapter.supportsStatics() && (target.getModifiers() & Modifier.STATIC) == 0) {
FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the field is not static", targetType, targ.getClassName(), targ.getObjectName());
throw new LoaderException(String.format("Attempted to load a proxy type %s into %s.%s, but the field is not static", targetType, targ.getClassName(), targ.getObjectName()));
}
if (!target.getType().isAssignableFrom(proxy.getClass())) {
FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the types don't match", targetType, targ.getClassName(), targ.getObjectName());
throw new LoaderException(String.format("Attempted to load a proxy type %s into %s.%s, but the types don't match", targetType, targ.getClassName(), targ.getObjectName()));
}
languageAdapter.setProxy(target, proxyTarget, proxy);
} catch (Exception e) {
FMLLog.log(Level.ERROR, e, "An error occurred trying to load a proxy into %s.%s", targ.getAnnotationInfo(), targ.getClassName(), targ.getObjectName());
throw new LoaderException(e);
}
}
// Allow language specific proxy injection.
languageAdapter.setInternalProxies(mod, side, mcl);
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.
the class MinecraftForge method preloadCrashClasses.
public static void preloadCrashClasses(ASMDataTable table, String modID, Set<String> classes) {
//Find all ICrashReportDetail's handlers and preload them.
List<String> all = Lists.newArrayList();
for (ASMData asm : table.getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
for (ASMData asm : table.getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
all.retainAll(classes);
if (all.size() == 0)
return;
FMLLog.log(modID, Level.DEBUG, "Preloading CrashReport Classes");
//Sort it because I like pretty output ;)
Collections.sort(all);
for (String name : all) {
FMLLog.log(modID, Level.DEBUG, "\t" + name);
try {
Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations