diff --git a/src/main/java/com/blamejared/ModTweaker.java b/src/main/java/com/blamejared/ModTweaker.java index 52dd1c8..dc93678 100644 --- a/src/main/java/com/blamejared/ModTweaker.java +++ b/src/main/java/com/blamejared/ModTweaker.java @@ -1,9 +1,15 @@ package com.blamejared; -import com.blamejared.api.annotations.Handler; +import com.blamejared.api.annotations.*; import minetweaker.MineTweakerAPI; import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.event.*; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.*; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; import static com.blamejared.reference.Reference.*; @@ -11,23 +17,71 @@ import static com.blamejared.reference.Reference.*; public class ModTweaker { @Mod.EventHandler - public void preInit(FMLPreInitializationEvent e) { + public void preInit(FMLPreInitializationEvent e) throws IOException { + File output = new File("output.txt"); + BufferedWriter writer = new BufferedWriter(new FileWriter(output)); + e.getAsmData().getAll(Handler.class.getCanonicalName()).forEach(data -> { try { Class clazz = Class.forName(data.getClassName()); Handler handl = (Handler) clazz.getAnnotation(Handler.class); - if(Loader.isModLoaded(handl.modid())) { + if(Loader.isModLoaded(handl.value())) { MineTweakerAPI.registerClass(clazz); + boolean document = false; + for(Method method : clazz.getDeclaredMethods()) { + if(method.isAnnotationPresent(Document.class)) { + document = true; + } + } + if(document) { + ZenClass zen = (ZenClass) clazz.getAnnotation(ZenClass.class); + writer.write("# " + handl.value() + "\n"); + writer.write("## " + zen.value() + "\n\n"); + + for(Method method : clazz.getDeclaredMethods()) { + if(method.isAnnotationPresent(Document.class)) { + StringBuilder builder = new StringBuilder(); + + Document doc = method.getAnnotation(Document.class); + Map paramMap = new LinkedHashMap<>(); + for(int i = 0; i < method.getParameters().length; i++) { + paramMap.put(doc.value()[i], method.getParameters()[i]); + } + builder.append("//"); + paramMap.forEach((key, val) -> { + if(val.isAnnotationPresent(Optional.class)) { + builder.append(""); + } + builder.append(val.getType().getSimpleName()).append(" ").append(key); + if(val.isAnnotationPresent(Optional.class)) { + builder.append(""); + } + builder.append(", "); + }); + builder.reverse().delete(0, 2).reverse(); + builder.append("\n```"); + builder.append(zen.value()).append("."); + builder.append(method.getName()).append("("); + paramMap.forEach((key, val) -> { + builder.append(val.getType().getSimpleName()).append(" ").append(key).append(", "); + }); + builder.reverse().delete(0, 2).reverse(); + builder.append(");"); + builder.append("```\n"); + writer.write(builder.toString()); + } + } + } } - } catch(ClassNotFoundException e1) { + } catch(ClassNotFoundException | IOException e1) { e1.printStackTrace(); } }); + writer.close(); } @Mod.EventHandler public void init(FMLInitializationEvent e) { - } @Mod.EventHandler diff --git a/src/main/java/com/blamejared/api/annotations/Document.java b/src/main/java/com/blamejared/api/annotations/Document.java new file mode 100644 index 0000000..ddb4068 --- /dev/null +++ b/src/main/java/com/blamejared/api/annotations/Document.java @@ -0,0 +1,9 @@ +package com.blamejared.api.annotations; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Document { + String[] value(); +}