Is there a programmatic way to retrieve a players current gamemode using the @minecraft - server module and WITHOUT using command blocks?

[BACK]
Is there a programmatic way to retrieve a players current gamemode using the @minecraft - server module and WITHOUT using command blocks?
Posted On: March 13, 2024

In my custom tools addon, I've noticed a bug where you can get negative durability values by using the tool in creative mode, then switching to survival mode. This is because while vanilla tools don't take durability damage when used in creative mode, the custom ones do. I'd like to be able to reproduce the vanilla tool functionality by having my decrement-durability function be called conditionally only when the player is not in creative mode.


But, I haven't found any way of detecting which game mode is active within the main.js file.


I'm aware of how to detect players' game modes using command blocks, as discussed in this question, and also how to set the game mode using this command. And, I have found the documentation page for the GameMode enumeration in the @minecraft/server module, which lists all the possible modes. I would have expected there to be a way of finding which one is active, but if so it's not documented there.


There doesn't seem to be a getCurrentGameMode() method or anything similar for either the World or Player classes.


I guess it is probably possible to do something like programmatically place a command block and set its command, then set up a chain command block in 'conditional' mode that places a certain type of block only if the 'test for player in creative mode' command returned true, and then have the script check for that special type of block before replacing all three with air. But, I'd really prefer not to use a workaround like this.


So, is there a way of detecting the active game mode using only script functions, that does not require placing temporary blocks?


Question from user Quack E. Duck at gaming.stackexchange.com.


Answer:

As of @minecraft/server version 1.10.0-beta, it is now possible to access the game mode programmatically using the new .getGameMode() method of the Player object.


Documentation: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/player?view=minecraft-bedrock-experimental#getgamemode.


Answer from user Quack E. Duck at gaming.stackexchange.com.


[BACK]
Is there a programmatic way to retrieve a players current gamemode using the @minecraft - server module and WITHOUT using command blocks?
Posted On: March 13, 2024

In my custom tools addon, I've noticed a bug where you can get negative durability values by using the tool in creative mode, then switching to survival mode. This is because while vanilla tools don't take durability damage when used in creative mode, the custom ones do. I'd like to be able to reproduce the vanilla tool functionality by having my decrement-durability function be called conditionally only when the player is not in creative mode.


But, I haven't found any way of detecting which game mode is active within the main.js file.


I'm aware of how to detect players' game modes using command blocks, as discussed in this question, and also how to set the game mode using this command. And, I have found the documentation page for the GameMode enumeration in the @minecraft/server module, which lists all the possible modes. I would have expected there to be a way of finding which one is active, but if so it's not documented there.


There doesn't seem to be a getCurrentGameMode() method or anything similar for either the World or Player classes.


I guess it is probably possible to do something like programmatically place a command block and set its command, then set up a chain command block in 'conditional' mode that places a certain type of block only if the 'test for player in creative mode' command returned true, and then have the script check for that special type of block before replacing all three with air. But, I'd really prefer not to use a workaround like this.


So, is there a way of detecting the active game mode using only script functions, that does not require placing temporary blocks?


Question from user Quack E. Duck at gaming.stackexchange.com.


Answer:

As of @minecraft/server version 1.10.0-beta, it is now possible to access the game mode programmatically using the new .getGameMode() method of the Player object.


Documentation: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/player?view=minecraft-bedrock-experimental#getgamemode.


Answer from user Quack E. Duck at gaming.stackexchange.com.


[BACK]

is there a Clothing shop in Baldur's gate? is there a Clothing shop in Baldur's gate?

Posted On: October 28, 2023
Im looking for some cool camp clothing. . Im lying, im looking for underwear. I just got to Act 3, Rivington to be exact. Can someone point me to the right direction please? Asking for myself. Or a...[More]


Can you drop bottlecaps in Fallout 4? Can you drop bottlecaps in Fallout 4?

Posted On: July 15, 2023
I've found a few lonely bottlecaps out on the wastelands, but I was wondering if you can get them out of your inventory onto a table to make, say, a bottlecap pyramid. As a bonus question I was al...[More]


Yenna doesn't get enough love. Yenna doesn't get enough love.

Posted On: March 6, 2026
I was going through a few reddit threads to get an idea of whether or not to accept the deals of Orin and Gortash, and whenever someone mentioned the kidnapping, they showed the least care for poor Ye...[More]


I ABSOLUTELY LOVE MY USERNAME!!! I ABSOLUTELY LOVE MY USERNAME!!!

Posted On: November 17, 2024
Love it.Question from user Relative_Pin8485 at BaldursGate3 at reddit.com.Answer:was the typo intentional lol ?Answer from user JamalSteve at BaldursGate3 at reddit.com....[More]


Do companions die in Skyrim? Do companions die in Skyrim?

Posted On: April 11, 2023
It is apparently possible to recruit companions who will fight by your side, carry out simple tasks, and so forth. I have managed to acquire one in the very first village, but have thus far not had hi...[More]


What does shadow cache option exactly do in resident evil 4 remake? What does shadow cache option exactly do in resident evil 4 remake?

Posted On: April 10, 2023
Resident evil 4 remake on PC has the graphics option "shadow cache", what does it exactly do? The comparison picture they provide does not show any difference really. Is it dynamic or for mo...[More]


I hate the Gith so much. Feel sorry for her. I hate the Gith so much. Feel sorry for her.

Posted On: April 25, 2026
Second time doing the Crëche quest. I found something, or rather someone I missed before. This one Tiefling scout whom you meet in the starting area. She warns you to steer clear of the Gith patrol, ...[More]


Am I Locked Out? Romance Question Am I Locked Out? Romance Question

Posted On: April 29, 2024
I was trying to start a love triangle between my Dark Urge, Astarion, and Shadowheart. I slept with Astarion very early on. He was at exceptional approval before we even reached the goblin camp. (And ...[More]


Did anyone did this ? Did anyone did this ?

Posted On: March 19, 2026
This is what I’d did.Question from user EpicCadero at BaldursGate3 at reddit.com.Answer:The grammar got me first, then the editing, and then finally that music. This might be the worst thing Ive cli...[More]


Where is the last red coin in Motos Factory? Where is the last red coin in Motos Factory?

Posted On: March 29, 2024
I am trying to collect the 8 red coins for Motos Factory in B3313 v1.0, but I have only been able to find 7. I've found the following red coins:.At the start of the level behind where you spawn.In the...[More]