Is there a way to set an "Adventure Mode Boundary" in Minecraft?

Is there a way to set an "Adventure Mode Boundary" in Minecraft? - Modern white automobile riding on empty roadway among green plants at sundown time with sun setting on horizon in summer time

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:

scoreboard objectives add inTown dummy

Now, create a fill clock and run the following commands

scoreboard players set @a inTown 0
scoreboard players set @a[score_inTown=0,x=X1,y=Y1,z=Z1,dx=dX1,dy=dY1,dz=dZ1] inTown 1
scoreboard players set @a[score_inTown=0,x=X",y=Y2,z=Z2,dx=dX2,dy=dY2,dz=dZ2] inTown 1
...
scoreboard players set @a[score_inTown=0,x=XN,y=YN,z=ZN,dx=dXN,dy=dYN,dz=dZN] inTown 1

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:

gamemode 0 @a[score_inTown=0,m=2]
gamemode 2 @a[score_inTown_min=1,m=0]

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 the tellraw or title commands.




Pictures about "Is there a way to set an "Adventure Mode Boundary" in Minecraft?"

Is there a way to set an "Adventure Mode Boundary" in Minecraft? - Assorted autumn leaves lying on wet asphalt road
Is there a way to set an "Adventure Mode Boundary" in Minecraft? - Wooden Bridge on Rainforest
Is there a way to set an "Adventure Mode Boundary" in Minecraft? - Road Between Pine Trees



How do you set an adventure mode area in Minecraft?

How to Enter the Command
  • Open the Chat Window. The easiest way to run a command in Minecraft is within the chat window.
  • Type the Command. In this example, we are going to change the gamemode to Adventure using the following command: /gamemode a. Once the cheat has been entered, the game mode will be updated to Adventure:


  • How do I allow certain blocks to be placed in adventure mode?

    A player can switch to Adventure mode from any other game mode by using the commands /gamemode adventure , /gamemode a , or /gamemode 2 .



    Spawn Protection / Anti-Griefing System | Minecraft Tutorial 1.15 Command




    More answers regarding is there a way to set an "Adventure Mode Boundary" in Minecraft?

    Answer 2

    An easy way to do this would be to set up a command block and an extremely fast clock in the middle of the village that is perpetually setting the game mode of all players within a certain radius (r) of the command block to adventure:

    /gamemode 2 @a[r=??]

    Replace ?? with the radius of the village.

    The problem lies with setting the players' gamemode to survival when they go outside the village. What could work is setting up a different command block on a slower clock that sets the gamemode of anyone in or slightly outside of the village to survival. When that command block activates and a player is inside of the village, the adventure mode command block should immediately reset the player's back to adventure. But if the player were to leave the village, the survival command block would be able to reach the player without interference from the adventure command block (if that makes any sense at all). Here's that command:

    /gamemode s @a[rm=??, r=??+7]

    Replace ??+7 with the radius of the village plus seven, and ?? with the radius of the village.

    That should do the trick. Both commands would need to be run in the same X and Z co-ordinates. Players in the village would obtain survival mode for a split second, but not long enough to do anything.

    Let me know if that helps.

    Answer 3

    An easy version would be this:

    /gamemode survival @a[gamemode=adventure,distance=10..]
    /gamemode adventure @a[gamemode=survival,distance=..10]
    

    Put this into a clock, for example a ticking function (archive), a repeating command block and a chain command block behind it, etc.

    This puts every player into Adventure mode who is 10 blocks or closer and everyone outside that radius into Survival mode. The gamemode restriction in the selector prevents the players to be put into the same gamemode over and over, which would lag the game.

    You'll likely want to restrict it somehow, for example by team.

    Answer 4

    Another way to do it would be to use the Mining Fatigue status effect.

    Here is a command you can use:

    /effect @a[r=???+6] 4 2 255
    

    and put it on a repeating command block.

    This command will give them mining fatigue 255 as long as they are in the specified radius so they cannot break the blocks as long as they are in the range.

    The +6 on the end is so that they cannot break blocks when they step outside the village and try to break from out there.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Erik Mclean, Marta Dzedyshko, Pixabay, veeterzy