Minecraft – make an invisible block which only people with a specific item can go through

minecraft-commandsminecraft-java-edition

I am currently making a server, and I want to make an invisible block in which only people with a specific item can go through(in this case, a nametag called:key). Is there a command to do so? I am making a server, so plugins will do fine too 🙂

Best Answer

Best way I can think of is teleporting the player backwards if they don't have the key and are in the blocked off area. So you'd use an invisible armor stand to mark the places these "blocks" would be. Then create a scoreboard objective that indicates if the player has the key. Every tick of a fill clock (or, in the 1.9 snapshots, of a repeating command block), you'd reset everyone's score to 0, then set the score to 1 for players who have the correct item in their inventory, as checked by their Inventory data tag (see http://minecraft.gamepedia.com/Player.dat_format#NBT_structure for more information about the format of the Inventory tag). Then you execute on each of your "invisible block" armor stands to /tp every player in radius 0 with a score of 0 back a block or two.