1

I have a server that I am working on. I'm trying to make it so when you spawn, you go into gamemode 2 (adventure mode) by using the execute detect commands. I want it so when you spawn on the yellow stained glass block, you are put into adventure mode. This is what I've tried:

/execute @a ~ ~ ~ detect -614 81 -923 minecraft:stained_glass -1 gamemode @p 2

When I tried this the first time it said there was no block called 'stained glass' and the second time it didn't work but it said nothing. Does anyone know what I'm doing wrong?

  • 1
    BTW, I used a command block that was set to Repeat and Always Active. – hakalo Mar 19 '18 at 0:16
  • 2
    What is wrong with this question? I explained it and then showed effort. What more do I need to do? – hakalo Mar 19 '18 at 0:33
  • 1
    You can look up all commands in the Minecraft wiki. – Fabian Röling Mar 19 '18 at 8:15
3

The command that you have will test the coordinate -614 81 -923 for stained glass of any color. It will fail to detect if it is not stained glass. It will fail to execute the gamemode command if there is stained glass.

The first problem is that you are testing static coordinates which has nothing to do with which block the player is standing on. It will always test those coordinates regardless of where the player is. In order to test the block under the player, you must use relative coordinates in the detect portion of the execute command: detect ~ ~-1 ~

For the dataValue argument in the detect portion of the execute command you have used -1 which match any block data. In this case, any color of stained glass. You want to specify the block data for yellow stained glass which is 4.

Another problem is the gamemode command sytax is incorrect. You have placed the target selector before the game mode which is backwards.

Also, you used @p as the target selector. I recommend using @s as the target selector. This will select whichever player is executing the command. In this case, whichever player the execute command tested for the stained glass.

This would leave us with: gamemode adventure @s

Here is a working command with all these corrections:

execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 4 gamemode adventure @s

This leaves out the -614 81 -923 coordinates you had specified in the detect portion of the command which means it would test any player any where in the world. If those coordinates are the world spawn, you would add target selector arguments to the original target selector to include those coordinates as well as a radius:

execute @a[x=-614,y=81,z=-923,r=10] ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 4 gamemode adventure @s

This has been tested and works properly. The last command will test the block below any player within a radius of 10 from -614 81 -923. If it is yellow stained glass, the player's gamemode will change to adventure.

  • Actually, this didn't work. It said: x y and z found nothing – hakalo Mar 25 '18 at 21:21
  • Then, I tried it again, and it said "failed to execute 'detect' as hakalo – hakalo Mar 25 '18 at 21:23
  • That sounds like it is working. The first error means it found no players within the bounds, the second means it did not detect yellow stained glass underneath you. – IronAnvil Mar 26 '18 at 2:26
  • Yeah, but when it said the second one, I was on the yellow stained glass, in that location. So, shouldn't it detect yellow stained glass under me? Also, what should the command block be set to? I set it to Repeat, Unconditional, Always Active. – hakalo Mar 30 '18 at 0:18
  • Repeat, Unconditional, Always Active will work. I am not sure why it didn't work. I just tested the command again and it works properly. – IronAnvil Mar 30 '18 at 4:00
3

The /gamemode command syntax is:

gamemode (mode) (selector)

You put the selector before, instead of after the mode.

If you just want the answer, I believe you could try something along the lines of:

execute @a[x=-614,y=81,z=-923,r=5] ~ ~ ~ detect ~ ~-1 ~ stained_glass color=yellow gamemode adventure @s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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