CC: Tweaked

CC: Tweaked

59M Downloads

Allow `GenericSource`s to have instance methods

SquidDev opened this issue · 1 comments

commented

Currently @LuaFunctions from a GenericSource/GenericPeripheral must be static. While this is somewhat logical - generic methods shouldn't reference their instance - it's also a bit odd and limiting at times.

We should instead add support for instance methods from generic sources. The recent generator rewrites (71669cf, d562a05) should now mean we can create a bound MethodHandle and keep the same logic as before.

This probably means we can no longer have a global cache of generated methods, and instead need to regenerate it on each world load. I don't think this is the end of the world - generation only takes 120ms1.

Once doing this, we should add abstract classes (or interfaces) for our generic peripherals, and then have the pre-loader implementations extend that class. This should allow us to ensure a consistent implementation across Forge and Fabric.

Footnotes

  1. And most of that is due to classloading/JIT warmup. A second load only takes 18ms to generate methods.

commented

Done in fe826f5. That was much easier than I thought it'd be.