Kirsle.net logo Kirsle.net

Fun with Command Blocks

April 10, 2013 by Noah
It's high time for my first Minecraft mini tutorial!

I tend to prefer playing vanilla Minecraft and try to get away with it as much as I can, and as such I've been electing not to run Bukkit or any other custom servers ever since about Minecraft 1.4 came out.

Minecraft has Command Blocks nowadays, and you can do a lot of creative things with them to replicate the behavior you could get by using Bukkit plugins. I recently started a new "Swampcore" server... the name is borrowed from a popular server on Reddit when they set up a swamp superflat temporarily while they waited for Bukkit plugins to get updated for the latest version of Minecraft.

Their version of Swampcore had you spawn in a small enclosed room, lined with pressure plates by the walls which would teleport you to an unpredictable location within a large radius on the overworld. The idea was to evenly distribute the players, so that people wouldn't build too close to the spawn point and therefore be open to griefing by newly joining players. Also, Swampcore had a 24/7 thunderstorm, which prevents mobs from burning up during the day and even allowed them to spawn in the middle of the day. I've managed to more or less copy all of this behavior using nothing more than the vanilla server, and here's how I did it:

First, the superflat preset I'm using is this:

2;0,49,1,2x7,3,2;6;biome_1,decoration,lake,lava_lake
Put simply, from the bottom up you have: 1 layer of air, 1 layer of obsidian, 1 layer of stone, 2 layers of bedrock, 1 layer of dirt, and 1 layer of grass. It's set in a swamp biome, with lakes and lava lakes, and sometimes the stone blocks (around lava lakes for example, or in the stone layer) might spawn ores.

So, go into creative mode and find the world's spawn point (give yourself a compass and go to where the needle points to, until you get to the point where the needle flips the opposite direction when you cross onto the next block). This is the center of the spawn point.

The server's spawn protection radius should be reasonably large (16 blocks should do). The protection radius basically prevents any users who aren't the operator from being able to change any blocks (destroy or place any). It also prevents them from activating any redstone devices except for pressure plates. They couldn't even open wooden doors in the protection zone.

Build a bunker out of bedrock. Here's what mine looked like:

Screenshot
(Click this and other screenshots for full size versions)

I put an iron door on my bunker and have a stone button that opens it. The button couldn't be activated by a non-operator, and as you'll see shortly, it should be unreasonably difficult for a non-operator to grief your bunker by having a creeper explode next to it.

Screenshot

Inside the bunker, build a redstone circuit designed to run on an infinite loop. I put a bunch of repeaters around, all set to the longest delay (right click 3 times), to keep the loop from bunching up on itself. When you're ready (not yet!), you'll place a redstone torch on the raised bedrock block and then immediately destroy it, so that it's only there long enough to give a quick pulse to the circuit and get it started.

Pro Tip: the 5x5 chunk radius surrounding the spawn point is always loaded in memory. Any redstone circuit that runs there will never be unloaded from memory even if all the players wander far away, so it's a good place to put your infinitely looping circuits that enforce "rules" on your server. The spawn protection radius is icing on the cake as well, as it automatically protects your circuit from being interfered with by other players (note that creepers and TNT launched from outside the protected zone can still damage the protected blocks).

Screenshot

In part of the circuit, make sure the redstone runs over the top of a command block. Use /give <your name> 137 to give yourself a command block to place. You'll definitely need to be an operator and in creative mode to set the command on the block. Hint: you can place redstone on top of the block by holding down the Shift key while you place the redstone.

Screenshot

The command I have here is this:

/tp @a[m=0,r=36] -336 202 179
This command will teleport all Survival Mode players (m=0), within a radius of 36 blocks from this command block, up to the coordinates -336, 202, 179. These coordinates in my case are, the spawn point, 202 blocks up into the sky.

The radius is set to 36 to make sure it fully encompasses the entire spawn region of the server. So anybody who joins the server or dies without a bed, they'll spawn on the surface (probably) within this radius and be immediately sniped up to the teleport spot. Players in Creative Mode are not affected, so that the operator can still get into the bedrock bunker to restart the redstone circuit in case it fails for any reason, or whatever.

Up in the sky above the spawn point, I built this floating room:

Screenshot

The floor of this room is at Y=200... I set the command block on the surface to teleport players to Y=202 just to have them off the floor a little bit. YMMV.

This room is a lot like their Swampcore server. It's a radially symmetrical room (looks the same on all 4 sides) with command blocks surrounding the perimeter. This is so that when you die and respawn and come back to this room, it won't be easy to know which pressure plate you used the last time. Even if you remember you "used the one in the middle", you still only have a 25% chance of guessing the same exact one as last time. The pressure plates are all rigged to command blocks to teleport players to a spot within a large radius, to evenly distribute them across the overworld.

Screenshot

Here is a view of this floating room from above. I put a roof area and a hole to drop down into the room just in case a user happens to spawn on top of the roof, instead of somewhere on the surface near the bedrock bunker. Hey, it happens. Note that since this room is still within the spawn protection zone, the blocks can't be destroyed or altered by the players unless they're operators. And since the room is so high in the air, the odds of getting a creeper up here, or launching TNT into the spawn region from outside to damage the room are extremely low.

Screenshot

Just like with the bedrock bunker, I have an iron door with a stone button for maintenance work (if needed) for the server operator. Even if a survival mode player spawns on the roof and drops down to this door, they can't get inside because of the protection radius.

Screenshot

This is a view from inside the maintenance room, directly below the main spawn room. These are all the command blocks that are positioned underneath the pressure plates above. I placed wooden signs under each command block that tells me the coordinates that the block will teleport you to. I also placed stone buttons on the side of the block (hint: hold down Shift to place the buttons), for testing purposes. Both the button and the pressure plate above will activate the command block.

The commands I used on these blocks are along these lines:

/tp @p 500 7 -1000
This teleports them to Y=7 (the level of the surface in my world), at the X/Y coordinates that are mentioned on the wooden signs below the command block. The @p targets the nearest player, which will usually be the one standing on the pressure plate above.

And that's all there is to it. If players find their way back to the spawn region, they can't get anywhere near the bunker without being teleported back up to the welcome room. The only way they could attack the bunker would be to somehow fling TNT over 36 blocks towards the bunker (an amazing feat in itself), but it being made of bedrock they wouldn't be able to do a whole lot of damage to it. The only way they could attack the welcome room would be to build up a super large tower to the top of the world, build a bridge as close as they're allowed to (within what the spawn protection radius will allow), and then fling TNT from all the way over there. If you set your radius high enough, even this will be highly impractical.

As for the 24-hour thunder storm... you could use another command block down in the bedrock bunker that does /weather thunder to make sure the weather stays tempestuous. Personally, I have a cron job that runs my make-it-rain script every 2 minutes. This is my cron entry for anyone interested:

*/2 * * * * /home/minecraft/bin/make-it-rain swampcore thunder 9000
Tags:

Comments

There are 23 comments on this page. Add yours.

Avatar image
knight81234 posted on August 8, 2013 @ 20:14 UTC

awesome guide dude.

Avatar image
winwil posted on September 3, 2013 @ 16:57 UTC

how to make a working space rocket with command block

Avatar image
Bodhi posted on November 11, 2013 @ 00:40 UTC

What texturepack?

Avatar image
Dwight Reed posted on February 13, 2014 @ 18:33 UTC

cool, it works well-not gettin' greifed no more

Avatar image
Noah (@kirsle) posted on February 13, 2014 @ 21:09 UTC

The texture pack is Sphax PureBDCraft. http://bdcraft.net/

Avatar image
Anonymous posted on March 13, 2014 @ 02:53 UTC

yolo swag

Avatar image
Justin posted on May 25, 2014 @ 01:34 UTC

Hi i am working on a OP only room on a game i am making. to make it so only if you are in creative mode you get tpd into the room, do i basically use the same code? the coords for the space before the door is -1543 63 355. just so you can use my coords if you answer with the correct formatting. i want to tp into the room but only if in creative mode

Avatar image
Mr.Slinky posted on August 27, 2014 @ 14:20 UTC

Hey, I love the blog. I've read most of your stuff. I was wondering if you could show a tutorial on how to make a vanilla command block store. I used to know how to make one and now for some reason I can't find it anywhere. All I remember is you had to have two command blocks the first saying something like xp -(number of xp levels) @p(and then the mininmum level) and then the second command block gave you the item @p(minimum level). Could you please help refresh my memory?

Avatar image
21stReviews posted on November 4, 2014 @ 08:56 UTC

Well, you can read more here http://minecrafters.info/overworld-survival-pack-2-75-minecraft-mini-fully-articulated-action-figure-pack-review/

Avatar image
Doopy posted on November 4, 2014 @ 20:08 UTC

Cool stuffz

Avatar image
guest posted on November 25, 2014 @ 15:09 UTC

last command doesn't work for me

Avatar image
colby m posted on December 10, 2014 @ 19:09 UTC

how do you set coordinates for a block (like tnt) to spawn, i just can figure it out

do you have to do like

summon minecraft:TNT ~(coordinates)

or

summon minecraft: TNT ~(x) ~(y) ~(z)

or what?

Avatar image
Noah (@kirsle) posted on December 10, 2014 @ 19:25 UTC

Commands

/summon <EntityName> [x] [y] [z] [dataTag]

So to summon at a specific coordinate, say X=123, Y=80, Z=456:

/summon PrimedTnt 123 80 456

Or you can prefix any coordinate with a ~ to make it a relative coordinate (relative to the player, if you typed the command directly into chat, or relative to the command block if it was run from a command block). For example, to summon something directly above the command block, 20 blocks up:

/summon PrimedTnt ~ ~20 ~

The ~ value for X and Z means to use the exact same X/Z coordinates as the command block (or player if typed into chat), and the ~20 for Y means +20 coordinates higher than the command block/player. ~-20 would mean -20 (or, 20 blocks lower than the command block/player).

minecraft:tnt isn't an entity name, it's a block name. You can't /summon blocks. What you wanted was probably PrimedTnt which is an entity (it will be a TNT block that's already been activated and is going to explode soon). Use /setblock if you want to place blocks.

/setblock <x> <y> <z> <TileName> [dataValue] [oldBlockHandling] [dataTag]

/setblock 123 60 456 minecraft:tnt 0 replace

Avatar image
Evan posted on January 25, 2015 @ 17:52 UTC

do the commands affect ops in survival?

Avatar image
kyle posted on February 15, 2015 @ 16:14 UTC

/tellraw @a {"text":"","extra":[{"text":"Spectator.","clickEvent":{"action":"run_command","value":"/gamemode 3"}},{"text":"Adventure.","clickEvent":{"action":"run_command","value":"/gamemode 2"}},{"text":"Survival.","clickEvent":{"action":"run_command","value":"/gamemode 0"}},{"text":"Creative","clickEvent":{"action":"run_command","value":"/gamemode 1"}}]} is a command that can let u change your game mode. NOTE: this is only on 1.8

Avatar image
KingSupernova posted on March 6, 2015 @ 03:55 UTC

What is the purpose of having blocks below the bedrock?

Avatar image
Noah (@kirsle) posted on March 6, 2015 @ 04:14 UTC

Some of the lava lakes are pretty deep and will actually "puncture" through the bedrock layer (e.g. the deepest lakes will have parts of the lava that are 4 blocks deep). The terrain generator in Minecraft spawns "structures" such as lava lakes after the first pass of terrain generation, so it overrides the bedrock from the superflat preset.

So this makes it possible to find such a lava lake and therefore find a way beneath the bedrock. I have layers of obsidian and stone down there as a sort of risky (and time consuming) reward for those who get below the bedrock, as they have a higher chance to find ores now, but being at the bottom of the world they have no room to build safe platforms.

Villages and other structures also override the bedrock rule. There was a "Nightcore" server I played on which was something along the lines of: bedrock, few layers of netherrack, some 40 layers of air, then about 11 layers of bedrock, some dirt and snow, and village generation was on. It worked out so that players would spawn on the surface (the snow) with the villages, and village wells were exactly deep enough to puncture ALL the way through the bedrock layers and allow access to the "underworld" below.

I don't remember the exact thickness of the bedrock from that preset but you could probably figure it out after checking how deep a village well goes.

Similarly, the treasure room of desert temples will puncture bedrock too.

Avatar image
meow_guy posted on March 12, 2015 @ 23:12 UTC

did you know: cat squared is banana?

Avatar image
I'm not putting my name in posted on May 5, 2015 @ 00:07 UTC

What was the command

Avatar image
DJsundae posted on August 17, 2015 @ 22:57 UTC

How do you make armour stands move

Avatar image
:))))))) posted on November 5, 2015 @ 12:46 UTC

nice dudeeeeeeeee

Avatar image
mark posted on December 27, 2016 @ 19:03 UTC

whats the code for the command block !!!???

Avatar image
Noah (@kirsle) posted on December 28, 2016 @ 20:35 UTC

@mark:

To give yourself a command block, you should be the server operator and run this command:

/give @p minecraft:command_block

The @p means "the closest player", which will usually be yourself. If you want to give the command block to another player, or just be very specific, use a player's name in its place, like:

/give kirsle minecraft:command_block

Add a Comment

Used for your Gravatar and optional thread subscription. Privacy policy.
You may format your message using GitHub Flavored Markdown syntax.