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]

More questions from an outsider More questions from an outsider

Posted On: October 24, 2023
As I've seen more footage from Baldur's Gate 3 (As an outsider who can't play), I've become curious about a few more things, if people would feel up to answering them for me! . I...[More]


Can I skip the launcher when launching Baldurs Gate 3 from Steam? Can I skip the launcher when launching Baldurs Gate 3 from Steam?

Posted On: July 12, 2023
I don't want to have to go through the "Larian Launcher" when I want to play Baldur's Gate 3 in Steam. How can I skip it? Question from user Oak at stackexchange. Answer: To...[More]


In the Witcher 3, what quests become unavailable after Capture the Castle? In the Witcher 3, what quests become unavailable after Capture the Castle?

Posted On: February 20, 2023
I am up to the main quest "Capture the Castle" in the Blood & Wine DLC. While going to the mission, I got a warning telling me that doing this quest may result in some side quests becomi...[More]


How do Zonaite and Zonai-based materials work together? How do Zonaite and Zonai-based materials work together?

Posted On: June 15, 2023
I am very confused about Zonai-based materials and how they work together to produce bigger/larger things. Specifically:. Zonaite. Zonai Charges. Energy Cells. Zonai Devices. Autobuild ...[More]


In Ben 10 Alien Force, How do you defeat the two huge snakes that come out of the wall? In Ben 10 Alien Force, How do you defeat the two huge snakes that come out of the wall?

Posted On: April 2, 2023
In Ben 10: Alien Force – Vilgax Attacks (Xbox 360), how do you defeat the two huge snakes that come out of the wall? Question from user Bravax at gaming.stackexchange.com. Answer: It se...[More]


Finished Far Cry Primal, but the play through is only at 54.02% Finished Far Cry Primal, but the play through is only at 54.02%

Posted On: August 24, 2023
I just finished Far Cry Primal. I played about 30 hours, and did all the (people) missions. I also build and crafted everything. I conquered all the towers and area's, and tamed all the b...[More]


Why does my PS5 change the screen size sometimes? Why does my PS5 change the screen size sometimes?

Posted On: March 5, 2024
Occasionally when I turn on my PS5 by pressing the controller PS button, the console will not use the full screen size of my TV.Sometimes it's the correct size, let's call that 100%.Sometimes it's sma...[More]


You're his lawyer, defend him You're his lawyer, defend him

Posted On: November 18, 2024
Question from user Gettor at BaldursGate3 at reddit.com.Answer:Your Honor its a well known fact, axiomatic even, that a victim of vampirism is not themselves.The vampire cazador is different from the ...[More]


No reward for vault entrance completion in Hogwarts Legacy? No reward for vault entrance completion in Hogwarts Legacy?

Posted On: July 11, 2023
Some of those puzzles were somewhat difficult, I feel like you should get XP for completion and not just janky gear.  Question from user Pandy_45 at HogwartsLegacyGaming at reddit. Answer: ...[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]