Freeze player displacement but not rotation

I wish to freeze a player in place for about 1.25 seconds, but I want to allow them to be able to rotate around.

I put the player uuid into a set to check in a DisplaceEntityEvent.Move.TargetPlayer to see if i freeze them or not…

I am able to trip the event by standing still and rotating - logs show no difference in double-precision numbers. I have tried various combos of things, but might have missed one - resetting the position of ToTransform to be that of FromTransform and cancelling the event, setting the player rotation to be that of the totransform rotation, and location to be that of the totransform, etc. But if i cancel the event, it ignores the changes, and if i let the event go through it doesn’t accept the changes - and i think that setting the position/rotation portions ends up triggering the event again as well.

Anyone have ideas on if its possible to freeze position but allow rotation? This particular event doesn’t have a Cause chain to fish out how it is set either.

Give the player Speed 128 and Jump Boost 128 (128 wraps around to -128).

As in potion effects for both, or settings for one and potion effects for the other? I can try that later today…

I assume both are potion effects, but it does not matter at this point, as potion efects are not yet implimented…

@JBYoshi

Putting aside the non-implimented coding part, i decided to test this via console-commands to at least ‘fill the gap’ as a workaround to test out the rest of the code flow in my plugin…

The jump_boost at 128 does indeed prevent the player from jumping up at all.
But the speed 128 simply turns me into a comic book superhero and after but a press of the movement keys, im way beyond the horizon… I’ve also checked in both the server, and offline (and with a long enough potion effect time overlap in case both were absolutely required) …not offline, but single player with cheat mode…

Identical effects so its not a server difference :frowning:

@TheBoomer You can try using slowness 127 instead of speed 128.

@TheBoomer You were almost there with the event. Try this:

@Listener
public void onPlayerMove(DisplaceEntityEvent.TargetPlayer e) {
    if (shouldFreezePlayer(e.getTargetEntity())) {
        e.setToTransform(e.getFromTransform().setRotation(e.getToTransform().getRotation()));
    }
}
1 Like

Interesting, @simon816 – i cant’ test it out for a while yet, but, is that really it?
No cancelling required to null the position change?

Is the ENTIRE to-transform being re-written to be JUST a rotation? What is happening to the position part of the transform ? It doesn’t really LOOK like it should work…

It works, I tested it.

It may not be clear what it’s doing so I’ll break it down

First thing to note is that Transform is immutable, so methods such as setRotation return copies of the original with a new rotation.
So what I’m basically doing is setting the resultant transform to the previous transform, but using the new rotation
e.getFromTransform().setRotation(e.getToTransform().getRotation()) will return a new transform instance with the same position as FromTransform but using the rotation from ToTransform
Then simply set the event’s ToTransform to the new transform

2 Likes