Minecraft – How to block people getting onto the roof of the Nether in Minecraft

minecraft-commandsminecraft-java-edition

I'm building a Minecraft "War" server where there are 2 teams. Each has a 750×750 area of the Nether to gain resources from. However, I don't want them getting onto the Nether roof and then breaking bedrock to gain access into the other team's side. I can use command blocks and commands.

Best Answer

My method uses scoreboards for detecting position. Since with scoreboards you can execute if a score is in a range.

Note: This will work in a infinite area, and may cause less lag then some other methods

Hovering your mouse over italicized words will give you a short explanation/tooltip

Important: You must be in a Minecraft version of at least 1.13 for this method to work

Preparation

In Minecraft, you need to create a scoreboard objective with a dummy critera. You can do that with the following command.

scoreboard objectives create ypos dummy

After Preparation

Next, you need to have in a Repeating Command Block or a Ticking Function a command that gets the Pos[1] of all players/entities and stores it in our ypos scoreboard. The following command will accomplish that.

execute as @a at @s store result score @s ypos run data get entity @s Pos[1]

If you want it to work for all entities, replace @a with @e. Next, you need a Repeating Command Block or a Ticking Function with a command testing for players that have a ypos score of 122 or more and teleport them to 121 or lower. The following command accomplishes that.

execute as @a[scores={ypos=122..}] at @s run tp ~ 121 ~

Again, if you want this to work with entities, change the @a to @e

Summary

This method stores the ypos of every player/entity in a scoreboard, then checks to see if the ypos value is greater than or equal to 122 and if so, it will teleport them down.