KubeJS Additions

KubeJS Additions

1M Downloads

[Question] Fabric Event setResult

getBishop opened this issue · 2 comments

commented

MC 1.19.2.

Hi. I'm trying to use this event, but I don't quite understand how to return the result.
UseEntityCallback - requires ActionResult anyway
java.lang.IllegalArgumentException: Arch Event requires a result but was provided none!

// server_scripts
const RESULT = Java.loadClass("net.minecraft.util.ActionResult"); // → Failed to load Java class 'net.minecraft.util.ActionResult': Class could not be found!

FabricEvents.handleServer('UseEntityCallback', e => {
    console.log('Event UseEntityCallback has fired!');
    console.log('Event Args:', e.getArgs());
    console.log('Event Param:', e.getParameters());
    
    e.setResult(RESULT.pass()); //
});
//startup_scripts
const USEENTITYCALLBACK = Java.loadClass('net.fabricmc.fabric.api.event.player.UseEntityCallback');

FabricEvents.registry(event => {
    event.register('UseEntityCallback', USEENTITYCALLBACK, 'EVENT');
});
commented

I think you have the wrong type of Result class loaded at the start of the server script.
It likely needs to be net.minecraft.world.InteractionResult not net.minecraft.util.ActionResult.
At least according to the docs I generated a while back for 1.19.2
https://hunter19823.github.io/kubejsoffline/1.19.2/fabric/#net.fabricmc.fabric.api.event.player.UseEntityCallback
which returns https://hunter19823.github.io/kubejsoffline/1.19.2/fabric/#net.minecraft.world.InteractionResult

commented

I see that searching Google for fabric event shows the ActionResult that you saw (reference).
This likely is a version difference of some kind, which is why I recommend using a tool like KubeJS Offline to generate the exact method signature used at runtime.
It should be more accurate than any online docs since it is generated during the JVM runtime.