I didn't want to post it in the Minecraft Forge forums because it's not fully completed yet, and for now I've only written it in Kotlin and not yet ported it to Java (it should be pretty easy if you know Kotlin and want to do it yourself), so I'm just showing off the work I've done so far.
I also want to note that this is a giant JVM hack and generally a very bad idea (as I was constantly repeated by a Forge Forums moderator), but boredom is the root of bad ideas and breaking Minecraft sounds like loads of fun, so I certainly don't care
So, without further ado here is the class that allows this dark magic to happen; this class relies on two Java libraries (org.javassist:javassist and com.ea.agentloader:ea-agent-loader) as well as the JDK's attach native library, which must be included in the mod since it's only available in JDK8 but not in JRE8 (I included one for each architecture type); note that not including these will only make your mod work in the development environment.
Please note that by relying on limited a set of native libraries, a mod using this might not be compatible with some - more arcane - architectures or operating systems, like your smartfridge
Using the method redefine utility is very simple: just call one of the public extension methods available (eg: replaceMethodOrFallback) from the desired class, with the SRG name of the method as the first parameter, and a lambda function of your method as second parameter; this (Kotlin) lambda has the same receiver as the original method, and an array of Objects (representing the parameters passed to the function) as second parameter
Here is an usage example, I placed it in my mod class' constructor:
/**
* Replaces the animateTick method inside the TorchBlock class
* This will make torches NOT show flame particles in The End dimension
*/
TorchBlock::class.replaceMethodOrFallback("func_180655_c") {(_, world) ->
if ((world as World).dimension?.type != DimensionType.THE_END) RedefineUtils.fallback()
}
I didn't want to post it in the Minecraft Forge forums because it's not fully completed yet, and for now I've only written it in Kotlin and not yet ported it to Java (it should be pretty easy if you know Kotlin and want to do it yourself), so I'm just showing off the work I've done so far.
I also want to note that this is a giant JVM hack and generally a very bad idea (as I was constantly repeated by a Forge Forums moderator), but boredom is the root of bad ideas and breaking Minecraft sounds like loads of fun, so I certainly don't care
So, without further ado here is the class that allows this dark magic to happen; this class relies on two Java libraries (org.javassist:javassist and com.ea.agentloader:ea-agent-loader) as well as the JDK's attach native library, which must be included in the mod since it's only available in JDK8 but not in JRE8 (I included one for each architecture type); note that not including these will only make your mod work in the development environment.
The class also relies on a small reflection delegate I made (reflectField), but it can be replaced with simple and straightforward reflection.
Please note that by relying on limited a set of native libraries, a mod using this might not be compatible with some - more arcane - architectures or operating systems, like your smartfridge
Using the method redefine utility is very simple: just call one of the public extension methods available (eg: replaceMethodOrFallback) from the desired class, with the SRG name of the method as the first parameter, and a lambda function of your method as second parameter; this (Kotlin) lambda has the same receiver as the original method, and an array of Objects (representing the parameters passed to the function) as second parameter
Here is an usage example, I placed it in my mod class' constructor:
Easier done than said, and Bob's your uncle