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]

How to setup Xbox Series S|X for a family? How to setup Xbox Series S|X for a family?

Posted On: March 7, 2023
I'm new to Xbox and have created an account for me and my children and have linked them to as a family. Will all members of the family be able to play if I login and setup the Xbox with my acco...[More]


How do I check which video clips I've watched in Yakuza 0? How do I check which video clips I've watched in Yakuza 0?

Posted On: March 17, 2023
One of the completion list tasks in Yakuza 0 is to watch 30 different video clips at the erotic video store. Rewatching a clip you've already seen doesn't count. Is there a way to check wha...[More]


Discord mods are power tripping. Discord mods are power tripping.

Posted On: September 9, 2025
I am not invested enough to explain the situation, but if a BG3 dev / mod sees this, it's out of my hands now. Go investigate yourselves. Bye.Question from user Admirable_Maximum524 at BaldursGate3 at...[More]


Why do Pokemon sometimes have dark stripes in Pokemon Go? Why do Pokemon sometimes have dark stripes in Pokemon Go?

Posted On: February 5, 2023
Occasionally I'll face a Charizard or Venusaur in GBL that has dark striping like this:.How do they get those markings, or what is the significance of them?Question from user Lysander at gaming.stacke...[More]


Cannot figure out why the door will not open in Hogwarts Legacy Cannot figure out why the door will not open in Hogwarts Legacy

Posted On: July 17, 2023
I used accio on the handle in the Ranrok evidence search and cannot figure out why the door will not open. I’m worried that I missed something, any suggestions? Question from user Apprehensiv...[More]


How do I disable Civ 5s opening movie? How do I disable Civ 5s opening movie?

Posted On: August 23, 2015
It seems like the opening movie always starts up and won't let me cancel it until it has played for about 10 seconds. Is that because it takes the game that long to load regardless? Is there a way t...[More]


Export a Minecraft Realms world to a locally hosted bedrock server Export a Minecraft Realms world to a locally hosted bedrock server

Posted On: July 12, 2023
I’ve been paying for a Minecraft realm for a while now but now have a static ip and a half decent internet connection so have recently been self hosting a bedrock server myself. Is it possibl...[More]


Is the missable chest in the Mushroom Castle still in the remake? Is the missable chest in the Mushroom Castle still in the remake?

Posted On: November 26, 2023
In the original Super Mario RPG on SNES, there is a missable hidden treasure chest that could only be obtained by jumping on a Toad's head the first time you visit Mushroom Castle. Once you enter ...[More]


What is the Eraser Trick in StarCraft? What is the Eraser Trick in StarCraft?

Posted On: July 4, 2023
What is the eraser trick mentioned in this StarCraft video? Note: This is referring to the 1998 game, not the current game. Question from user C. Ross at stackexchange. Answer: Here's ...[More]


What happens if you break the Old Barbarian Statue in Clash of Clans? What happens if you break the Old Barbarian Statue in Clash of Clans?

Posted On: July 11, 2023
As the title asks, what happens if you break (the original) Old Barbarian Statue in the builders base? I have looked online but there isn't much continuity in what it does. Some sources say you ge...[More]