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]

Act I, Astarion approval high, but romance not triggering? Act I, Astarion approval high, but romance not triggering?

Posted On: October 18, 2024
For the tiefling party my relationship was not high enough and Astarion outright rejected me.I'm still in Act I, just nearing the end of it and I finally got his approval up to high. I hear you can ro...[More]


What does it mean to have sacred - ancestral aspects? What does it mean to have sacred - ancestral aspects?

Posted On: August 15, 2023
As my level increases, I'm starting to find some sacred/ancestral versions of aspects. However, for the vast majority of aspects, it seems to make no difference what version it is. (in fact, th...[More]


Just Happened to Capture this in Hogwarts Legacy Just Happened to Capture this in Hogwarts Legacy

Posted On: June 10, 2023
Question from user BurnDownBabe at HogwartsLegacyGaming at reddit.com. Answer: I dont know if it was my second or third time around in that game, I tried to attack the dugbog. Obviously didnt wo...[More]


How can I complete Desert Snakes in Forza Horizon 5? How can I complete Desert Snakes in Forza Horizon 5?

Posted On: April 3, 2023
I have been trying to complete the challenge in Forza Horizon 5 Rally Adventure, but although the timer starts when I leave Valle de Foráneos, I do not get a waypoint to follow. I have tried...[More]


Do I sell my legendary Kraken cloak in favour of a superb one? Do I sell my legendary Kraken cloak in favour of a superb one?

Posted On: September 24, 2023
My legendary Kraken cloak provides me with 14 defence while my Superb cloak provides me with 18 defence. Should I sell my legendary gear? I’m pretty new to this game, so don’t really know ...[More]


Is there an easier Whistle Sprint Alternative to execute in Tears Of The Kingdom? Is there an easier Whistle Sprint Alternative to execute in Tears Of The Kingdom?

Posted On: July 25, 2023
Whistle Sprinting is a glitch in Breath of the Wild where you hold the whistle button and tap the B button to continuously sprint without draining stamina. In Tears of the Kingdom, this glitch has ...[More]


First time playing Hogwarts Legacy First time playing Hogwarts Legacy

Posted On: July 28, 2023
I haven't played this game yet and I've done a fantastic job at staying away from getting pretty much anything spoiled for me. That being said, what are some things (spoiler free please) that ...[More]


How do I pass the level 7 will find forward puzzle? How do I pass the level 7 will find forward puzzle?

Posted On: June 12, 2023
The objective is to delete all the red outlined characters. . It allows only 12 key presses and you enter from the bridge above (on either n, d or the space after "find)". Leaving the puz...[More]


This is terrible in Hogwarts Legacy This is terrible in Hogwarts Legacy

Posted On: August 10, 2023
I just started playing today and after pretty much playing all day and after getting to the map chamber my computer said low battery so i plugged it in and went and did some stuff and i came back and ...[More]


Does renaming a pokemon to its original name count as a nickname? Does renaming a pokemon to its original name count as a nickname?

Posted On: June 15, 2023
Basically what I actually want to know is, if I rename a Pokémon to its original name and trade it, will the traded Pokémon evolve with its proper evolved Pokémon name or retain i...[More]