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]

What is the maximum stamina in Nier Reincarnation? What is the maximum stamina in Nier Reincarnation?

Posted On: April 15, 2024
What is the maximum amount of stamina you can have at once in Nier Reincarnation?Question from user Stevoisiak at gaming.stackexchange.com.Answer:Stamina maxes out at 999. Any stamina gained after rea...[More]


Can I repair my crew during battle? Can I repair my crew during battle?

Posted On: May 20, 2023
I can rearm at the checkpoint, but can I repair my crew? I heard rumors that I can do it, but I haven't found confirmation of this. Any information is welcome. Question from user dos4dev ...[More]


Is there a limit to common boons, and what happens if you reach it? Is there a limit to common boons, and what happens if you reach it?

Posted On: March 27, 2024
In Hades, if you look at the 'normal' boons list, there seems to be 22 slots (4 rows that alternate 5 or 6 slots).Is that 22 limit a hard limit, and if you reach for your 23rd boon, what happens?Quest...[More]


What does the moon icon on a challenge mean? What does the moon icon on a challenge mean?

Posted On: January 26, 2023
Challenge M-015 has a yellow moon icon with a star on it. What does the moon icon mean?Question from user Stevoisiak at gaming.stackexchange.com.Answer:According to IGN, challenges with a crescent moo...[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]


Why do I have to lay the Wii controller on a flat surface? Why do I have to lay the Wii controller on a flat surface?

Posted On: March 24, 2023
When I start Skyward Sword (its the only MotionPlus game I have, others that use it are probably similar) it always asks me to lay the MotionPlus controller on a flat surface for a bit before it start...[More]


What happened to old high scores on the updated Imagine Dragons maps? What happened to old high scores on the updated Imagine Dragons maps?

Posted On: October 19, 2023
Beat Saber v1.28.0 updated the Imagine Dragons Song Pack to change the layouts of existing songs. Surprisingly, it looks like old high scores from the previous versions weren't wiped from the lead...[More]


How to unlock the Science is done by Quantity achievement? How to unlock the Science is done by Quantity achievement?

Posted On: March 19, 2024
The "Science is done by Quantity" achievement has a description that says you need to extract a mission with at least 15 common samples. I've done this with my friend multiple times now, but the achi...[More]


Is there a limit for the waiting queue outside the vault? Is there a limit for the waiting queue outside the vault?

Posted On: December 13, 2023
Inspired by this question i wondered how many Dwellers can wait outside the vault. Even if there is no gameplay limit, what happens when more dwellers are waiting then can be graphically displayed bec...[More]


Why is this Electrolyzer and Hydrogen Generator combo unsustainable? Why is this Electrolyzer and Hydrogen Generator combo unsustainable?

Posted On: April 13, 2024
I have this small Electrolyzer + Hydrogen Generator setup in my base:.The Electrolyzer says it generates 112 g/s of Hydrogen, while the Hydrogen Generator states it needs 100g/s of Hydrogen to functio...[More]