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]

How to download Windows games from Steam onto a Linux computer? How to download Windows games from Steam onto a Linux computer?

Posted On: November 11, 2023
I recently switched to an Ubuntu computer and the one thing that annoys me is the lack of games available. However I have found a program called WINE which can run Windows applications (.exe) on Linux...[More]


Is there any way to reduce repeated science experiments in KSP? Is there any way to reduce repeated science experiments in KSP?

Posted On: April 10, 2023
There are many science experiments in the game that only give you part of the value whenever you carry them out and retrieve the data. So, even if you rerun the experiment, you only get part of t...[More]


Is it possible to do The Pitt without a slave outfit in Fallout 3? Is it possible to do The Pitt without a slave outfit in Fallout 3?

Posted On: June 19, 2023
I found the slave camp before I found The Pitt guy. I killed the slavers, freed the slaves, talked to The Pitt guy and didn't choose the right dialog options. Then went back to Megaton to do a who...[More]


Does router speed affect ping? Does router speed affect ping?

Posted On: June 11, 2023
I currently own a 150 Mbps router, and I am playing MW3 on PS3 with about 75ms to 100ms ping. Does getting a new 300 Mbps router make a big difference? Would it reduce my lag? Question from user...[More]


How much HP does Ygdar Orus Li Ox revive you with? How much HP does Ygdar Orus Li Ox revive you with?

Posted On: April 12, 2023
The "Ygdar Orus Li Ox" mutation "saves you one time if you die prematurely while not cursed". Do you stay at 1hp when you get saved, or do you get a bit of extra HP so you don'...[More]


What weapons do you associate with certain companions? What weapons do you associate with certain companions?

Posted On: March 17, 2026
So recently I googled "Lae'zel sword" and found two specific greatswords pop up, the soulbreaker sword and the silver sword of the astral plane. Personally, I associate Lae'zel with soulbreaker more, ...[More]


In Hogwarts is it possible to change audio language? In Hogwarts is it possible to change audio language?

Posted On: February 10, 2023
I am playing the Japanese version of Hogwarts Legacy on PC (Steam). The store page says that Hogwarts Legacy has Full Audio support for 8 languages, including Japanese. But, for immersion, I want t...[More]


Which city does chopping production go to in Civilization 6? Which city does chopping production go to in Civilization 6?

Posted On: July 20, 2023
Is the city that owns the tile? (If so, what determines tile ownership? The city that first expanded into that tile? Or if you swap that tile to a 2nd city to work, does that 2nd city work?). Or is...[More]


Will setting your time to April 1st bring back April Fools features on Minecraft? Will setting your time to April 1st bring back April Fools features on Minecraft?

Posted On: February 24, 2023
As most people know Minecraft had an April Fools update that removed the inventory entirely only allowing you to pick up one block/item at a time. I was not able to play on April first though so I ...[More]


What's the most visually satisfying effect or ability? What's the most visually satisfying effect or ability?

Posted On: October 16, 2023
What abilities or effects are the most appealing visually for you? My top contenders divine smite and fireball. Smite especially when it's an unexpected smite on a crit. Not knowing it's co...[More]