Can I make an invisible block which only people with a specific item can go through?

Solution 1:

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.

Solution 2:

How about you make a system that warns the player without the item required (using testfor and stuff) that they can't go through and tp them back if they get in the wanted area of yours.(sr for my english).

Solution 3:

If you were to use a command like so:

/testfor @p[r=2] {Inventory:[{tag:{display:{Name:"key"}}}]}

This will testfor if they have the item somewhere in there inventory

Then if you testfor the item in there inventory, and it activates true, have a sticky piston push a redstone block that changes there gamemode to spectator. Which will allow them to go through the wall: (Here you could use a barrier as your invisible block.)

/gamemode 3 @p

If they leave the radius of 2 then the /testfor command will read false which will deactivate the sticky piston, pulling the redstone block back to activate another command block with the command

/gamemode 2 @p

Or the gamemode you want. It should look like this.enter image description here

If you would like to test for the item in a certain slot in there inventory then you could use a command like this:

/testfor @p[r=2] {SelectedItemSlot:0,Inventory:[{Slot:0b,­tag:{display:{Name:"key"}}}]}

This will test for the "key" in there first slot of there inventory where they hold items.

/give (name) minecraft:barrier (for the invisible wall)