Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 2 — Coordinates and Building

What You’ll Build

So far your commands have talked to the game (/say), handed you items (/give), and spawned mobs (/summon). This chapter teaches your commands to shape the world. By the end you’ll be able to type a short sequence that builds a small house out of stone, hollows out the inside, cuts a doorway, lays a floor, decorates it, and finishes with a puff of particles and a little chime. To get there you first need the game’s address system: coordinates, the numbers that name a spot in the world. You’ll learn the three directions the world runs in, how to read your own position off the F3 screen, and three different ways to write a position: one exact, one measured from where you stand, and one measured from where you’re looking. Then you’ll meet the five “world-shaping” commands: /setblock, /fill, /clone, /particle, and /playsound.

Everything happens in your test world (Creative with cheats), the same one you’ve used since Chapter 1.

The three axes: how the world is laid out

Every spot in a Minecraft dimension has an address made of three numbers, written in the order X Y Z. Each number is a distance along one axis, an invisible measuring line that runs through the world. The three axes cross at one spot called the world origin, the place where all three numbers are zero (0 0 0). One step of any axis is exactly one block (one cubic meter), so the numbers are just “how many blocks from the origin.”

Here’s what each axis measures:

  • The X-axis runs east–west. Travel east and your X number goes up (positive); travel west and it goes down (negative).
  • The Z-axis runs north–south. Travel south and your Z number goes up (positive); travel north and it goes down (negative).
  • The Y-axis runs up–down. Climb up and your Y number goes up; go down and it goes down. In the Overworld, Y ranges from -64 at the bottom of the world to 320 at the top, and sea level is Y=63.

So a position like 100 70 -40 means “100 blocks east of the origin, 70 blocks up, and 40 blocks north of the origin.” When you’re reading a set of coordinates, the trick is just to remember the order, X, then Y (the height), then Z, and that the middle number is always the height.

What Went Wrong? “I thought north was the positive direction, like ‘up’ on a graph.” A very natural guess, and a wrong one. Minecraft’s map is turned a quarter-turn from the math-class graph you may have seen: going north makes Z smaller (negative), not bigger. If a build keeps appearing on the wrong side of you, you’ve probably got a Z sign backwards. Face one direction, check F3, and walk a few blocks to see which way the number moves.

Under the Hood Your coordinates are actually the spot at the center of the bottom of your body. When F3 says you’re at Y=63, your feet are at 63.0 and your eyes are a bit higher (about 64.62). You don’t need this number for anything yet. It just explains why “your” Y and the block you’re standing on can differ by a hair. (Skippable.)

Reading your position with F3

To see your own position, press F3 (or Fn+F3 on a Mac or some laptops) to open the F3 debug screen, the overlay of technical text. Look at the upper-left: it shows your current coordinates (your XYZ) and which way you’re facing. It also lists your block position, your coordinates rounded down to whole numbers, which is the actual block you’re standing in (more on that just below).

The F3 screen also swaps your crosshair for a tiny set of colored arrows so you can see which way each axis points: +X is red (east), +Y is green (up), and +Z is blue (south). Whenever you lose track of which way is which, glance at that crosshair.

Figure (to be captured). F3 debug screen with the XYZ line and the colored +X red / +Y green / +Z blue crosshair annotated

Try It! Press F3, note your X, Y, and Z, then walk straight in one direction without turning. Watch which of the three numbers changes and whether it climbs or drops. You’ve just measured which axis you’re walking along. No memorizing required.

Block position: why coordinates round down

Your position can be a decimal, because you stand between whole blocks, but a block itself sits on the whole-number grid. The block position is the coordinates of the lower-northwest corner of a block: the whole numbers you get by rounding the decimal coordinates down. That’s the number the block-placing commands in this chapter use.

One quirk worth knowing because it bites people: rounding down behaves differently on each side of zero. For positive coordinates the block position starts at 0 (so the block from 0.0 up to 0.999… is block 0). For negative coordinates it starts at -1 (the block from -1.0 up to -0.001 is block -1). You don’t have to do this math by hand (F3 prints the block position for you), but it explains why a build can land one block off when you’re working in negative territory.

Three ways to write a position

Every command that takes a position will accept it in any of three styles. Learning all three now means the rest of the chapter (and the rest of the book) just works.

Absolute coordinates: the exact spot

Absolute coordinates are the plain numbers straight off F3: X Y Z measured from the world origin. 100 70 -40 always means that one exact spot in the world, no matter who runs the command or where they’re standing. Use absolute coordinates when you want something to appear in a fixed place: a build that always lands at the same spot.

Relative coordinates with ~ (tilde): “from where I am”

Often you don’t care about the exact spot. You want “right here” or “ten blocks that way from me.” That’s what relative coordinates are for. You write them in tilde notation: a ~ (tilde) before each number means “offset from the command’s current position along that axis.” A number after the tilde is the offset; a lone ~ with no number means an offset of 0 (i.e. “don’t move on this axis”).

  • ~ ~ ~ means the command’s current position, exactly here.
  • ~10 ~ ~-30 means 10 blocks east (+X) and 30 blocks north (–Z) of here, same height.
  • ~ ~5 ~ means 5 blocks straight up from here.

You can even mix tildes with absolute numbers. For example, a teleport to ~ 64 ~ keeps your X and Z exactly where they are but sets your height to an absolute Y of 64.

Relative coordinates are the workhorse of building: type a command with ~ coordinates and it acts around wherever you’re standing right now, instead of one hard-coded spot.

Local coordinates with ^ (caret): “from where I’m looking”

The third style measures from your facing direction instead of the world’s compass. Local coordinates use caret notation: a ^ (caret) before each number. The three carets mean, in order, sideways, up, and forward relative to the way the executor is looking:

  • The first ^ is left/right (left is positive),
  • the second ^ is up/down (up is positive),
  • the third ^ is forward/back (forward, the way you face, is positive).

So ^ ^ ^5 means “5 blocks straight ahead of where I’m looking,” wherever that is. Turn around and run it again and you end up back where you started, because “forward” flipped with you. This is perfect for “place something right in front of the player” effects.

Two rules to keep straight:

  • You can’t mix carets and world coordinates in the same position. Writing something like ^ 0 ^ fails: the game tells you “Cannot mix world & local coordinates.” A position is all carets or no carets.
  • When you have rotation 0 0 (looking due south, level), your local frame happens to line up with the world frame. A handy sanity check.

Under the Hood Pressing F3+B draws a blue ray out of every entity’s head showing its +Z-local (“forward”) direction. If you ever want to see which way “forward” points for a mob, that’s the toggle. (Skippable.)

Modern Minecraft If you’ve watched older build tutorials, you may have only ever seen absolute numbers typed into chat. Relative and local coordinates (~ and ^) are more powerful precisely because the same command works for any player at any location, well beyond the one spot you happened to test it. Think in relative and local coordinates and your builds become reusable: when you later save these commands into command blocks (Chapter 6) and functions (Part III), they’ll already work wherever they run.

/setblock: placing one block

The simplest building command places a single block. Its shape is:

setblock <pos> <block> [destroy|keep|replace|strict]

<pos> is a position (absolute, ~, or ^), <block> is the block to place, and the last word is an optional mode that says how to treat whatever block was already there. The modes are:

  • replace: swap in the new block; the old block drops neither itself nor its contents, and no break sound plays. This is the default if you leave the mode off.
  • destroy: the old block is broken as if a player mined it: it drops itself and its contents, and the breaking sound plays.
  • keep: only place into air; if there’s already a non-air block there, leave it alone.
  • strict: place the block as-is without triggering block updates. (You won’t need this until much later; it’s listed here only so the option isn’t a mystery when you see it.)

Here’s a command that drops a block of gold one space in front of where you’re looking:

/setblock ^ ^ ^1 minecraft:gold_block

Some blocks carry extra settings called block states, written in square brackets right after the block name (we’ll use them as we build from here on). For example, to place a chest already facing east at your feet:

/setblock ~ ~ ~ minecraft:chest[facing=east]

What Went Wrong?/setblock says it failed and nothing happened.” A few honest reasons: the target spot is outside the loaded world; or you tried to place the same block that’s already there (the game skips a pointless no-op); or with keep mode the spot wasn’t air. None of these are bugs. Read the red message and adjust.

/fill: building whole regions at once

/setblock does one block; /fill does a whole rectangular box of them in a single command. You give it two opposite corners and it fills everything in between. Its shape is:

fill <from> <to> <block> [outline|hollow|destroy|strict|replace|keep]
fill <from> <to> <block> replace <filter> [outline|hollow|destroy|strict]

<from> and <to> are any two opposite corners of the box (it doesn’t matter which is which: 0 0 0 to 5 5 5 fills the same box as 5 5 5 to 0 0 0). <block> is what to fill with. The optional mode says how to handle the blocks already there:

  • replace: replace every block in the box (including air) with your block, dropping nothing. This is the default.
  • destroy: replace everything, but drop the old blocks and their contents as items, as if mined.
  • hollow: fill only the outer shell of the box with your block and turn the inside to air. Great for making a room. (If the box is too small to have an inside, it acts like replace.)
  • outline: fill only the outer shell with your block, but leave the inside untouched. Like hollow, but it doesn’t clear what’s already inside.
  • keep: fill only the air blocks in the box, leaving existing blocks alone.
  • strict: place blocks as-is without triggering block updates (an advanced option you can ignore for now).

There’s also a second form with a filter: fill <from> <to> <block> replace <filter> changes only the blocks that match <filter>, leaving the rest as they are. For example, in a 20x10x20 box near you, this turns only orange glazed terracotta into gold, leaving everything else:

/fill ~ ~ ~ ~19 ~9 ~19 minecraft:gold_block replace minecraft:orange_glazed_terracotta

A few worked examples straight from the way /fill is meant to be used. A solid 7x3x7 pool of water just below you:

/fill ~-3 ~-3 ~-3 ~3 ~-1 ~3 minecraft:water

A hollow stone box around you (a house-sized shell, inside cleared to air):

/fill ~-3 ~ ~-4 ~3 ~4 ~4 minecraft:stone hollow

A solid 31x31x31 cube of stone centered on you:

/fill ~-15 ~-15 ~-15 ~15 ~15 ~15 minecraft:stone

What Went Wrong?/fill did nothing on a giant region.” There’s a size cap on how many blocks one command may change, and over-large fills are rejected. There’s a hard ceiling of 655360 blocks, and a gamerule that controls the limit as well. So rather than memorize one exact gamerule value, just know a limit exists: if a huge /fill or /clone refuses to run, break it into smaller boxes. To see the current name of that gamerule on your version, type /gamerule in chat and read it off the suggestion list; the in-game message is always the authority.

/clone: copying a region

/clone copies a box of blocks from one place to another, perfect for duplicating a build. The Java shape you’ll use is:

clone <begin> <end> <destination> [strict] [replace|masked|filtered <filter>] [force|move|normal]

<begin> and <end> are the two opposite corners of the region to copy (the source), exactly like /fill’s corners. <destination> is the lower-northwest corner where the copy is placed. Then come two optional choices:

What to copy (the “mask”):

  • replace: copy all blocks, overwriting everything in the destination. This is the default.
  • masked: copy only the non-air blocks, so the destination’s existing blocks show through where the source had air.
  • filtered <filter>: copy only blocks that match <filter>.

How to treat the source (the “clone mode”):

  • normal: copy and leave the source alone. This is the default.
  • force: allow the copy even if the source and destination regions overlap.
  • move: copy, then replace the source region with air (it “moves” the build).

There’s also a strict option (place as-is, no block updates) you can ignore for now.

A plain copy looks like this. It copies a 5x5x5 box next to you and pastes it 10 blocks east:

/clone ~ ~ ~ ~4 ~4 ~4 ~10 ~ ~

What Went Wrong?/clone failed.” The usual causes: the source and destination overlap (use force if you meant to, or move the destination away); the region is too big (same size limit as /fill); or part of either region isn’t loaded. If you’re cloning right next to the original, overlap is almost always the culprit.

Under the Hood /clone can even copy between dimensions with from <dimension> and to <dimension> forms. That needs the idea of naming a dimension, which we don’t cover until Chapter 44. So for now, clone within one world. (Skippable.)

/particle: visual effects

/particle sprays visual effects (smoke, flames, hearts, sparkles) into the world. They’re purely cosmetic (no gameplay effect), which makes them perfect for marking a spot or celebrating a result. The basic shape is short:

particle <name> [<pos>]

<name> is the particle type (like minecraft:explosion_emitter or minecraft:white_smoke) and the optional <pos> is where to make it, defaulting to your position if you leave it off. So a single explosion ten blocks east of you (cosmetic only) is:

/particle minecraft:explosion_emitter ~10 ~ ~

There’s a longer form for finer control:

particle <name> <pos> <delta> <speed> <count> [force|normal] [<viewers>]

You can mostly read those four numbers as: <count> is how many particles to make, <delta> is how spread out they are around <pos> (bigger numbers = a wider cloud), and <speed> scales how they behave. There’s one neat special case: if <count> is 0, you get a single particle and <delta> becomes its motion (the direction it drifts), with <speed> as a multiplier. The trailing force|normal controls range: normal only shows to nearby players, force pushes the particle to players much farther away and shows it even on low particle settings.

One puff of smoke drifting downward (count is 0, so delta is its motion):

/particle minecraft:white_smoke ^ ^1 ^2 0 -1 0 0.1 0

A whole vertical cloud of smoke (count is 10, so delta is the spread):

/particle minecraft:white_smoke ^ ^1 ^2 0 -1 0 0.1 10

Under the Hood Local coordinates (^) are great for the position of a particle, but <delta> always gets converted to absolute directions internally, so putting ~ or ^ in the delta numbers doesn’t do anything special. Use plain numbers there. (Skippable.)

/playsound: sound effects

/playsound plays a sound for a player. Its Java shape has a lot of optional pieces, but most have sensible defaults:

playsound <sound> [<source>] [<targets>] [<pos>] [<volume>] [<pitch>] [<minVolume>]
  • <sound>: the sound event to play, like entity.pig.ambient. (A sound event is a named entry the game already knows about; one event can pick randomly from several actual sounds, which is why pigs don’t all sound identical. Making your own sound events is a resource-pack topic for Chapter 30; here we use built-in ones.)
  • <source>: the volume category the sound belongs to, which lets players mute it with the right audio slider. It must be one of: master, music, record, weather, block, hostile, neutral, player, ambient, voice, or ui. Defaults to master.
  • <targets>: who hears it. Defaults to the player who ran the command. (We’ll cover picking targets properly in Chapter 3; @s, “me”, is enough here.)
  • <pos>: where the sound comes from. <volume> sets how far it carries (1 ≈ a 16-block radius; bigger numbers widen the range). <pitch> raises or lowers it (above 1 = higher and faster, below 1 = lower and slower; values under 0.5 are treated as 0.5). <minVolume> is the volume for listeners outside the normal range, and defaults to 0.

A simple chime to yourself, a pig oink (source neutral, so the “Friendly Creatures” slider controls it):

/playsound entity.pig.ambient neutral @s

What Went Wrong?/playsound failed even though I’m standing right there.” Two common causes: the target isn’t a player (sounds play to players, not mobs), or nobody could actually hear it: if the listener is outside the volume’s range and you didn’t set a <minVolume> above 0, the command reports failure. Move closer, raise the volume, or set a small minVolume.

Walkthrough: building a house

Now the payoff. You’ll type a short sequence that builds a small stone house around you, using relative ~ coordinates so it appears wherever you’re standing, then decorates it and signals that it’s done. Stand in an open spot in your test world, open chat, and type these lines in order, pressing Enter after each. Each one is described just before it.

The shell: a hollow stone box, 7 wide, 5 tall, 7 deep, with its floor at your feet. hollow fills the outer walls/roof/floor and clears the inside to air:

/fill ~-3 ~ ~-3 ~3 ~4 ~3 minecraft:stone hollow

A wooden floor inside, one layer, just above your feet:

/fill ~-2 ~ ~-2 ~2 ~ ~2 minecraft:oak_planks

Cut a doorway in the south wall, two air blocks tall:

/setblock ~ ~1 ~3 minecraft:air /setblock ~ ~2 ~3 minecraft:air

A glowing block in the ceiling so the room isn’t dark:

/setblock ~ ~4 ~ minecraft:glowstone

A chest in the corner, facing into the room:

/setblock ~2 ~1 ~2 minecraft:chest[facing=west]

A celebratory puff of particles at the center of the room:

/particle minecraft:white_smoke ~ ~2 ~

And a sound so you know the build finished:

/playsound entity.pig.ambient neutral @s

Type those in order and a stone hut springs up around you, floored, lit, with a door and a chest, finished off with a puff of smoke and an oink.

Figure (to be captured). the finished stone house built around the player, with the doorway, glowstone ceiling light, and chest visible

Try It! Change minecraft:stone in the first line to a flashier block (minecraft:quartz_block, minecraft:oak_planks, even minecraft:glass for a greenhouse) and run the sequence again. One word changes the whole look of your house.

Want a second house next door? Stand in the same spot you built the first one from and type this to copy the house you’re standing in and paste an identical one to the east:

/clone ~-3 ~ ~-3 ~3 ~4 ~3 ~5 ~ ~-3

Because the source box (~-3 ~ ~-3 to ~3 ~4 ~3) is exactly the box you filled for the shell, this copies the whole hut. The destination corner ~5 ~ ~-3 puts the copy a few blocks to the east, clear of the original so the regions don’t overlap.

Practice

  1. Make it bigger. Retype the shell line, widening it from ~-3 ... ~3 to ~-5 ... ~5 and raising the roof from ~4 to ~6. Notice you have to widen the floor line to match, or you’ll have a stone rim around your wooden floor.
  2. A window with the filter. Type a line that turns the front wall’s middle blocks into glass using the replace <filter> form, e.g. /fill ~-1 ~2 ~3 ~1 ~3 ~3 minecraft:glass replace minecraft:stone. Because it filters on minecraft:stone, it only changes wall blocks, never your doorway air.
  3. Light it from the front. Type a line that places a torch-like block in front of you with local coordinates: /setblock ^ ^ ^2 minecraft:glowstone. Run it facing different directions and watch the block follow your gaze.
  4. Clone a row of houses. Build a house, then run the clone line twice from the same spot but change the destination each time (~5 ~ ~-3, then ~13 ~ ~-3) to line up three identical huts.
  5. Mark the center. Type a /particle line that drops minecraft:white_smoke particles at ~ ~3 ~ so you can spot the middle of a build at a glance.

What Can Go Wrong

  • Coordinate order mix-ups. It’s always X, Y, Z, and Y is the height. If your build is buried or floating, you almost certainly swapped a number into the wrong slot. F3 prints them in the same X-Y-Z order, so compare directly.
  • Mixing ^ with ~ or plain numbers. A single position must be all caret (^) or no caret. ^ ~2 ^ won’t parse: the game refuses it with a “can’t mix world & local coordinates” message. Pick one style per position.
  • Forgetting hollow and getting a solid block of stone. /fill ... minecraft:stone with no mode defaults to replace, which fills the box solid. If you wanted a room, you need the hollow mode (and remember it clears the inside to air: put your floor and furniture in after).
  • Region too large. Very big /fill or /clone commands are rejected by the block-modification limit. If a giant build silently does nothing, split it into smaller boxes.

What You Know Now

You can now describe the world’s address system: the X (east/west), Y (up/down), and Z (north/south) axes, the origin at 0 0 0, and the Overworld’s Y range from -64 to 320. And you can read your own position straight off the F3 screen. You can write any position three ways: absolute (exact, from the origin), relative with ~ (“from where I am,” a lone ~ meaning no offset on that axis), and local with ^ (“sideways, up, forward, from where I’m looking”). And you can shape the world from the chat box: place one block with /setblock (and its destroy/keep/replace modes), fill and hollow and outline regions with /fill (including the replace <filter> form), copy a build with /clone (replace/masked/filtered, force/move/normal), throw cosmetic /particle effects, and play a built-in sound with /playsound. Best of all, you’ve typed a sequence that constructs and decorates a whole house around you: the first time your commands have built something real in the world.