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 most feasible option to play (almost) all Zelda games? What is the most feasible option to play (almost) all Zelda games?

Posted On: January 23, 2023
Given the timeline list of games on The Legend of Zelda - Wikipedia, what would be the most feasible option to preferably legally play all (or a vast majority of) the games in the series? These are...[More]


How can I tell if a corpse is safe to eat? How can I tell if a corpse is safe to eat?

Posted On: July 9, 2020
I am a human wizard, and I just killed a monster, leaving a corpse on the ground. How do I tell whether it is safe to eat the corpse? I left the monster unspecified because I am interested in "...[More]


Why will she not take Panteas Flute? Why will she not take Panteas Flute?

Posted On: January 17, 2023
I found Pantea's Flute before the quest was given to me. Now she will not accept it from me, and it says I still need to go find it. What do I do now? Is this a glitch? I have the game on PC if th...[More]


Is there a minecraft command to become immune to damage? Is there a minecraft command to become immune to damage?

Posted On: July 4, 2023
Is there any minecraft command to become completely immune to damage? Question from user Pika Supports Ukraine at stackexchange. Answer: This command will make you invulnerable to most types ...[More]


Does over-completing challenges earn extra XP in Mario Golf GBC? Does over-completing challenges earn extra XP in Mario Golf GBC?

Posted On: March 17, 2024
When doing side quests in Mario Golf for Game Boy Color, you are often given challenges to complete a task a certain number of times with a set number of attempts. You can keep playing after completin...[More]


Can I save Burmano from Himself in Zelda Tears of the Kingdom? Can I save Burmano from Himself in Zelda Tears of the Kingdom?

Posted On: June 22, 2023
Darling Burmano is the in-house chef for Lookout Landing, and very early in my adventure, he asked for an apple. After completing this quest, the next time I returned to Lookout Landing, the Chef was ...[More]


Floo Flames in Hogwarts Legacy Floo Flames in Hogwarts Legacy

Posted On: March 24, 2023
LoL anybody else in here make it a point to visit every last floo flame on the map shortly after u got ur broom? I'm like 16 hours into the game and barely %25 done with the game  Question...[More]


Progression through WoW that avoids spiders Progression through WoW that avoids spiders

Posted On: April 18, 2024
Background: My girlfriend is terrified of spiders. So much so that she cringes and closes her eyes whenever there are spiders on my screen, even if I'm not fighting them. I'm now introducing her to ...[More]


Dueling in Hogwarts Legacy Dueling in Hogwarts Legacy

Posted On: August 28, 2023
EDIT Thank you to everyone who commented with your advice! I admit I started getting frustrated and my bf had to take over as PVP isn't usually my thing in video games! (I usually do Minecraft, st...[More]


How can you run Skyrim in borderless window mode? How can you run Skyrim in borderless window mode?

Posted On: April 6, 2023
I've noticed Skyrim has some issues when minimizing. This is a real pain when playing on multiple monitors and you attempt to find something on the other monitor. Is there anyway to enable borderl...[More]