Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helper method to ASMDataTable #267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ public void modConstruction(FMLConstructionEvent evt)
}

List<String> all = Lists.newArrayList();
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/')))
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class))
all.add(asm.getClassName());
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/')))
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class))
all.add(asm.getClassName());
// Add table classes for mod list tabulation
all.add("net/minecraftforge/common/util/TextTable");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/minecraftforge/common/MinecraftForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public static void preloadCrashClasses(ASMDataTable table, String modID, Set<Str
{
//Find all ICrashReportDetail's handlers and preload them.
List<String> all = Lists.newArrayList();
for (ASMData asm : table.getAll(ICrashReportDetail.class.getName().replace('.', '/')))
for (ASMData asm : table.getAll(ICrashReportDetail.class))
all.add(asm.getClassName());
for (ASMData asm : table.getAll(ICrashCallable.class.getName().replace('.', '/')))
for (ASMData asm : table.getAll(ICrashCallable.class))
all.add(asm.getClassName());

all.retainAll(classes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public <T> void register(Class<T> type, Capability.IStorage<T> storage, Callable
private IdentityHashMap<String, List<Function<Capability<?>, Object>>> callbacks = Maps.newIdentityHashMap();
public void injectCapabilities(ASMDataTable data)
{
for (ASMDataTable.ASMData entry : data.getAll(CapabilityInject.class.getName()))
for (ASMDataTable.ASMData entry : data.getAll(CapabilityInject.class))
{
final String targetClass = entry.getClassName();
final String targetName = entry.getObjectName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static void register(Class<?> cls, ITypeAdapter adpt)
public static void loadData(ASMDataTable data)
{
FMLLog.log.debug("Loading @Config anotation data");
for (ASMData target : data.getAll(Config.class.getName()))
for (ASMData target : data.getAll(Config.class))
{
String modid = (String)target.getAnnotationInfo().get("modid");
Multimap<Config.Type, ASMData> map = asm_data.computeIfAbsent(modid, k -> ArrayListMultimap.create());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void distributeStateMessage(LoaderState state, Object... eventData)

MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes...");

for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) {
for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class)) {
if (!log) {
MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes...");
log = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,30 @@ public ASMData(ModCandidate candidate, String annotationName, String className,
this.objectName = objectName;
this.annotationInfo = info;
}

public ModCandidate getCandidate()
{
return candidate;
}

public String getAnnotationName()
{
return annotationName;
}

/**
* @return the internal name
*/
public String getClassName()
{
return className;
}

public String getObjectName()
{
return objectName;
}

public Map<String, Object> getAnnotationInfo()
{
return annotationInfo;
Expand Down Expand Up @@ -108,9 +116,9 @@ public boolean apply(ASMData data)
private Map<ModContainer, SetMultimap<String,ASMData>> containerAnnotationData;

private List<ModContainer> containers = Lists.newArrayList();
private SetMultimap<String,ModCandidate> packageMap = HashMultimap.create();
private SetMultimap<String, ModCandidate> packageMap = HashMultimap.create();

public SetMultimap<String,ASMData> getAnnotationsFor(ModContainer container)
public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container)
{
if (containerAnnotationData == null)
{
Expand All @@ -122,9 +130,27 @@ public SetMultimap<String,ASMData> getAnnotationsFor(ModContainer container)
return containerAnnotationData.get(container);
}

public Set<ASMData> getAll(String annotation)
/**
* @param type The canonical name of a annotation type
* Or the internal name of a interface type
* @return the asm datas
*/
public Set<ASMData> getAll(String type)
{
return globalAnnotationData.get(type);
}

/**
* @param type interface of annotation
* @return the asm datas
*/
public Set<ASMData> getAll(Class<?> type)
{
return globalAnnotationData.get(annotation);
if (type.isInterface()) {
return this.getAll(type.getName().replace('.', '/'));
} else if (type.isAnnotation()) {
return this.getAll(type.getName());
} else throw new IllegalArgumentException("The type are trying to be got from ASMDataTable is neither annotation nor interface");
}

public void addASMData(ModCandidate candidate, String annotation, String className, @Nullable String objectName, @Nullable Map<String,Object> annotationInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void inject() {

public void findHolders(ASMDataTable table) {
FMLLog.log.info("Identifying ItemStackHolder annotations");
Set<ASMData> allItemStackHolders = table.getAll(GameRegistry.ItemStackHolder.class.getName());
Set<ASMData> allItemStackHolders = table.getAll(GameRegistry.ItemStackHolder.class);
Map<String, Class<?>> classCache = Maps.newHashMap();
for (ASMData data : allItemStackHolders)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public enum ObjectHolderRegistry
public void findObjectHolders(ASMDataTable table)
{
FMLLog.log.info("Processing ObjectHolder annotations");
Set<ASMData> allObjectHolders = table.getAll(GameRegistry.ObjectHolder.class.getName());
Set<ASMData> allObjectHolders = table.getAll(GameRegistry.ObjectHolder.class);
Map<String, String> classModIds = Maps.newHashMap();
Map<String, Class<?>> classCache = Maps.newHashMap();
for (ASMData data : table.getAll(Mod.class.getName()))
for (ASMData data : table.getAll(Mod.class))
{
String modid = (String)data.getAnnotationInfo().get("modid");
classModIds.put(data.getClassName(), modid);
Expand Down
Loading