HookLib
HookLib is a specialized framework for creating core mods in the MinecraftForge environment. This solution is primarily aimed at mod developers and provides convenient tools for modifying existing game logic without the need to directly edit the source code.
Main Features
The main goal of the project is to offer a simple way to modify existing functionality through writing additional code. The advantage of HookLib is that working with it does not require deep knowledge of JVM bytecode.
How Hooks Work
When there is a need to modify a specific piece of code (whether it's Minecraft code or another mod's code), you can use the following approach:
@HookContainer
public class MyHooks {
@Hook
@OnBegin
public static void resize(Minecraft mc, int x, int y) {
System.out.println("Window resize, x=" + x + ", y=" + y);
}
}
HookLib will automatically find a method named resize that takes two int arguments in the Minecraft class and will add a call to MyHooks#resize at the beginning of the target method. As a result, a message will appear in the console every time the window size changes.
Getting Started
Adding Dependency
Add to the build.gradle file:
repositories {
maven {
url "https://cursemaven.com"
}
}
dependencies {
implementation "curse.maven:hooklib:12345"
}
VM Parameter Configuration
Add the VM option: -Dfml.coreMods.load=gloomyfolken.hooklib.minecraft.MainHookLoader
Alternatively, through Gradle:
minecraft {
mappings channel: 'snapshot', version: '20171003-1.12'
runs {
client {
workingDirectory project.file('run')
property "fml.coreMods.load", "gloomyfolken.hooklib.minecraft.MainHookLoader"
}
server {
workingDirectory project.file('run')
property "fml.coreMods.load", "gloomyfolken.hooklib.minecraft.MainHookLoader"
}
}
}
After making changes, perform a Gradle refresh in your IDE.
Further Learning
For detailed information about the API and advanced techniques, it is recommended to refer to the project documentation.
Development Roadmap
- [x] Creating HookLib as a core mod loader
- [x] Injection point at method call
- [x] Ability to display available @LocalVariable arguments
- [x] Injection point at expression level
- [x] Access to private variables
- [ ] Portability to new Minecraft versions
- [ ] Annotation processor for compile-time validation
- [ ] Configurations for core mods
- [ ] Caching of target classes with applied hooks