-
Bug
-
Resolution: Unresolved
-
None
-
1.21.60.27 Preview, 1.21.60.23 Preview, 1.21.60.21 Preview, 1.21.50.30 Preview, 1.21.50.29 Preview, 1.21.44 Hotfix, 1.21.60.25 Preview, 1.21.60.24 Preview, 1.21.60.28 Preview, 1.21.51 Hotfix
-
None
-
Unconfirmed
-
Multiple
If you cancel a gamemodeChange Event with Script API, the game dosen't correctly cancel the gamemodeChange (probaply a client server gamemode desync)
Steps to reproduce:
- Make a behavior pack with the following Code for the ScriptAPI:
import {world} from "@minecraft/server"; world.beforeEvents.playerGameModeChange.subscribe(eventData => { eventData.cancel = true })
- Go into a world with this code applied or just add the behavior pack GamemodeChangeEvent.mcpack (down below)
- Change youor gamemode
Observed result:
The gamemode changes, but if you were previosly in creative and change it to surviaval your now in survival, but can instamine block and pickblock blocks that you don't have in the inventory or as another example if you change to spectator. Your in spectator, but the chunks reload constantly as if you were constantly switching from spectator to another gamemode
Expected result:
The gamemodeChange should just be canceld
What could be the cause (Speculation):
My speculation to why it is happening is that the server never accepts the gamemodeChange, but the client never becomes a packet that the gamemodeChange was canceled. This is probably why then you change from creativ to survival mobs don't attack you, you can't damage yourself in any way.
After some testing it seems like the servers sends a packet to the client to change the gamemode before it is canceld by the script API, but then its canceld the server never lets the client know
Workaround:
After some testing it turns out the server sends the packet that the gamemode has changed before it was canceld from the script api script so if you just cancel the package with the @minecraft/server-net
beforeEvents.packetSend the player keeps his gamemode and there is no wired behavior