Skip to content
diskria edited this page Apr 21, 2026 · 23 revisions

I need to start from afar to describe the schema concept. Let's start with an example of methods. Look at this string:

"Lnet/minecraft/world/entity/player/Player;crit(Lnet/minecraft/world/entity/Entity;)V"

This is a long, magical string that's required for the Mixin but completely unreadable and would be an anti-pattern in modern Kotlin development. My goal was to come up with some kind of entity that would contain information from which this string could be deduced during compilation, but at the same time, make it so that the modder would never have to write it manually. The most elegant solution for this in Kotlin is callable references:

val crit = Player::crit

If the method is overloaded, then we need to clarify which one we mean. For this purpose, Kotlin provides us function types:

val crit: Player.(victim: Entity) -> Unit = Player::crit

By using both features together on a consistent basis, we force the compiler to check that the crit is actually non-static method, exists in the Player class, takes single parameter of type Entity, and returns void. Naming function type parameters is optional, but it's a good idea to have a "cheat sheet" for future (what if later you forget that the entity mean?). Also, parameter names are not checked for matching, so you can change the name from your mappings to something you like better.

Before we understand how we can use these references, let's consider the scale of the problem of their absence.

Problem

In standard mixins, you often need to write the same thing in several places. For example, first you want to inject into the head of the method:

@Inject(
    method = "Lnet/minecraft/world/entity/player/Player;crit(Lnet/minecraft/world/entity/Entity;)V",
    at = @At(value = "HEAD")
)
private void doStuff(Entity entity, CallbackInfo ci) {}

Then you will want to change the argument when calling it from another method:

@WrapOperation(
    method = "Lnet/minecraft/world/entity/player/Player;attackVisualEffects(Lnet/minecraft/world/entity/Entity;ZZZZF)V",
    at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;crit(Lnet/minecraft/world/entity/Entity;)V")
)
private void doStuffAgain(Player instance, Entity entity, Operation<Void> original) {}

Then you want to call this method directly in mixin and use @Shadow:

@Shadow
public abstract void crit(Entity entity);

And finally, if you need to call this method from outside the mixin and it is private, then you create an separate class with @Invoker:

@Mixin(Player.class)
interface PlayerAccessor {
    @Invoker("crit")
    void crit(Entity entity);
}

Or you use AW for it (text file outside of code):

accessible method net/minecraft/world/entity/player/Player crit (Lnet/minecraft/world/entity/Entity;)V

This leads to significant code redundancy, as signatures must be manually duplicated across string descriptors (in annotations and AW) and Java code (in injection parameters, @Shadow, and @Invoker methods). Maintaining this is highly inefficient: a single change to the crit method signature in a future Minecraft update would require manual updates in multiple locations, making the codebase fragile and difficult to refactor.

Solution

Single Source of Truth

Lapis.Method

Lapis.Constructor

Lapis.Field

Example

Clone this wiki locally