1

How do I make command blocks that teleports players away from an area, like 2 blocks or so, repeatedly, when they don't have a specific item? I'm trying to make an adventure map that would require certain items to proceed to the next portion of the map.

I want the command blocks to search players inventory for a diamond. If they have a diamond nothing happens. If they do not have diamond it teleports the player backwards 2 blocks. The issue is the first block is a repeating block that searches the players inventory within 2 block range. The second block is a chain block for testforblock (repeating block) successcount:0. Third block tp's ~ ~ ~2. I want the teleport to happen once unless the player reenters the radius. As it is, it teleports infinitely backwards and I have to disable command blocks to fix it.

9
  • You added the "minecraft-feed-the-beast" tag. Does that mean you're playing with mods? Then you should say that in the question. Commented Nov 15, 2017 at 8:27
  • Can it happen that multiple players are in the area and some have the item, some not, so that only the ones without the item should get teleported? Commented Nov 15, 2017 at 8:38
  • Would it be acceptable for you to update your Minecraft version to one of the latest snapshots? That would make it much easier, but of course they are unstable and buggy, so you might not want to run an important world in it. Commented Nov 15, 2017 at 8:39
  • @Fabian if the tag indicates the mod, then there is no need to also say so in the body. With that said, there are an awful lot of unnecessary tags here =)
    – Oak
    Commented Nov 15, 2017 at 8:53
  • "minecraft" was actually useful, because it indicated the Java Edition. Commented Nov 15, 2017 at 8:57

1 Answer 1

2

This is a good place to use scoreboard tags. This will allow you to tag any player that has diamond and use that tag to target them within the tp command.


Use 3 command blocks in a chain. The first command block removes the tag from all players. The second command block tags any players who have a diamond in their inventory. The third command block teleports any player within the boundaries of the target selector who do not have the tag.

These command blocks have to remain loaded. I recommend putting them in the spawn chunk. I also recommend stopping command block output to prevent chat spam for op players. Use command:

/gamerule commandBlockOutput false

The first command block is RepeatUnconditionalAlways Active with command:

scoreboard players tag @a remove Obtained

The second command block is ChainUnconditionalAlways Active with command:

scoreboard players tag @a add Obtained {Inventory:[{id:"minecraft:diamond"}]}

The Third command block is ChainUnconditionalAlways Active with command:

tp @a[x=X,y=Y,z=Z,r=R,tag=!Obtained] ~ ~ ~2

Replace X, Y, and Z with the coordinates of your gate area. Replace R with the desired radius for that area.

2
  • Thank you for this information its been super helpful!!! Commented Nov 18, 2017 at 4:28
  • Glad I could help. If the answer solved your problem, feel free to accept the answer by clicking the checkmark next to the answer. This lets future visitors with the same problem know that it solved your problem. If it did not solve your problem, I recommend editing your question with the extra details in order to get the exact solution you are looking for.
    – IronAnvil
    Commented Nov 18, 2017 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.