/say @a[score_cookie_min=1] has been given 5 cookies.
/give @a[score_cookie_min=1] minecraft:cookie 5
第四個指令方塊的指令
/scoreboard players set @a[score_cookie_min=1] cookie 0
"I" 代表輸入紅石訊號端。(建議可使用循環紅石電路)
也可以用
/give @r cookie 1
傳送
你可以透過使用/tp x y z來傳送。其中y表示上下方向的移動,x和z表示前後和左右方向的移動,玩家可以透過這個指令傳送到(x y z)這一個座標的位置。如果要以目前站的位置為標準進行傳送的話就只要在x y z前面加上一個~即可,例如/tp ~x ~y ~z。如果當玩家位於(x y z)座標為(-36 96 -12)的時候輸入/tp @p ~3 ~4 ~5,這時他會被傳送到(-33 100 -7)這個座標,和玩家輸入/tp @p -34 100 -8是一個效果。
他也可以被用於傳送(例如一個遙遠的要塞,在地下挖礦,或者在一個浮天空島世界)。 如果他需要你花了很長時間才能到達那裏,然後你不介意他是一種軟作弊, 這樣你可以建立起一個傳送系統。請確保你在設定指令方塊的時候是創造模式(請使用 gamemode 1。 如果你并没有开启作弊选项,打开局域网模式设置打开作弊),但你还是可以在生存模式中使用它。在打开的命令方块的界面中输入tp @p x y z 。 然后, 用红石 (包括按钮,拉杆,压力板)激活这个命令方块,然后你就会被送到远处的目的地。你可以建立多种不同的传送器。这也可以用于跨越大面积的大型项目,或者如果您将箱子从旧房子转移到新房子。
使用 /spawnpoint 可以直接設定重生點,但是要跳過白天就需要 /time set <时间> 指令,18000為夜晚(並非絕對,可以按喜好設定,不要少於12500),這樣就可以模擬出睡覺的效果了。(可用/time set 700 直接轉為白天,/spawnpoint指令和/time set 700配合不就行了麼?)
/say指令非常有用因為它可以直接給玩家發送訊息. 用指令方塊將會更好,這樣你就不需要放很多的告示牌和編頁碼長到不行的書來告訴玩家遊戲規則. 你只需要把指令方塊放成一條線然後在中間鋪中繼器來弄各個語段之間的延遲(so the player isn't spammed)接著你就可以把那堆告示牌和放著書的儲物箱移走。
最後但並非最不重要,他可以更容易的建立一個任務系統。來讓我們的玩家開始進行廝殺。 他透過壓力板啟動了RS NOR鎖存器 (所以他不能被再次啟動) 然後一個有 /say指令的指令方塊去滿足屠夫對玩家的要求。他需要去殺一隻豬 (他真可恥)。 玩家到達站在石制壓板上的豬,當豬死了時就會關閉. 所以, when the player gets back to the butchery, he activates another circuit containing yet another RS NOR Latch and two command blocks with two commands. First, the /say command in which the butcher thanks the player, and other one, the /give command, so the player gets the reward. Along with that, don't forget to use the @p command so the butcher says the player's name. For example, if the command block is set to do this: /say Thanks, @p. You helped me a lot killing that pig., the channel will say: "@]: Thanks, <name of the player>. You helped me a lot killing that pig." This makes the map way cooler and looks like it's made for the player as it says his/her name!
* Subtracting xp CAN work as a currency, by using the command /xp -3l @p[lm=3] where l (L for level) is subtracted. The minimum xp for the command to work can be listed inside the brackets, where lm is short for minimum level necessary.
You can make a Store using xp as a currency. Just place a command block before all the others with the following instructions: /testfor @p[lm=5] with a Comparator in front of the command block. That way you can only do the trade if you're at least at level 5 (in this case, but you can choose what level you want).
*
*The last two "updates" are pointless, as the [lm=(level)] in the first post will keep players from getting the item or losing their xp unless they are that level or higher. so if the command says [lm=5], they will NOT be able to use the "store" if they are level 4 or below, but WILL be able to if they are level 5 or above.
The blocks must be in order for this to work. If the blocks are powered at the same time, the cost block will subtract as per normal, but the block giving the item will not function unless your level is double or higher what the cost of the block is. (example: item costs 5, you have 7 levels, you will lose the 5 levels, but will not gain the item. You would only receive the item if your starting level is 10 or higher) The fix for this is to power the blocks linearly, give block first followed by xp block.
Minecarts over floating rails created with the setblock command.
在1.7版本中, the command block gained an expanded potential. 也就是 /summon and /setblock 指令的加入, and can be used to automatically build structures, 填充儲物箱, 以及生成以前不能生成的實體。 下面是這些指令的語法:
setblock的使用方法:/setblock <x> <y> <z> <方块名> [数据值] [旧方块处理方式] [数据标签] summon的使用方法:/summon <实体名> [x] [y] [z] [数据标签]setblock指令也可以用於做突然消失的地板或突然出現的牆。
setblock指令的例子:
* MobSpawners pt 1: The Basics
This code will create a zombie spawner 2 blocks from you in the x direction. Note that the name given for mob spawners in this code ("minecraft:mob_spawner") is the long version and you can leave out the "minecraft:" part.
幾件事情需要注意:
A) All times are in game ticks (20ths of a second). 200-800 is 10-40 seconds.
B) Keep in mind that they are in groups of 2 and won't work if their partner is missing. SpawnRange requires RequiredPlayerRange (and vice-versa), MinSpawnDelay requires MaxSpawnDelay, and I assume SpawnCount needs MaxNearbyEntities (although I haven't actually heard confirmation on that last one).
C) There is also a parameter called "Delay" which contains the amount of time before next spawn (20 ticks for the first time, whatever random number it picks between MaxSpawnDelay and MinSpawnDelay every other time).
D) the coordinates given are ~0 ~-1 ~-3 (so 3 blocks in the negative Z direction from the commandblock's current position and 1 block down). This presumably will imbed it in the surface of the floor. Keep in mind that a spawners "SpawnRange" setting only applies horizontally not vertically. Vertically it will only spawn at the same height or 1 lower or higher, so imbedding it in the surface of the floor cuts the available spawn area by 2/3rds (but can help hide it). Naturally occuring spawners have their height cut by 1/3rd due to appearing 1 block above the floor instead of 2.
E) All the values used here are the defaults.
* MobSpawners pt 2: Custom monsters
Now we get into the SpawnData. That's the stuff that tells the spawner you want a non-standard version of a monster, like a Zombie with a Diamond Sword and a Chainmail Helmet.
Using ~ without any number after it in the coordinates counts as zero. Since none of those 6 parameters from last example are used they will all be defaults.
Note that the 5 equipment slots are: Hand, Boots, Legs, Chest, Helmet. You must even specify empty slots (the { }, parts) unless they're after the last non-empty slot. So if you want him to have a helmet you have to specify all 5 slots, but if it's just a weapon you can leave off the other 4. Or if you want him to have leg armor you have to specify weapon and boot slots but not chest and helmet slots.
By the way, creatures that burn in sunlight are safe if they have a helmet on, although it damages the helmet instead.
About the Count tag: most codes can get away with leaving it out, however it is important. An item without a count tag is a stack of zero, better known in the community as a "Ghost Item". A player trying to use a ghost item will have it disappear out of his hands with it's first use (which is a failure). While monsters can use ghost items without problem (hence why codes get away with leaving it out sometimes) if they drop the items the player who picks it up won't be able to use it, SO INCLUDE COUNT!
Next up we have a Skeleton with an enchanted bow (Flame), a custom mobhead (Spider, internet connection required or it's just steve) with Protection 2, and riding a Skeletal Horse.
Well actually sitting on a Skeletal Horse, since the lower creature controls the movement and the horse isn't hostile. Don't try zombies on horseback, they just sit there ineffectually while the horse eats grass and snorts. Luckily this is a skeleton and can shoot you from wherever the horse decides to wander.
As for the horse itself, it's type 4 (skeletal horse), Tame is set to 1 (yes), and it's got a saddle (and the fact that they make us specify which saddle hints that they may eventually have more than one type). Technically you can have multiple levels of riders, although this gets silly quickly.
MobSpawners pt 3: SpawnPotentials
Using the SpawnPotentials tag lets us create a mobspawner with multiple mobs in it. It will randomly pick one each time it resets the timer (a second after spawning the previous mobs). Since these codes contain multiple mobs they tend to be quite long codes. Thanks to some youtuber whose name escapes me (Dragnoz) the fact that you can "break up" your code is known (command blocks ignore line breaks, so you can start a new line to clarify where one section ends and another begins and it won't ruin your code). Here's a more easy on the eye version of a SpawnPotentials code
Wow that's a mouthful! But then it is 6 separate mobs. In order we have:
0) Before the "SpawnPotentials" tag: The starter, which will never pop up again after the first time. If we want to see him again we have to include him a second time under SpawnPotentials. He is just some random dude in bluejeans (blue dyed leather leg armor) and a cactus green shirt (green dyed leather tunic) with a wooden sword. He's a zombie under that random-dood-mobhead of his of course. They all are.
1) Same random dood, only this time his wooden sword is 2 hits away from breaking.
2) Hey who let a ninja into the game?!? This one is a skeleton under his mask, but he's been given an iron sword. All his leather armor is dyed ninja-black. Skeletons with swords close the gap quicker than zombies so watch out.
3) Stone Sword and Chain Armor guy. Protection II on his mobhead.
4) One of my favorites. Gold Sword, Golden Armor, Pumpkin Helmet, and ON FIRE!!! Originally I wanted to give him a flaming pumpkin helmet but I realized the Fire tag only applies to entities not armor. The pumpkin is enchanted with Protection II and Fire Resistance X (10!) in a desperate attempt to keep him on his feet and threatening the player for more than 5 seconds. It works but if the player plays keepaway then Mr Pumpkinhead does tend to burn to death. Oh his sword has fire aspect too.
5) Iron Sword and Armor guy. Sharpness II on his Sword, Protection II on his mobhead.
6) Diamond Weapons and Armor guy. Wait who is that. Is...is that...Oh Em Gee it is! Run!...No of course it's not really him. Because he doesn't exist. FakeHB here has highly enchanted Diamond Armor (Boots with Fire Protection IV and Feather Falling IV, Leggings with Blast Protection IV, Chestplate with Protection IV, Mobhead with Protection IV, Fire Protection IV, Blast Protection IV, Respiration III) and a Diamond Pickaxe enchanted with Sharpness IV, Smite IV, Bane of Arthropods IV, Looting III and Unbreaking III. He's also got the previously unseen CustomNameVisible (set to 1 for yes), a CustomName, and PersistenceRequired (set to 1 for yes). That last one will prevent him from ever despawning, although he can be killed normally. If you can get through that Diamond Armor. And level 4 resistances. Luckily he's rarer (see below).
Other than the ninja it's a straight tour of the 5 tiers of swords and armor. Note the Weight tag, used right after the mob name in each SpawnPotential. That determines how rarely it's picked. Specific numbers don't mean anything, just the ratios between the numbers. For example if you want all the potentials to have an equal chance just set all the weights to 1. Changing them all to 8 wouldn't do anything different (they're still all the same size as each other), however changing all but one to 8 would make that one 1/8th as likely as the rest. In this code 4 is the default. The ninja only has a weight of 2 (making him half as likely to be picked) and FakeHB has a weight of 1 (making him 1/4th as likely to be picked, and thank god!) * MobSpawners pt 4: Rideable Monsters
Mobs can be ridden by using Minecarts or Boats on their heads. The command is fairly simple /setblock ~ ~1 ~ mob_spawner {EntityId:MinecartRideable(or Boat), SpawnData:{Riding:{id:<Entity>}}}
提示:
Some mobs simply can't be spawned with a spawner, sad to say, like bosses and Iron Golems. Adding a Minecart isn't going to change that.
Hostile Mobs with shooting abilities can and will use them against survival players. Watch out.
Ghasts cannot be ridden. The minecart becomes stuck in their head, no use to anyone.
Endermen cannot be walked around, but they can be forced to teleport by shooting a projectile at them (eg; snowball).
Ocelots (Ozelots in the game format) are some of the fastest mobs to ride, seeing they're trying to get away from you. They can also be partially controlled, by pointing away from the place you want to go.
Spiders are the only mobs that slow down when ridden.
Slimes and their cousins, Magma Cubes (game format LavaSlime) cannot have their sizes changed.
This is a reversed version of Destroyer. /execute @p ~ ~ ~ fill ~1 ~-1 ~1 ~-1 ~-1 ~-1 grass. This puts a 3x3 grass square under your feet. Only problem: Don't jump. It becomes a mountain of a problem.
Examples
The player can make a kind of world guard using the command block. (e.g. code: /gamemode <模式:[survival|creative|adventure|spectator]> @a[r=<radius>])
Using the radius argument with a teleporter hooked up to a clock circuit can be used to create an exclusion zone ("forcefield") around an x y z coordinate (which should not be centered on the command block itself, otherwise it will be difficult to edit or disable it later). Simply program it to teleport any player within a certain range to a further away point, or just back 10 meters using relative coordinates. Note that such a forcefield wouldn't know which direction you were approaching from, and may result in pulling a player in before pushing them back out the other side.
The commands /say Hello, @p, /tell @p Hello, @p, and /me Hello, @p will cause the command block to say user name of the nearest player in the message.
You can also clear players inventories, to prevent griefing and/or cheating: /clear <目標(玩家)> <物品> <資料> <最大量> <資料標籤>
Spawners
Command Blocks can create spawners using the setblock command, e.g.: /setblock ~1 ~-1 ~0 mob_spawner 0 replace {EntityId:Zombie,SpawnData:{Equipment:[{id:276,Count:1}]}} Anything that counts as an entity can be spawned (except a player), which includes all hostile, neutral and passive mobs, as well as animals, minecarts, fireballs, arrows, snowballs, ender pearls, custom thrown potions, fireworks, primed TNT, falling sand, red sand, or gravel, paintings and item frames, experience orbs, and even dropped items of any type.
Pig/Cow/Chicken spawners can be placed in the butcher's backyard in a village to create a constant meat supply. E.g.: /setblock ~1 ~-1 ~0 mob_spawner 0 replace {EntityId:Chicken,MaxNearbyEntities:10,RequiredPlayerRange:16,SpawnCount:6,SpawnRange:2,MinSpawnDelay:50,MaxSpawnDelay:200,SpawnData:{Riding:{id:"Pig"}}} Note that the spawner in the last code example will spawn a chicken riding a pig. There doesn't seem to be a limit to how many levels of riders you can use (e.g.: a chicken riding a pig riding a cow riding a horse riding a silverfish riding a villager ("Say, that's a mighty odd hat you have on, Farmer Brown")).
Please note that if you want to use the RequiredPlayerRange tag you have to use the MaxNearbyEntities tag as well. Same deal with MinSpawnDelay and MaxSpawnDelay. Lastly, note that the y value used in both of those spawner example codes was ~-1, which (assuming you're not flying) will put the spawner in the surface level of the ground at your feet.
If you don't want to target a specific player, you can use @a, @p, or @r instead of <player>. Keep in mind that you can use @p (which means "closest player") in player issued commands as an easy to type 2 character replacement for your own name as the closest player to you will always be you.
Booby traps
The most lethal booby trap would be a command block set to teleport someone into the void.
As of 1.8 you can do /kill @e[r=2] in a command block below a block with a pressure plate to make a multi-use landmine that kills all nearby entities upon stepping on it (including players, item frames, and paintings)
Note that booby traps that use @p can be dangerous due to the fact that non-player entities could trigger them (if something like a pressure plate is used), resulting in the teleportation of the nearest player, no matter how far away they are and regardless of the fact that they haven't actually stepped on the plate. To get around this, you can either use the /testfor command as an invisible pressure plate, or you can do /tp @p[r=radius] x y z. Hook a clock circuit up to a command block programmed with /testfor @p[x=1, y=2, z=3, r=radius], with the coordinates changed as appropriate. Note that as of 1.8 a range of zero can now be specified.
Teleporters
It is possible to make teleporters using the command block. (e.g. code: /tp @p x y z) Taking it one step further, a teleporting station can be made, with multiple button-activated teleporters that each teleport to different locations. Scouting and testing teleportation destinations first is advisable, to make sure players don't end up stuck inside blocks or in other unintended places. If you appear in ground while testing coordinates, use /tp @p ~0 ~8 ~0 to get out (may require multiple uses).
If you use the teleport command with the command block, you can use relative coordinates in the destination coordinates by placing an ~ in front of a Coordinate (e.g. code: /tp @p ~0 ~8 ~0 This would teleport the player 8 blocks into the air).
Commands that use coordinates (e.g. /tp or /spawnpoint) add 0.5 to whole numbers when no decimal follows. This is so you appear centered over the block you appear on instead of at the edge or corner of it. For example, the number -33 would execute as -32.5, and 187 as 187.5. To prevent this behavior, add .0 (25.3, 90.0) after them, as these values are executed left as-is.
With the 1.8 update, you can now also teleport minecarts or boats, with you in them. The command is /tp @e[type=Boat] (coordinates).
More commands in fewer blocks
There are several ways to combine groups of commands into just one command.
/execute will run its command as many times as the number of targets it selects. If it doesn't matter what entity runs a particular command, you can use @e[c=10] to ensure the code always runs 10 times (as long as there are always at least 10 entities in the loaded world).
To run multiple commands, /summon a command-block minecart riding another command-block minecart riding another, with the commands in reverse order, on an activator rail. There are also commands called one-command mods that use this tactic. Mr. Garretto makes one-commands and maps here.
Exp Shop
This will allow server owners to sell effects, items, and more to any player using level ups and exp. All they have to do is press one button
Building The Structure
Setting The Commands
Using a map item as a scroll
In his recent videos, Sethbling uses a map as a scroll to perform commands (summon creatures, teleport). He has an empty map in his inventory and when he uses it, it becomes a filled map which immediately disappears and a redstone task is done. In this tutorial I will show you how to build a redstone mechanism to detect the use of a map as a scroll and perform a task (give an effect, open a door,...).
Pros
Fast redstone interaction.
Compact system.
At-will triggered system, just right-click to activate it.
Single use : the map disappears during the inventory check, but you can give it back through a /give command
Cons
There can only be one purpose for the scroll. I.E. you cannot do a scroll of teleporting and a scroll of strength without using complicated data values.
You may see the map animation when activating the map before it gets deleted.
You cannot use the map item during your playthrough (showing a text message, a path, a drawing,...).
Building the mechanism
You can change the display name of an item to give the player a better understanding of the object and use the tooltip display. Use the following command to give the player a custom named map :
The two hoppers form a redstone clock. You can use other clocks shown here.
The Command block 1 contains the /give command described in the section above. It can be dismissed if you don't want the scroll to come back after being activated.
The Command block 2 contains the inventory check command :
/clear <player> filled_map
The Command block 3 is the output in case of success. You can do whatever you want : give an effect to the player, teleport him somewhere,... You can also wire this output to a door, a piston,...
Going further
The /clear command can check for other interactive items :
check for a glass_bottle if the player just drank a potion.
Sethbling also uses a fishing rod which works when the line is reeled in. The /clear syntax involves another argument, the damage value, after the item name:
/clear <player> fishing_rod 2
Note that spamming the reel, or hooking a mob, may damage it more than 2, so make another one of these every 2.
Command-Piston-Repeater Fun
Command block: /setblock x y z minecraft:sand
1st Piston Front: Showing to set /setblock x y z to that position
Fast Pusher
Repeaters are risen by 1 block from 1-3 so you can see them