Is there a way to set an "Adventure Mode Boundary" in Minecraft?
I am trying to create this village where players can spawn in, and then set out to explore the world and build and do normal minecraft stuff. I don't want them to destroy this village, so I want them to be in adventure mode when they are in the village and then switch them to survival when they leave, and vice-versa. When they return to the village, they get switched back to adventure mode.
In other words, I want to set an "Adventure Mode Boundary" to protect buildings. I am working without mods. I am hoping there is an simple way using command blocks.
Best Answer
While @BassetHound has given a nice and easy solution, I'd like to provide a more powerful and robust solution, in case the protected area is not adequately described by a sphere of radius R. For example, your server might have a main road that is off-limits, but players are encouraged to build houses next to it, or catacombs beneath.
To do so, we'll set up a scoreboard objective, which will be changed based on the location of the player, allowing us to define the protected area with multiple different commands, thus allowing arbitrary shapes.
Start by setting up the objective itself, let's call it
inTown
:Now, create a fill clock and run the following commands
Each of these will define an area from
(Xn,Yn,Zn)
to(Xn+dXn,Yn+dYn,Zn+dZn)
as part of your town, and set the score for players in that area to 1. If a player is not in any of these areas, his score will remain at 0 instead.Of course, you can use other target selector arguments to define your area as well.
Now, add two commands to the end of your clock to set the gamemodes correctly:
Adding the
m
selector ensures that gamemodes are only set when appropriate. Players in spectator or creative mode are not affected. Just before changing the gamemode, you could use the same target selectors as above to inform your players of the change using thetellraw
ortitle
commands.