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 benefit does Clash Of Clans upgrading walls have? What benefit does Clash Of Clans upgrading walls have?

Posted On: May 8, 2023
The cost for a level one to level two wall upgrade seems huge - 1000 gold per segment. The upgrade screen displays an increase in hitpoints but is this really noticeable? Can a wall breaker still one ...[More]


Sona-Taric League Of Legends bot lane in Season 9 Sona-Taric League Of Legends bot lane in Season 9

Posted On: May 11, 2023
At the time of writing, the combination of Sona and Taric is extremely powerful in pro play. What is the reasoning and strategy behind professional League teams taking both Sona and Taric bot lane?...[More]


Why is killing Mongrels any different than what the poachers do? Why is killing Mongrels any different than what the poachers do?

Posted On: July 24, 2023
I just find it completely hypocritical to hate the poachers for kidnapping animals, and from our player's POV, we don't even know if they kill them or not. Sorry not everyone has the opportuni...[More]


Is it possible to jump over the flag-pole in Super Mario Bros? Is it possible to jump over the flag-pole in Super Mario Bros?

Posted On: August 16, 2019
When I was younger, I remember there was a persistent rumour that claimed that under certain circumstances it was possible to jump completely over the flagpole at the end of each level. . Every tim...[More]


What are the in-app purchases for Layton and the Diabolical Box on Android? What are the in-app purchases for Layton and the Diabolical Box on Android?

Posted On: March 19, 2023
The Google Play store page for Professor Layton and the Diabolical Box on Android says it contains in-app purchases. I can't find any other mention of them on the store page. What are the in-ap...[More]


Frequency of the Golden Bowser Train? Frequency of the Golden Bowser Train?

Posted On: January 28, 2023
Does anyone happen to know how often you can go to the Golden Bowser Train? For those that don't yet know, it is a level with nothing but coins, and is a great way to bolster your extra lives.Questio...[More]


I cant find Manaphy in Pokemon Legends Arceus I cant find Manaphy in Pokemon Legends Arceus

Posted On: July 13, 2023
I finished all the tasks, even unlocked the cave, but Manaphy isn't there. I already repeated the process many times, he's not there. Any help? Question from user Maria Zapata at stackex...[More]


Anyone else disturbed by Sebastian using imperio on a goblin to make it kill itself? Anyone else disturbed by Sebastian using imperio on a goblin to make it kill itself?

Posted On: August 31, 2023
I'm not usually one for trigger warnings on things, but this was a lot for me. I figured Sebastian would just kill it, but when he forced it to kill itself, it changed the entire tone of the game ...[More]


In A Dark Room, Is there a a reputation system for me among villagers? In A Dark Room, Is there a a reputation system for me among villagers?

Posted On: May 19, 2023
I was wondering if there was a reputation system that makes my villagers love/hate me with things such as choosing whether or not to hang the thief, cure plagues, give to beggars, etc. impacting it. ...[More]


What game is this character on Nintendos eShop from? What game is this character on Nintendos eShop from?

Posted On: April 19, 2024
I've been planning to buy a 3DS and was exploring Nintendo's eShop online and I ran across one of the buttons advertising games with DLC and it has a character that I have never seen before?Does anyon...[More]