Closed thecatcore closed 1 year ago
Do you specifically have a use-case for which allocating a fresh instance and calling a mixed-in initializer method doesn't work?
It's also worth noting that it's not actually possible to add a constructor because they're a source-only concept. Bytecode has initializer methods (<init>
) which contain the code from the relevant constructor, but also copy-pasted versions of every field initializer and non-static initialization block. The copy-pasted bits are impossible to extract without reliable line number information, which Minecraft obviously does not have, so you'd have to remake all the initializers yourself, which is kind of annoying and at that point I don't really see the benefit over the approach I mentioned above. Still curious to see your use-case though, maybe there's something I'm missing.
Well, I'm working on a project called Fabricated-(Legacy-)Forge, which ports Forge into a fabric mod on old mc versions and I''ve successfully ported patches to mixins in 99% case. But some patches add new constructor to some classes, so rn I'm copying the bytecode from the patched forge class and writing it using ASM.
It’s possible to add a constructor to a mixined class by using ASM and visiting the method in a MixinPluginConfig postApply. But you have to write the byte code yourself, I would like to find an easier way to do it.