Article Categories
- Baldur's Gate 3
- Diablo
- Elder Scrolls
- General
- Hogwarts Legacy
- League of Legends
- Minecraft
- Pokemon Go
- Sims 4
- StarCraft
- Steam Platform
- Xbox Game Console
More Articles
Is there a programmatic way to retrieve a players current gamemode using the @minecraft - server module and WITHOUT using command blocks?
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.
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.
How do I make food in Planet Crafter?
How to get the Operating Profit Graph for the entire game?
Should I turn in sebastion in Hogwarts Legacy?
How can I keep monsters out of my nether regions?
In EVE, What happens to skills in the training queue when an account reverts to alpha clone status?
Will unplucked pikmin be left behind at the end of a day?
Meeting specific person at the end of Life Is Strange Before The Storm
Why does the Tinker aspect only work on some skills in Dead Cells?
Can I use Xbox 360 controllers with Xbox Classic (first generation of Xbox)?
How to download Windows games from Steam onto a Linux computer?


