Skip to content

Commit 47cda10

Browse files
authored
Add Helper method to ASMDataTable (#267)
* add helper and doc * add helper and doc * fix string * err usage * fix
1 parent 7b98551 commit 47cda10

File tree

8 files changed

+41
-14
lines changed

8 files changed

+41
-14
lines changed

src/main/java/net/minecraftforge/common/ForgeModContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ public void modConstruction(FMLConstructionEvent evt)
530530
}
531531

532532
List<String> all = Lists.newArrayList();
533-
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/')))
533+
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class))
534534
all.add(asm.getClassName());
535-
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/')))
535+
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class))
536536
all.add(asm.getClassName());
537537
// Add table classes for mod list tabulation
538538
all.add("net/minecraftforge/common/util/TextTable");

src/main/java/net/minecraftforge/common/MinecraftForge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public static void preloadCrashClasses(ASMDataTable table, String modID, Set<Str
104104
{
105105
//Find all ICrashReportDetail's handlers and preload them.
106106
List<String> all = Lists.newArrayList();
107-
for (ASMData asm : table.getAll(ICrashReportDetail.class.getName().replace('.', '/')))
107+
for (ASMData asm : table.getAll(ICrashReportDetail.class))
108108
all.add(asm.getClassName());
109-
for (ASMData asm : table.getAll(ICrashCallable.class.getName().replace('.', '/')))
109+
for (ASMData asm : table.getAll(ICrashCallable.class))
110110
all.add(asm.getClassName());
111111

112112
all.retainAll(classes);

src/main/java/net/minecraftforge/common/capabilities/CapabilityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public <T> void register(Class<T> type, Capability.IStorage<T> storage, Callable
102102
private IdentityHashMap<String, List<Function<Capability<?>, Object>>> callbacks = Maps.newIdentityHashMap();
103103
public void injectCapabilities(ASMDataTable data)
104104
{
105-
for (ASMDataTable.ASMData entry : data.getAll(CapabilityInject.class.getName()))
105+
for (ASMDataTable.ASMData entry : data.getAll(CapabilityInject.class))
106106
{
107107
final String targetClass = entry.getClassName();
108108
final String targetName = entry.getObjectName();

src/main/java/net/minecraftforge/common/config/ConfigManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void register(Class<?> cls, ITypeAdapter adpt)
106106
public static void loadData(ASMDataTable data)
107107
{
108108
FMLLog.log.debug("Loading @Config anotation data");
109-
for (ASMData target : data.getAll(Config.class.getName()))
109+
for (ASMData target : data.getAll(Config.class))
110110
{
111111
String modid = (String)target.getAnnotationInfo().get("modid");
112112
Multimap<Config.Type, ASMData> map = asm_data.computeIfAbsent(modid, k -> ArrayListMultimap.create());

src/main/java/net/minecraftforge/fml/common/LoadController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ public void distributeStateMessage(LoaderState state, Object... eventData)
170170

171171
FMLContextQuery.init(); // Initialize FMLContextQuery and add it to the global list
172172

173+
173174
// Load late mixins
174175
FMLLog.log.info("Instantiating all ILateMixinLoader implemented classes...");
175-
for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) {
176+
for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class)) {
176177
try {
177178
modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance`
178179
Class<?> clazz = Class.forName(asmData.getClassName().replace('/', '.'));

src/main/java/net/minecraftforge/fml/common/discovery/ASMDataTable.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,30 @@ public ASMData(ModCandidate candidate, String annotationName, String className,
5555
this.objectName = objectName;
5656
this.annotationInfo = info;
5757
}
58+
5859
public ModCandidate getCandidate()
5960
{
6061
return candidate;
6162
}
63+
6264
public String getAnnotationName()
6365
{
6466
return annotationName;
6567
}
68+
69+
/**
70+
* @return the internal name
71+
*/
6672
public String getClassName()
6773
{
6874
return className;
6975
}
76+
7077
public String getObjectName()
7178
{
7279
return objectName;
7380
}
81+
7482
public Map<String, Object> getAnnotationInfo()
7583
{
7684
return annotationInfo;
@@ -108,9 +116,9 @@ public boolean apply(ASMData data)
108116
private Map<ModContainer, SetMultimap<String,ASMData>> containerAnnotationData;
109117

110118
private List<ModContainer> containers = Lists.newArrayList();
111-
private SetMultimap<String,ModCandidate> packageMap = HashMultimap.create();
119+
private SetMultimap<String, ModCandidate> packageMap = HashMultimap.create();
112120

113-
public SetMultimap<String,ASMData> getAnnotationsFor(ModContainer container)
121+
public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container)
114122
{
115123
if (containerAnnotationData == null)
116124
{
@@ -122,9 +130,27 @@ public SetMultimap<String,ASMData> getAnnotationsFor(ModContainer container)
122130
return containerAnnotationData.get(container);
123131
}
124132

125-
public Set<ASMData> getAll(String annotation)
133+
/**
134+
* @param type The canonical name of a annotation type
135+
* Or the internal name of a interface type
136+
* @return the asm datas
137+
*/
138+
public Set<ASMData> getAll(String type)
139+
{
140+
return globalAnnotationData.get(type);
141+
}
142+
143+
/**
144+
* @param type interface of annotation
145+
* @return the asm datas
146+
*/
147+
public Set<ASMData> getAll(Class<?> type)
126148
{
127-
return globalAnnotationData.get(annotation);
149+
if (type.isInterface()) {
150+
return this.getAll(type.getName().replace('.', '/'));
151+
} else if (type.isAnnotation()) {
152+
return this.getAll(type.getName());
153+
} else throw new IllegalArgumentException("The type are trying to be got from ASMDataTable is neither annotation nor interface");
128154
}
129155

130156
public void addASMData(ModCandidate candidate, String annotation, String className, @Nullable String objectName, @Nullable Map<String,Object> annotationInfo)

src/main/java/net/minecraftforge/fml/common/registry/ItemStackHolderInjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void inject() {
4747

4848
public void findHolders(ASMDataTable table) {
4949
FMLLog.log.info("Identifying ItemStackHolder annotations");
50-
Set<ASMData> allItemStackHolders = table.getAll(GameRegistry.ItemStackHolder.class.getName());
50+
Set<ASMData> allItemStackHolders = table.getAll(GameRegistry.ItemStackHolder.class);
5151
Map<String, Class<?>> classCache = Maps.newHashMap();
5252
for (ASMData data : allItemStackHolders)
5353
{

src/main/java/net/minecraftforge/registries/ObjectHolderRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public enum ObjectHolderRegistry
4949
public void findObjectHolders(ASMDataTable table)
5050
{
5151
FMLLog.log.info("Processing ObjectHolder annotations");
52-
Set<ASMData> allObjectHolders = table.getAll(GameRegistry.ObjectHolder.class.getName());
52+
Set<ASMData> allObjectHolders = table.getAll(GameRegistry.ObjectHolder.class);
5353
Map<String, String> classModIds = Maps.newHashMap();
5454
Map<String, Class<?>> classCache = Maps.newHashMap();
55-
for (ASMData data : table.getAll(Mod.class.getName()))
55+
for (ASMData data : table.getAll(Mod.class))
5656
{
5757
String modid = (String)data.getAnnotationInfo().get("modid");
5858
classModIds.put(data.getClassName(), modid);

0 commit comments

Comments
 (0)