Перейти к содержимому
Mineforgian

HookLib

Framework for coremods

Загрузки
541
Подписчики
0
Обновлён
11 февраля 2026 г.
Лицензия
MIT

Опубликован 25 ноября 2024 г.

Introduction

This is framework for coremods at MinecraftForge.

Basicaly, useful for mod developers.

Goal of this project is to provide an easy way to modify existing logic without directly changing code of it, but by writing your additional code.

Doesn't require knowledge of jvm bytecode.

Welp, kinda I'm late with publishing it project, bc Mixins took over the world, but I found out HookLib more handy, and I still have unimplemented good ideas, which will make it even better. So maybe it makes sense

Getting started

Understanding of hooks

When exists some code which you wanna to change, but its part of Minecraft or other mod, you can write something like:

@HookContainer
public class MyHooks {
    @Hook
    @OnBegin
    public static void resize(Minecraft mc, int x, int y) {
        System.out.println("Resize, x=" + x + ", y=" + y);
    }
}

HookLib will find method with name `resize` with two `int`'s arguments in class `Minecraft` and will insert call of MyHooks#resize to begin of found
target method.

Then you will see in console message when window resized.

Adding to project

  • Add dependency to build.gradle:

    repositories { maven { url "https://cursemaven.com" } } dependencies { implementation "curse.maven:hooklib:12345" }

  • Add VM option `-Dfml.coreMods.load=gloomyfolken.hooklib.minecraft.MainHookLoader`

It's possible by gradle too:

minecraft {
    mappings channel: 'snapshot', version: '20171003-1.12'

    runs {
        client {
            workingDirectory project.file('run')
            property "fml.coreMods.load", "gloomyfolken.hooklib.minecraft.MainHookLoader" //here
        }

        server {
            workingDirectory project.file('run')
            property "fml.coreMods.load", "gloomyfolken.hooklib.minecraft.MainHookLoader" //here
        }
    }
}
  • Perform Gradle Refresh in your ide

Next learning

Check our wiki for api details and advanced techniques

Roadmap

  • make HookLib to modloader for coremods

  • injection point at method call

  • way to print possible @LocalVariable arguments

  • injection point at expression

  • way to access to private variables

  • port to new versions of Minecraft

  • annotation processor for compile-time validation

  • configs for coremods

  • caching of target classes with applied hooks

Gratitudes

  • Thanks @GloomyFolken for original HookLib development!
  • Thanks @Foreck for cool logo!

Ченджлог

3.28Релиз1.12.2 · 11 февраля 2026 г.
  • fixed crash on multiple method lenses to same target method
  • fixed @PrintLocalVariables output to consider named parameter id
  • @OnExpression with shift=INSTEAD really remove found expression
  • now possible to use array types, as example at field lenses
  • hybrid mappings support: stable_39 and snaphot_20171003
  • support for multiple hook application, as example mixins can run transformers twice for same target class
  • improve printing of hook when fail to inject
  • support cases of FieldAccessor.defaultValue when value type is subclass of field type
  • added way to access private classes
  • optimized search of suitable hooks for method
3.17Релиз1.12.2 · 13 апреля 2025 г.
  • consider @SideOnly-marked hooks
  • added lenses for accessing methods
  • field lenses:
    • added support for static fields
    • added way to work with primitive fields
    • added way to define default value of created field
    • fix field creation with no FieldLens#createField turned to true
    • consider obfuscation of field names
  • hooklib keep self as last applicable transformer
  • added feature of class dumping which changed by hooklib
  • jars with hooks will be added to classpath like regular coremods
  • added logging to separate file
  • added feature of multiple ordinal's in one hook
  • make @OnMethodCall with shift=INSTEAD more safe with type checks of replaced

Комментарии

Загружаем…