简体   繁体   中英

How to force a gamemode in minecraft mod?

I am making this private modpack in Minecraft. It's all ready, but I need help with making a mod that forces all players to be in gamemode 2 (adventure mode), or just make players unable to place/destroy blocks. How can I make a mod like that?

This is no online server, it is just meant to be in my mod pack in singleplayer. (modpack is a collection of several mods). It is an apocalypse modpack, where players must raid houses, kill NPC players, hide during night etc. This is why I want the player who creates the world, automatically gets set to gamemode 2 (or atleast isn't able to build/destroy). NOTE: I have not created a single mod before, I did not make the mods in my modpack.

Solution 1:

In your server.properties file, there are two options that can do this for you (you don't need a mod). This is also a vanilla thing so even if you switch to a server like spigot/bukkit, canary or plain vanilla, it will still work.

force-gamemode=true
gamemode=2

Solution 2:

You can also use a command block to force all players into a gamemode. If you have this command block going on a clock, all players will change gamemodes instantly apart from you (you must put in your name).

gamemode 2 @a[name=!<insert_your_username_here>]

If you use this method, you must remember to to enable command blocks on your server. This can also be done in the server.properties file by changing enable-command-blocks=true

Edit:

Since you have said it isn't a server, look up some forge mod making tutorials. Wuppy has some good tutorials so check them out: http://www.wuppy29.com/minecraft/modding-tutorials/forge-modding-1-8/

Futhermore: Once you have got the basic mod set up, you will want a player login event that sets a player's gamemode to gamemode 2. The other method would be to deny all block placement and break events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM