ZReflex is a small Java utility library for advanced reflection and access-modifier tweaks in mixin-based environments for minecraft. It provides:
- A
ZReflectionToolutility with convenient helpers to read/write fields, invoke methods, and instantiate classes (including private members) with assignable type resolution. - A
ZEnumToolutility for dynamically adding or creating Enum constants at runtime. - A
@ModifyAccessannotation plus aModifyAccessTransformermixin plugin that can adjust field/method access modifiers after mixin application.
- Unified reflection helpers for fields, methods, constructors, and modifier checks.
- Optional lookup APIs to avoid exceptions when members are missing.
- Dynamic Enum constant manipulation (add, create instances).
- Mixin plugin that rewrites access flags based on
@ModifyAccessannotations.
repositories {
mavenCentral()
}
dependencies {
implementation "kr.zzik2:zreflex:0.0.3"
}String value = ZReflectionTool.getFieldValue(target, "privateField");
ZReflectionTool.setFieldValue(target, "privateField", "modified");
String result = ZReflectionTool.invokeMethod(target, "methodName", arg1, arg2);
MyType instance = ZReflectionTool.newInstance(MyType.class, "arg");Add a simple Enum constant:
Color yellow = ZEnumTool.addConstant(Color.class, "YELLOW");
// yellow.name() == "YELLOW", yellow.ordinal() == 3 (if 3 existed before)Add an Enum constant with constructor parameters:
// For enums like: enum Size { SMALL(10), MEDIUM(20), LARGE(30); Size(int value) {...} }
Size xxl = ZEnumTool.addConstant(Size.class, "XXL", new Class<?>[] { int.class }, 100);Create an Enum instance without adding to values():
Color temp = ZEnumTool.createInstance(Color.class, "TEMP", 999);
// Color.values() remains unchangedAdd multiple constants at once:
ZEnumTool.addConstants(Color.class, List.of(color1, color2, color3));Note: Enum manipulation relies on JVM internals and is not guaranteed to work in all environments.
- Register the plugin in your
mixin.json:
{
"plugin": "zzik2.zreflex.mixin.ModifyAccessTransformer"
}- Annotate target members in your mixin class:
@ModifyAccess(access = { Opcodes.ACC_PUBLIC }, removeFinal = true)
@Shadow @Final private int someField;You can rename methods or fields at runtime using @ModifyName. This is useful for handling obfuscated names or resolving conflicts.
// Rename 'oldName' to 'newName'
// By default, it attempts to remap 'newName' using the current environment's remapper.
@ModifyName("newName")
@Shadow private void oldName() {}
// Disable remapping if you want to use the exact name provided
@ModifyName(value = "myCustomName", remap = false)
@Shadow private void oldName() {}- Java 11+