#Java reflection: I cant seem to give the player a speed boost upon completing a parkour move

3 messages · Page 1 of 1 (latest)

thorny mural
#

Basically the title. Unfortunately I am pretty new to Java reflection so I cant get it to work. The attached script is attempting to give the player a speed boost upon finishing a parkour move from the mod ParCool. Any help or pointers would be so appreciated, thanks

Here my running script:

// Import Java reflection classes
const Action = Java.loadClass("com.alrex.parcool.common.action.Action");

PlayerEvents.tick(event => {
    const player = event.player;
    
    const actionInstance = player.getCapability('com.alrex.parcool.common.capability.Parkourability').orElse(null);
    
    // Check if the player has completed the parkour move
    if (actionInstance && actionInstance.getClass().getMethod('isDoing').invoke(actionInstance)) {
        const isActionCompleted = !actionInstance.getClass().getMethod('isDoing').invoke(actionInstance);
        
        if (isActionCompleted) {
            // Give the player a speed boost
            player.potionEffects.add('speed', 600, 1); // Speed for 30 seconds (600 ticks)
            
            // Optionally reset the action state
            actionInstance.getClass().getMethod('setDoing', java.lang.Boolean.TYPE).invoke(actionInstance, false);
        }
    }
});

And here is the Github for the ParCool mod that I am trying to work with:

https://github.com/alRex-U/ParCool/blob/main/src/main/java/com/alrex/parcool/common/action/Action.java

GitHub

A Minecraft Forge Mod for action of Cool Parkour. Contribute to alRex-U/ParCool development by creating an account on GitHub.

keen hearthBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

loud locust
#

it's .add(effect, duration, amplifier, ambient, showParticles)