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 do I make food in Planet Crafter? How do I make food in Planet Crafter?

Posted On: April 29, 2024
In The Planet Crafter, I'm building my base, and I have enough food for now. I don't have any machines to make food, but I know I'm going to eventually run out. I guess that, like with water, I'm goin...[More]


How to get the Operating Profit Graph for the entire game? How to get the Operating Profit Graph for the entire game?

Posted On: September 6, 2023
The game shows it only for last few years:. Is it possible to get similar graph for the entire game duration? Question from user ZakiMa at stackexchange. Answer: It's not possible. The...[More]


Should I turn in sebastion in Hogwarts Legacy? Should I turn in sebastion in Hogwarts Legacy?

Posted On: March 16, 2023
I already learned Avada Kedavra so there's no point for me to keep him around just wondering if there are any underlining consequences to doing so, plus he does say whatever happens he's glad ...[More]


How can I keep monsters out of my nether regions? How can I keep monsters out of my nether regions?

Posted On: January 24, 2017
In order to find myself some nice lapis lazuli and get away from my current base, I'm building a little tunnel in the Nether to allow me to get into the midst of some fresh chunks fairly quickly.I hav...[More]


In EVE, What happens to skills in the training queue when an account reverts to alpha clone status? In EVE, What happens to skills in the training queue when an account reverts to alpha clone status?

Posted On: March 9, 2023
I have a bunch of skills queued to train, which includes advanced skills that an Alpha clone cannot train and several skills that are scheduled to start several days out. Since these two conditions ar...[More]


Will unplucked pikmin be left behind at the end of a day? Will unplucked pikmin be left behind at the end of a day?

Posted On: March 31, 2024
In Pikmin 1, if I have Pikmin sprouts I haven't plucked yet, what happens to the unplucked Pikmin when a day ends? Will they be left behind?Question from user Stevoisiak at gaming.stackexchange.com.An...[More]


Meeting specific person at the end of Life Is Strange Before The Storm Meeting specific person at the end of Life Is Strange Before The Storm

Posted On: May 9, 2023
I just ended a game. After the credits, I noticed that there is the possibility of: . Rachel meeting her mother - Sera. I searched the internet for clues on how I can make this happen. I then re...[More]


Why does the Tinker aspect only work on some skills in Dead Cells? Why does the Tinker aspect only work on some skills in Dead Cells?

Posted On: April 12, 2023
The description for the Tinker aspect says "Reduce skill cooldown to 1 sec." In practice the cooldown seems to be unchanged on most abilities I've tried (Infantry Grenade, Pollo Power, Tonic, Face Fla...[More]


Can I use Xbox 360 controllers with Xbox Classic (first generation of Xbox)? Can I use Xbox 360 controllers with Xbox Classic (first generation of Xbox)?

Posted On: November 12, 2023
This is a tricky question and I can't find reliable answer anywhere on the Internet. I love my old Xbox Classic (the first Xbox console from 2001). Unfortunately both my original pads have died...[More]


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]