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]

Why don't I love my Dragonborn as I did my Argonians? Why don't I love my Dragonborn as I did my Argonians?

Posted On: March 22, 2026
I can't pinpoint what it is, but I had a fantastic time playing lizard people in Morrowind, Oblivion and Skyrim. It felt different, fun and interesting. The racial traits didn't matter to me - I just ...[More]


Villager breeder not working, showing angry particles: 1.17.1 Villager breeder not working, showing angry particles: 1.17.1

Posted On: June 15, 2023
I've built a villager breeder following this tutorial: . It worked for a while before it stopped working, as villagers show angry particles whenever they try to breed. I have broken and plac...[More]


Can you play the entire game solo? Can you play the entire game solo?

Posted On: May 28, 2024
Just curious. It seems like it would be impossible with some of the fights but I wonder if it can be done. Like you just use tav and leave all your companions at camp every day?Question from user glit...[More]


How can I complete Desert Snakes in Forza Horizon 5? How can I complete Desert Snakes in Forza Horizon 5?

Posted On: April 3, 2023
I have been trying to complete the challenge in Forza Horizon 5 Rally Adventure, but although the timer starts when I leave Valle de Foráneos, I do not get a waypoint to follow. I have tried...[More]


How do you pet Bubba with a controller? How do you pet Bubba with a controller?

Posted On: August 30, 2023
When playing Holocure on keyboard you can pet Amelia's dog Bubba by pressing P while standing next to him. However, I'm playing on Steam Deck. Is there a way to pet Bubba when playing with a c...[More]


How does the Hard Light Swords damage scale with gun marks? How does the Hard Light Swords damage scale with gun marks?

Posted On: April 7, 2023
The Hard Light Sword's description says it "Deals critical damage depending on the number of gun marks on the target". How exactly does the damage scaling work? How much extra damage get...[More]


Waukeen's rest cannot be saved Waukeen's rest cannot be saved

Posted On: July 12, 2025
Hey all. I've just encountered Waukeen's Rest in my save; where I came through the mountain pass, beat Kith'rak Voss and his fellow githyanki soldiers and finally came upon the burning building. IMMED...[More]


How do you hire a Hacker in Game Dev Story? How do you hire a Hacker in Game Dev Story?

Posted On: April 13, 2024
I'm on my second playthrough of Game Dev Story, choosing the Hire option at least twice per game year and varying between "Word of Mouth", "Magazine Ad", and "Online Ad" — never seen a Hacker availa...[More]


This Just Distracts Me in Hogwarts Legacy This Just Distracts Me in Hogwarts Legacy

Posted On: April 22, 2023
Question from user Ravenclaw-Gamer at HogwartsLegacyGaming at reddit.com. Answer: Started playing God of War: Ragnorok after HL and I’m pressing the revelio everywhere and it’s not w...[More]


Can I play a single-player game alongside a multi-player party without one affecting the other? Can I play a single-player game alongside a multi-player party without one affecting the other?

Posted On: August 7, 2023
I'm already playing a multiplayer game in BG3. What I want to know is. Can i NOW start a singe-player game by clicking NEW GAME on the main menu. If so, will this allow me to play my single-player...[More]