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]

Ask anything Ask anything

Posted On: September 28, 2024
My brother brought it and i am planning on playing it too, but before that i wanted to do this and make fun of it when i finish it so.Question from user Choice_Knowledge_577 at BaldursGate3 at reddit....[More]


Hogwarts dungeons? Hogwarts dungeons?

Posted On: July 14, 2023
So I was on the quest to find the astrolabe and I was just swimming around in the lake and stumbled onto a door that leads to Hogwarts underground. I was new to the game and I didn't explore it mu...[More]


Miraak is stealing all my dragon souls Miraak is stealing all my dragon souls

Posted On: January 15, 2023
After reading the book Waking Dreams and seeing Miraak, I couldn't absorb a dragon's soul. I killed more than 10 dragons and Miraak took all the souls. Is this supposed to happen? Question ...[More]


Professor Layton: are there multiple solutions to Alchemists Lair 08? Professor Layton: are there multiple solutions to Alchemists Lair 08?

Posted On: March 12, 2023
In Professor Layton and the Miracle Mask, are there multiple solutions to the Alchemist's Lair 08 downloadable puzzle? I find that the four flasks in the bottom right corner should be able to b...[More]


Today I learned Today I learned

Posted On: August 29, 2023
That you can simply kill a dugbog by slicing its tongue. Question from user BoosterSeat3 at HogwartsLegacyGaming at reddit. Answer: Yeah! If you keep your eye on the dueling feats, they usual...[More]


Is Bae'zel Green or Yellow? Is Bae'zel Green or Yellow?

Posted On: February 5, 2025
Question from user DearPersimmon8155 at BaldursGate3 at reddit.com.Answer:Yes.Answer from user Toki_mon at BaldursGate3 at reddit.com....[More]


What is the origin of the Qin Shi Huang theme music in Civilization IV? What is the origin of the Qin Shi Huang theme music in Civilization IV?

Posted On: July 10, 2023
I've been trying to identify the music that is heard while one talks diplomacy with Qin Shi Huang in Civilization IV. The melody has been stuck in my head for a while now, and I'd like to k...[More]


Slay The Spire: Does defeating minions reward extra gold? Slay The Spire: Does defeating minions reward extra gold?

Posted On: January 15, 2024
When fighting an Elite Enemy, they can sometimes summon minions to assist them in the fight. Defeating the Elite causes any surviving minions to run away. Will defeating the minions before defeating t...[More]


Do I sell my legendary Kraken cloak in favour of a superb one? Do I sell my legendary Kraken cloak in favour of a superb one?

Posted On: September 24, 2023
My legendary Kraken cloak provides me with 14 defence while my Superb cloak provides me with 18 defence. Should I sell my legendary gear? I’m pretty new to this game, so don’t really know ...[More]


How can I assigning specific depots to trains? How can I assigning specific depots to trains?

Posted On: March 18, 2024
Is there a way to tell a train to which depot it "belongs"? .Because it frequently happens to me, that my trains leave their normal route and head to depots on some other tracks (probably they just h...[More]