Posted April 15, 20214 yr Hello there, I am trying to something a little unconventional... I hope I am right here and this is an allowed question. Basically, I'm working on a sort of wrapper on top of forge - allowing mods for older version to work. The specifics of that shouldn't matter, but I'm looking to improve the way I go about things. To do the heavy lifting, I'm using wrappers - I've spent quite some time on the architecture, and I don't think that's avoidable. However, a lot of the code is redundant and I want to autogenerate it. Let's take the following (pseudocode) example: @Wrapper(Block.class) public interface IBlockWrapper { public void setXYZ(); } I want to generate an implementation for that interface: public class BlockWrapper implements IBlockWrapper { private Block block; public BlockWrapper(Block block) { this.block = block; } public void setXYZ() { // ... } } Currently I generate the classes for the interfaces at runtime using asm and then loading them into the running program. Which is a pretty... terrible approach, actually. What I'm looking for is a way to generate an actual .java class, that a) works in eclipse and b) will be compiled into the finished jar (and properly re-obfuscated to srg) I searched around, and apparently there are Annotation Processors that seem suited, but I am not entirely sure. Could you help point me in the right direction on how to approach that problem? Surely I'm not the first who wants to autogenerate classes. I understand that what I'm doing might sound crazy, but I'd prefer if this doesn't turn into a discussion on why what I'm doing is a bad idea. I just like hacking Minecraft, what should I say. EDIT: For the setup, I want it to work with a clean 1.16.5 forge install (latest version). Using the gradle version and eclipse-generating capabilities that comes with. Once that works, I'll integrate it into my existing code base, and might try to backport it on my own. But the final target should still be 1.16.X. Regards, DarkShadow44 Edited April 17, 20214 yr by DarkShadow44
April 15, 20214 yr Author Thanks, that looks suitable for generating the classes themselves. It's surely better than stitching text together. Although I'd still need a way to hook into the compile process, both with gradle and eclipse. That's my main problem, how would I go about that?
April 17, 20214 yr Author I found a way to handle this, using javapoet as you suggested. For those who are interested in how it works, you can take a look at my sample here: https://github.com/DarkShadow44/compatibilitymod/tree/sourcegen Might not work with eclipse yet, but it builds properly.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.