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]

N++ System Requirements on Mac N++ System Requirements on Mac

Posted On: March 17, 2024
I'm looking at N++ (https://store.steampowered.com/app/230270/N_NPLUSPLUS/) and it doesn't list the system requirements for a mac.This question is not about whether my specific computer can run N++, b...[More]


Broom races vs. type of broom Broom races vs. type of broom

Posted On: September 7, 2023
I got annoyed in previous playthroughs that I would miss the winning time by 10+ seconds or multiple hoops. This playthrough I picked a different broom from Albie Weeks, the one that mentions 'sta...[More]


Is it possible to use NBT tags in commands in Minecraft: Bedrock Edition? Is it possible to use NBT tags in commands in Minecraft: Bedrock Edition?

Posted On: January 19, 2023
This question was split into different questions for each workaround. See these two meta posts for more information.Can you use NBT tags in commands? I’ve tried commands that normally work in J...[More]


Is Wordle always beatable under optimal play? Is Wordle always beatable under optimal play?

Posted On: June 15, 2023
Is Wordle always beatable under optimal play on easy mode (where you can guess any valid word)? To put the question more formally, does there exist a deterministic computer program that can play Wo...[More]


How do I get the space shuttle launch in Gameboy Tetris? How do I get the space shuttle launch in Gameboy Tetris?

Posted On: February 12, 2023
I've been playing Tetris on the virtual Gameboy console on my Nintendo Switch. As a kid, with an actual Gameboy, I remember getting to see a space shuttle launch after doing well enough on an A-Ty...[More]


Can the Haglins Satchel add any orb to your deck? Can the Haglins Satchel add any orb to your deck?

Posted On: December 7, 2023
The description for Haglin's Satchel says it "Randomly adds 2 orbs to your deck, then randomly upgrades orbs 4 times." Are there any limits to which orbs the Haglin's Satchel can ...[More]


Is there an in-world explanation why Aloy needs to learn skills again? Is there an in-world explanation why Aloy needs to learn skills again?

Posted On: April 14, 2023
I just finished playing Horizon: Zero Dawn on PC. While waiting for a PC version of Forbidden West, or ability to buy PlayStation 5, I have read the reviews and it looks like in Forbidden West Aloy ne...[More]


What are decals for in Starcraft 2? What are decals for in Starcraft 2?

Posted On: May 6, 2023
What are the Decals in the rewards section used for? Question from user Erv Walter at gaming.stackexchange.com. Answer: Images of StarCraft II buildings and units with decals:. Answer from...[More]


What happens to the Master Builder when using the Battle Machine? What happens to the Master Builder when using the Battle Machine?

Posted On: July 11, 2023
I haven't unlocked/rebuilt the Battle Machine yet in CoC Builder Base. . Since the Master Builder "operates" the Battle Machine during an attack, can you use the Battle Machine for at...[More]


Does Fallout 4 have a color filter like Fallout 3 and Fallout: New Vegas? Does Fallout 4 have a color filter like Fallout 3 and Fallout: New Vegas?

Posted On: April 22, 2024
Previous 3D Fallout games, Fallout 3 (green) and Fallout: New Vegas (orange), both have a color filter (filter enabled on the left, disabled on the right):.Fallout 3:.New Vegas:.By looking at Fallout ...[More]