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]

Where does the name Yiga come from? Where does the name Yiga come from?

Posted On: June 15, 2023
I've been told that the Sheikah race in the Legend of Zelda series were originally named the "Seekers"; when adapted to Japanese phonology that becomes Shiikaa which was transcribed back...[More]


What is the optimum pattern to place crops in Minecraft? What is the optimum pattern to place crops in Minecraft?

Posted On: April 25, 2023
What factors affect soil hydration and crop growth time? What is the most efficient layout of dirt and water to grow crops? Question from user Joe Dovahkiin at gaming.stackexchange.com. Answer: ...[More]


Is there any strategy to 2048 Numberwang? Is there any strategy to 2048 Numberwang?

Posted On: July 22, 2023
I tried out 2048 Numberwang and I can't figure out if there is a strategy to it. Unlike 2048, the numbers keep changing every time you press a key. I just kept randomly pressing the arrow keys unt...[More]


Why is the default dark urge a storm sorcerer? Why is the default dark urge a storm sorcerer?

Posted On: November 7, 2025
Just seems the least likely for a big ass dragon born murderer to be a barbarian or even rogue would have made alot more sense so im just wondering whats the logic behind here.Question from user 24cma...[More]


Is it still possible to start and finish a quest from Chapter 1 after starting Chapter 2? Is it still possible to start and finish a quest from Chapter 1 after starting Chapter 2?

Posted On: July 27, 2023
Baldur's Gate: Enhanced Edition is divided by chapter. When I start Chapter 2, will I still be able to activate quests from Chapter 1? In my journal, all previous chapter quests disappeared after ...[More]


How do you discover combos in Street Fighter V? How do you discover combos in Street Fighter V?

Posted On: April 11, 2023
If I wanted to learn a character in SFV (or any fighting game, really), how should I go about discovering new combos (without the use of videos). Should I be looking at frame data? Question from us...[More]


Does losing to Natsai in the first Charms class matter? Does losing to Natsai in the first Charms class matter?

Posted On: August 11, 2023
Does losing against her make any difference. Also did you win or lose against her your first time? Question from user Kronik95 at HogwartsLegacyGaming at reddit. Answer: I lost to her on m...[More]


How can I give (or sell?) my dwarves mugs in dwarf fortress? How can I give (or sell?) my dwarves mugs in dwarf fortress?

Posted On: April 9, 2023
I've crafted two bins full of mugs, yet I still have dwarves having unhappy thoughts about drinking without mugs. Question from user aslum at gaming.stackexchange.com. Answer: You need an...[More]


Storyline of Hogwarts Legacy Storyline of Hogwarts Legacy

Posted On: April 7, 2023
Did anyone else feel like the storyline of the entire game was too weak? Like I loved the game and its beautiful creation of the world of Hogwarts but the main storyline about the ancient magic, ranro...[More]


Is No Mans Sky actually multiplayer? Is No Mans Sky actually multiplayer?

Posted On: August 7, 2018
I've heard claims that the game is multiplayer, but the universe is so huge you will almost certainly never encounter another player.That seems unlikely. It's a lot of work to make a game multiplayer...[More]