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]

Does completing Sly 1 to 100% give anything other than artistic content? Does completing Sly 1 to 100% give anything other than artistic content?

Posted On: July 29, 2023
I completed Sly Cooper and the Thievius Raccoonus from The Sly Collection (PS3). I got the platinum trophy, but the game isn't 100%. I've completed the "Master Thief Sprint" in a cou...[More]


XBox 360 storage device issue with Darksiders XBox 360 storage device issue with Darksiders

Posted On: April 16, 2024
I've been playing Darksiders now for some time now and I've noticed that when I start the game, in the main menu where it says "Press Start", it always triggers me to select a storage device. Why does...[More]


Nexus Mod Manager wont recognize Fallout New Vegas Nexus Mod Manager wont recognize Fallout New Vegas

Posted On: February 8, 2023
I have trouble opening NMM for my New vegas game saying that it does not have the permission to write the game and I've been told that I should run as admin to open it, but :.Can someone please explai...[More]


What are the requirements of these Steam specific achievements? What are the requirements of these Steam specific achievements?

Posted On: September 24, 2023
Most of the hidden achievements in KoA seem to resolve themselves through normal game play (defeat this guy, complete on hard, etc) so I imagine the answer to this one is going to be along the same li...[More]


In PUBG, Where are all the underground bunkers? In PUBG, Where are all the underground bunkers?

Posted On: May 1, 2023
In Player Unknown battlegrounds there's a massive underground bunker in F4 filled with high grade loot. I know from a game where I joined a random squad that there are more underground bunkers as we r...[More]


What is the True Ending in Hogwarts Legacy? What is the True Ending in Hogwarts Legacy?

Posted On: July 19, 2023
What is the True Ending in Hogwarts Legacy after you've completed the main storyline? The answer in this question explains the main storyline endings, but I'm looking for the so-called &quo...[More]


In Hogwarts is how do I get to this chest behind the revolving statues? In Hogwarts is how do I get to this chest behind the revolving statues?

Posted On: February 12, 2023
There are some caves that has these chests behind the revolving statues. Standing on the platform rotates and you end up on the other platform, rather than the other side of the wall. How do I get ...[More]


Stuck with the conjuration curse Stuck with the conjuration curse

Posted On: August 22, 2023
I have got 139/140 conjurations and I am missing the medium constructed decorations. All my collection chests are completed across the maps, I have checked the butterfly missions more than 5 times,...[More]


Attention to detail is awesome! Attention to detail is awesome!

Posted On: September 6, 2023
I’ve spent a lot of time in the Middle East/Africa. There is a non spin-able globe in the headmasters office. Given that the game takes place in 1890, while it’s not 100% perfect, the glob...[More]


In Zelda TOTK, Is it possible to save scum the "Cash In on Ripened Flint" quest? In Zelda TOTK, Is it possible to save scum the "Cash In on Ripened Flint" quest?

Posted On: May 23, 2023
In the Cash In on Ripened Flint side quest Gomo a Gordon in Bedrock Bistro offers 1,000 rupees for a piece of ripened flint. Unfortunately he has to eat (consume) flint to determine if it is of the ri...[More]