Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement
Ic translate
此條目的(部分)內容需要翻譯。

你可以幫助我們來翻譯此條目,但請勿使用機器翻譯

Brush
該文章需要整理以符合格式指導 討論

請幫助最佳化文章格式來讓它符合格式指導。

指令方塊是一種主要用於冒險模式、多人遊戲的自動化和自訂地圖的方塊。如果你想了解更多細節,請參見指令方塊頁。如果你想知道怎樣使用指令方塊,請參見指令頁。如果你不知道在某些指令中如何設定座標,請見座標

一般的應用

指令方塊有各種各樣的用途,如改變難易度,改變天氣的狀態,或者給你指定的物品。它們只能在作弊為開啟時才能使用。 例如/time set x 此指令會變更目前世界的時間。

指令方塊也可以將文字顯示於玩家的聊天選單。如/tell <玩家名> <資訊>, 或者/tellraw <玩家名> <JSON文字>。如果加上參數"@p"在/tell/tellraw的後面,那麼只有最近的玩家會看到資訊。 而如果指定了一個玩家名,那麼該指定的玩家會看到資訊。 你也可以輸入:/tell <玩家名> ,會顯示以下資訊:「! 悄悄地 對 玩家 說:」。

你可以用以下指令去改變難易度:/difficulty x,如 /difficulty peaceful,會將遊戲難易度變更為和平。

另外一種使用指令方塊的方法是使用/tp <參數> <目的地座標>在兩個不同的區域之間傳送。

給予一個隨機玩家一個物品並告訴所有人

File:Cookietut.png

餅乾給予器 5000X

這個裝置會給予一個隨機玩家五個餅乾,然後告訴所有人。

首先建立一個計分板(名字任意,注意除非在你測試,不然不要顯示它),比如說「cookie」

/scoreboard objectives add cookie dummy cookie

第一個指令方塊的指令:

/scoreboard players set @r cookie 1

第二個和第三個指令(兩者可顛倒,但要同時被啟動)

/say @a[scores={cookie=1}] 已被给予五个[[曲奇]]。

/give @a[scores={cookie=1}] minecraft:cookie 5

第四個指令方塊的指令

/scoreboard players set @a[scores={cookie=1}] cookie 0

"I" 代表輸入紅石訊號原。(建議可使用永動紅石電路)

傳送

你可以透過使用/tp <x> <y> <z>來傳送。其中<y>表示垂直方向的移動,<x><z>表示前後和左右方向的移動,玩家可以透過這個指令傳送到(x y z)這一個座標的位置。如果要以目前站的位置為標準進行傳送的話就只要在其(x y z)座標前面加上一個~即可,例如/tp ~x ~y ~z。如果當指令方塊座標(x y z)位於0 0 0時輸入/tp @p ~3 ~4 ~5,這時他會被傳送到3 4 5這個座標,和玩家輸入/tp @p 3 4 5是一個效果。

玩家安全系統

指令方塊也可以製作安全系統。 只要在建築物入口的鐵門前放置一個壓力板,並於指令方塊輸入指令:/tp @p[r=<半径>,name=!<你的玩家名>] <x> <y> <z>。對於怪物,簡單的柵欄或熔岩護城河就能達到目的。

自動人行道

類似於電梯的概念,用於使生物往x或z座標移動。 可以透過以下方式建立:

  • 使用/fill指令加上你的座標。 (比如/fill <x> <y> <z> <x2> <y2> <z2>)
  • 對於要填充的方塊,使用這個:command_block 1 replace{Command:/tp @p ~-1 ~ ~}
  • 編輯括號內的座標,會改變將移動的方向。
  • 將壓力板放在所有指令方塊的頂部。
  • 在這時,請用/gamerule CommandBlockOutPut false將指令塊提示遊戲規則關閉,因為聊天選單會被指令提示洗頻。

永日

Time reseter
  • 13w24a,可透過在聊天選單輸入/gamerule DoDayLightCycle false指令來獲得永日,以及/time set 6000指令。

透過使用蛛網和礦車,你可以使用 /time set 0跳過夜晚。一個礦車需要31秒穿過一個蛛網。因此,透過使用23個堆疊的蛛網和檢測器軌道和幾個動力軌道來達成永日。

或者,你也可以在一個木製壓力板上放置一個掉落物去實現,掉落物每5分鐘就會放置出來,這時它會觸發一個指令方塊將時間重設為0,還會觸發一個發射器(或投擲器)將一個新物品扔到木製壓力板上。5分鐘是一天的週期,並且會在怪物產生之前觸發重設時間。然而,這個方法被限制在該區塊被載入後的64×9=576個週期,即48個現實小時的遊戲時間。在快照13w01a和更高版本中加入了漏斗,可以挑選物品並將它們存入儲物箱。在怪物磨床中,可以在發射器中填滿火藥或者腐肉。 另一種方法是使用指令方塊建立。(例如:/summon Item ~1 ~0 ~1 {Item:brown_mushroom} )這樣做的好處是它不像使用發射器那樣有64×9的格子限制。

這兩種方法都要求保持區塊載入以使系統工作。


或者你可以將指令方塊連接到一個重複的紅石脈衝,例如一個5分鐘,某種類型的循環,或者如右圖所示的日光感測器。為了防止聊天框被洗頻,使用指令/gamerule CommandBlockOutput false關閉指令方塊在聊天框上的訊息輸出。注意:這個方法可以使用不同的指令來設定各種各樣的東西。(比如,要使天氣永遠晴朗,在循環中加入另一個指令方塊,並使用指令/weather clear。)

為了可以在不同功能之間切換,可以在指令方塊前設定一個與門,在一邊放置一個控制桿,在另一邊設定一些電路。


使用日光感測器是永日的一種更直接的方法。

Automatic Time Resster view 1 Automatic Time Reseter view 2

當沒有足夠的亮度日光感測器在遠處為紅石火把供電時,傳感器會停止充能並啟動指令方塊,將時間設定為8000。換句話說,當亮度太低時,指令方塊會將時間設定為中午。當指令被啟動時,亮度會隨著紅石線的距離而變化,它設定的時間隨在指令方塊中輸入的時間而變化。

Automatic Time Reseter view 3

要做到這一點,首先,你要把日光感測器放在一個開放的區域。然後你從它相鄰的位置開始向遠處設定一些紅石線紅石線的距離取決於你需要多少延遲的時間。你最多只能有15個紅石線日光感測器發送訊號到它的另一端。接下來,在紅石的另一端放一個方塊。把紅石火把放在這個方塊的一側,並在火把頂部設定一個指令方塊。右鍵點擊指令塊輸入指令,指令以/time set開始,以有效的時間值結束。這個值即為指令方塊在觸發時會將時間設定到的數值。晚上是14000,中午是8000。

Automatic Time Reseter

這種設計可以在地圖上使用,使之保持在特定的時間。但這個簡單的裝置只能用在創造模式或者開啟作弊時。

還有一種更緊湊的設計。如果你把一個日光感測器作為一個紅石比較器的第一個輸入,一個強度為15的紅石線(紅石方塊紅石火把)放入第二個輸入,然後將比較器設定為減法模式,則比較器將會在中午之後立即啟動。

輕鬆設定日/夜

指令方塊上放置日光感測器,然後按下使用鍵,將其設定為夜光傳感器。 將指令/time set day加入到指令方塊中。或者如果你希望永遠是夜晚,你可以加入一個日光感測器,不要右鍵點擊它,然後將/time set night加入到指令方塊中。

無線紅石

可以使用指令方塊計分板系統實現無線紅石。該過程涉及使用計分板變數,該變數由附加到時鐘電路輸出的指令方塊進行搜尋。然後在無線輸出指令方塊上使用紅石比較器,該指令方塊在發現變數為正時觸發。

無線紅石也可以透過使用對象而不是變數來實現。如果輸出指令塊設定為嘗試刪除一個不存在的對象,則可以透過透過指令塊或聊天指令加入said objective來建立紅石訊號。這種方法對於變數法的優點是它不依賴於參與者。

為此,在在輸入處放置一個指令塊,並鍵入指令/scoreboard objectives add <對象名> dummy,在輸出位置放置一個指令塊,輸入/scoreboard objectives remove <對象名>,將其連接到時鐘電路上,然後在指令方塊外面放一個紅石比較器,然後放一個紅石中繼器。然後使用紅石中繼器作為輸出。

你還可以透過使用/setblock指令實現無線紅石,而不是透過計分板系統。你所要做的就是讓指令方塊將一個與任何不輸出訊號的方塊相鄰的紅石方塊的座標設定為目標座標,並且與一個連接到反向訊號的指令方塊一起設定為相同的座標。

無線按鈕

從技術上講,這可以在任何方塊上完成,但是按鈕、控制桿和其他可以互動的方塊會增加有趣的效果。雖然在伺服器上非常神秘,但它其實很簡單。它使用了1.8的/testforblock指令。它使用了一個指令方塊、一個將指令轉換為紅石訊號的紅石比較器、一個要測試的方塊和一個重複啟動指令方塊的時鐘電路。這是一個無線按鈕的示例:/testforblock 123 12 123 stone_button 10。輸入要測試的特定方塊的座標和名稱,在本例中是位於123 12 123石製按鈕。這可以使用在任何可變更資料值的方塊上。座標之後的數字10對應於我們希望指令方塊測試的按鈕的資料值。在本例中,當按下面向西部的按鈕時,要讓指令方塊啟動,因此必須將該資料值值設定為10

注意:這個值根據方塊狀態變化,沒有按下的面向西部的按鈕的資料值是2。當一個按鈕被按下時,它會在初始狀態中增加8的值,所以當按下時,一個面向西部的按鈕的資料值是10。關於資料值的詳細內容,請見按鈕#資料值控制桿#資料值

入門套件

透過使用參數 [gamemode=<模式名称>], 你可以在(伺服器)地圖上製作一個只能獲得一次的套件,首先, 在地上挖 3個方格, 然後放置一行指令方塊(工具包中的每個物品一個)。 在指令方塊的介面中, 輸入 /give @p[gamemode=<初始游戏模式>] <物品ID> <数量>。這樣他們會獲得你所希望給予他們的物品。 在一個額外的指令方塊裡面輸入 /gamemode <非初始遊戲模式> <對象>, 然後潛行後用紅石連接整個指令方塊串。 將洞填起來然後放上壓力板。 當玩家走過去,他們會得到他們應得的工具包,他們因為改變了他們的遊戲模式所以他們不會獲得更多的套件 (除非作弊)

(注意:此命令也可以透过记分板的方式完成,首先建立一个记分板并命名它,如/scoreboard objectives add <名称> dummy <名称>,然後,給予計分板數值為0的玩家要給予的物品,如/give @p[scores={<记分板名称>=0}] <物品> <数量> <数据值>,最後將他的數值設為非0的值,如下/scoreboard players add @p <记分板名称> <任意非0的数值>。同時,你也可以透過不同的計分板名稱重複以上步驟。)

作為壓力板的替代品

是不是已經厭煩了壓力板只有四種材質可用了呢(石製,木質,鐵質和金質)?現在你可以不再為這個問題困擾了。你可以使用包含指令/testfor,區域大小的帶有時鐘電路的指令方塊來代替壓力板了。指令/testfor @p[r=2]會檢測2格內(朝任意方向兩個方塊加上指令方塊本身的區域內)是否有任意玩家。當指令方塊在一層地板下面的時候,r=2剛好是希望達到的效果。記住玩家是在一個球形區域內(而不是方形區域)觸發這個指令的,所以r=2的區域大約是5*5*5,r=1的區域大約是3*3*3(其實更像是一個+號上下各加一個方塊)。你可以用dx,dy,dz這些參數來編輯指令。你也可以在代碼裡指定xyz座標(比如/testfor @p[x=50,y=64,z=46,r=1]),但是注意不能把區域縮小到一個方塊。因為在不包含座標的指令中區域大小代表著指令方塊本身加上週圍r個方塊厚的區域,對於指令方塊來說比較合理(如果縮小到只有一個中心方塊,那就只有你站在指令方塊那個位置時才會觸發指令了,所以並不合理)。至少來說一個r=1的觸發區域(即+號上下各加一個方塊)可以被埋在地層下,只露出上表面,前提是你知道玩家不可能在地表下兩層的位置行走。如果實現這一效果且不使用xyz座標則要求指令方塊嵌在地表上,可以被玩家看到。

在單機非創造模式地圖中使用指令方塊

透過/gamemode也可以使你在單機非創造性地圖中使用指令方塊,簡單的切換遊戲模式可以使用 /gamemode creative 然後將指令方塊的指令設定為您想要的任何內容, 最後使用/gamemode survival切換回生存模式。 指令方塊只是需要在創造模式下設定,但切換至生存模式仍然可以正常運作。

他也可以被用於傳送(例如一個遙遠的要塞,在地下挖礦,或者在一個浮天空島世界)。 如果他需要你花了很長時間才能到達那裡,然後你不介意他是一種軟作弊, 這樣你可以建立起一個傳送系統。請確保你在設定指令方塊的時候是創造模式(請使用 /gamemode creative。 如果你並沒有開啟作弊選項,打開局域網模式設定打開作弊),但你還是可以在生存模式中使用它。在打開的指令方塊的介面中輸入tp @p x y z 。 然後, 用紅石 (包括按鈕,控制桿,壓力板)啟動這個指令方塊,然後你就會被送到遠處的目的地。你可以建立多種不同的傳送器。這也可以用於跨越大面積的大型項目,或者如果您將儲物箱從舊房子轉移到新房子。

探險家地圖繪製

如果一個人希望創造一個單人玩家的探險家地圖,做 /publish指令來讓其他的指令(見下方)被使用。

在多人中的應用 (SMP)

這個章節詳細介紹了指令方塊多人遊戲中的應用。

  • 傳送/運輸

透過 /tp指令,可以製作一個所有人都可以使用的傳送裝置。可以在每個地方都使用。 例如,在整個世界裡做一個龐大的傳送系統,所有的傳送點入口都匯集到傳送大廳中,而傳送大廳可以進入每個傳送點入口處進而達到出口。這樣就可以建造一個「快速交通中心」了。

  • "定格動畫"

透過使用/tp,或者Minecraft地圖編輯器,例如MC地圖編輯器可以複製一張圖片(利用方塊做出來的繪畫),然後粘貼到一處遙遠的地方,並變動繪畫的一些方塊,利用一些壓力板或者絆線鈎,在玩家短時間欣賞繪畫後,指令方塊做出/tp指令,將玩家傳送到下一張繪圖點. 如果大量的複製粘貼這樣的零件,讓玩家按順序的在這些之間傳送並稍稍弄出一點點的延遲,那麼玩家就會產生幻覺,認為這個繪畫是在運動的(甚至認為是某MOD做出來),這就是利用指令方塊來實現定格動畫技術。

1.7+裡可以使用/setblock來直接放置和刪除方塊,利用/setblock還可以免除傳送時不必要的卡頓和一大堆的房間,而1.8+的/fill更是可以極其方便地放置大量的方塊。

  • 抽獎

/give @r指令,可以創造一個抽獎。但是記住, /give指令是直接把物品放進他們的背包,而不是放在他們面前。

  • 監獄

透過連接高頻紅石到一個指令方塊和用/tp指令,你可以強制玩家留在某個地方。如果你想讓這個方法成為可行的,在你的聊天窗內使用指令/gamerule commandBlockOutput false。使用"Range"(最大範圍)和"Minimum Range"(最小範圍)兩個參數,你可以在玩家離開一定距離後再將他們傳送回來。

  • 只針對管理員

如果使用參數[m=1],那麼只有創造模式的玩家才會受到這條指令的影響,當然輸入m=0既只對生存模式的玩家有效。

  • 戲弄創造模式玩家

你可以放置一個指令方塊,輸入/tp @p[m=1] <坐标>或者一些整人指令。當創造模式的玩家啟動這個指令方塊就會被傳送到某個地方或者變成生存模式,好無聊的惡作劇!

  • 公告

註:使用AutoMessage等伺服器端外掛就可以達到自動公告的功能

透過在指令方塊中使用 /me,可以創造一個無人自動廣播(需要連接循環紅石等不斷發出啟動訊號的紅石元件),不需要OP,用1.7+的新指令/tellraw {text:"<信息>"}可以免除開頭的[@]並且可以做到懸浮事件和點擊事件等。

  • 安全掃描

註:大部分伺服器管理外掛支持封鎖危險物品。

使用 /clear指令, 你可以清除玩家背包中的某物品。具體步驟是這樣的,使用 /clear @a(或者某玩家ID) <清除的物品名>。如果想實現自動清理危險品需要連接循環紅石。

  • 比賽裁判

使用/say @p,指令方塊就能報告最近的玩家。如果指令方塊放在終點線後,他會很方便的說出贏家,但是/say會給所有玩家發送資訊,為了防止洗頻,建議使用/tell/tellraw

  • 建立保護區域

註:Residence等伺服器領地外掛的拓展外掛可以實現領地內遊戲模式的變化。

你可以透過指令方塊創造一個「創造/生存模式區域」,但是很繁瑣。可以透過用指令方塊的範圍限制來製作一個「圍欄」,透過圍欄的玩家會變成生存或創造模式。在指令方塊中輸入指令 /gamemode adventure @a[x=<区域中心坐标> y=<区域中心坐标> z=<区域中心坐标> r=<最大的玩家搜索半径> rm=<最小的玩家搜索半径>] 這樣放置兩個搜尋區域不重合的指令方塊,就可以將規定半徑內的玩家改變模式。

  • 無外掛PVP

使用指令 /gamerule keepInventory true 來關閉玩家死亡後的物品掉落(同樣在重生後會保留物品和經驗等,所以需要在玩家重生後清空背包) 。使用 /give @p <物品ID>可以給予玩家武器(可以加入NBT標籤),你可以設計一套完善的職業系統,玩家選擇不同的職業會有不同的裝備。使用 /spawnpoint [x y z座標] 設定玩家重生地點,使用 /tp [x y z座標]移動地圖中的玩家到指定區域。

  • 新手工具包

你可以很簡單的使用指令方塊給予新手包且不需任何外掛: "/give @p[r=2] 274"。 為防止玩家按下兩次按鈕獲得兩個新手包,您可以設定按鈕後的兩個指令方塊:: 1. "/give @p[r=2,m=adventure] 274" 2."/gamemode survival @p[r=2]"(玩家一開始是冒險模式,獲得工具包後調成生存模式,然後再限定工具包僅限冒險模式能拿即可)

  • 特殊的彩色文字

雖然你不能於指令方塊直接輸入彩色/粗體/斜體文字,但是透過McEdit編輯器可以編輯那些地圖或伺服器內儲存的文字。基岩版可以使用"§"來進行文字的變色、甚至是亂碼(§k)。 SethBling's McEdit Filter: ColourCommandBlockText

同時/tellraw可以直接利用"color"等參數來弄出彩色字體。

  • 警報系統

當玩家走上壓力板時,他能觸發指令方塊/say @p <警告内容>

  • 獎勵屋

如果某個玩家在伺服器有著特別的貢獻或者有元老資歷,但卻不足給他管理員權限,你可以獎勵他一組鑽石或者一些奇怪的東西。 建立一個只有透過傳送指令才能進入的房間,將有卓越貢獻的玩家傳送進去,玩家會啟動房間中的指令方塊從而獲得獎勵,然後他又會被另一個指令方塊傳送回原地,如果伺服器允許/back的話,連續2次傳送到原點,這樣/back就無效了。(可以避免玩家重複領取獎勵)

  • 天氣機

使用/toggledownfall/weather thunder來開始或者結束降雨(雷雨。)合理安排這些指令的話會十分有用, 你可以隨自己的意願開始或停止降雨。這個技術可以用於村民和一些由降水控制的紅石機械,不用輸入任何指令就可以控制天氣(需要管理員啟動指令方塊自動執行), 合理利用將會十分有效,比如在森林火災時或者在雨天生怪。

  • 有獎競賽

可以使用/tp @p/give @p指令製作一個障礙賽跑或者有獎迷宮,遊戲結束後就將玩家傳送回重生點或其他地方。

  • 時間機器

在地圖上模擬兩個十分相似的環境,透過指令方塊將玩家從一個傳送到另一個,並且時間也會被設定為開始的時刻,這就好像是時間倒退。 (註:可以廣泛用於劇情RPG地圖。)

  • 地雷

使用指令/testfor @p[r=<半径检测范围>,name=<玩家名(如果没有限制可不写)>] 使用紅石比較器和紅石中繼器連接指令方塊和TNT,當指令方塊於檢測範圍內檢測到指定的玩家就會啟動TNT!砰! (註:指令方塊的/testfor指令為一次性指令,指令方塊檢測到一次就會一直輸出訊號,如果需要多次性的話,你可以直接使用/summon tnt指令直接召喚出TNT。)

  • 安全門

透過使用 /testfor @p[r=5,name=<房主>],指令方塊會在一定範圍內檢測房主並且為他開門,也只會為他開門。 (註:指令方塊的/testfor指令為一次性指令,指令方塊檢測到一次就會一直輸出訊號。)

在自訂地圖中的應用

這一節詳細介紹了指令方塊在自訂地圖的應用。

Minecraft中使用大量指令方塊的地圖有很多優勢。 比如:SethBling's TF2 Map

https://www.youtube.com/watch?v=_f2brU8hBWc&feature=plcp

另一個優秀的應用例子是 Hypixel's Gladiator Arena,這個地圖中的戰鬥職業系統完全依賴於指令方塊。

https://www.youtube.com/watch?v=jryJkWcqmzM

  • 「沉默的」指令方塊

在地圖中控制指令方塊不輸出提示資訊很重要,這可以保持玩家對地圖的未知性和劇情的隱蔽性,如果玩家看到了各種指令的提示資訊,地圖將會索然無味。 關閉指令方塊輸出資訊(除非是/say這類的指令)使用/gamerule commandBlockOutput false就可以實現。

  • 庇護所/角斗場

使用壓力板或者絆線 (以安全城堡為例)設定進入城堡內的玩家為和平模式(對於不同區域視情況而定)。城堡大門可以有連接指令方塊的絆線,玩家一旦走過絆線(或壓力版),啟動指令方塊,就會變為和平模式,這樣就可以創造一個「避難所」。反之,你可以用同樣的方法創造一個「困難模式區域」,當玩家進入會變為困難模式。

  • 對於不同遊戲模式玩家的控制

使用值[m=creative]你就可以設定指令只對創造模式的玩家有效,生存模式就是[m=survival]。 例:傳送所有創造模式的玩家到254,47,-874,使用的指令為 /tp @a[m=creative] 254 47 -874

  • 「聯合」住宅

建造至少兩個建築物,在房間的入口或者出口設定一個 /tp指令的指令方塊,你不必將你的建築都在同一個地方建設,它們可以在任何地方,只需要入口的指令方塊傳送過去,玩家會忽然覺得外面感覺很小的建築內部空間竟如此之大。用這種方法聯合多個建築,可用作與伺服器或單人地圖中的場景瞬移。

  • 出生地

使用 /spawnpoint 可以設定玩家出生地點。(應用十分廣泛,PVP地圖,RPG地圖等等)

  • 熔岩跑酷

之前的內容提到過,/gamerule keepInventory true可以在玩家死後儲存背包物品。 在跑酷地圖的出發點設定一個這樣的指令方塊,就可以使掉落熔岩死亡的玩家不會丟失物品,同時記錄點可以用/spawnpoint來做。

  • 我要睡覺!

使用 /spawnpoint 可以直接設定重生點,但是要跳過白天就需要 /time set <时间> 指令,18000為夜晚(並非絕對,可以按喜好設定,不要少於12500),這樣就可以模擬出睡覺的效果了。(可用/time set 700 直接轉為白天,/spawnpoint指令和/time set 700配合不就能模擬睡覺了麼?)

  • 時間和天氣下的場景

比方說,你的地圖開始在一個寒冷的暴風雨之夜,你可以設定突然天晴了,外面有燦爛的陽光(光影mod麼?)!或者,如果你想開始一個光明的一天,想讓雨突然下起來又沒辦法?不要怕,有/weather指令。只需使用/weather,輸入就行了!你也可以使用/time set輸入:0是凌晨,6000是中午,12000是黃昏,18000是午夜。

  • 檢測世界是否切換到了和平模式

建立一個攻擊型生物,把它放在壓力板上。(請確保它會保持始終按下狀態,所以一定要確保它不能跳或走開)。做一個紅石電路,讓壓力板在沒有接收到紅石訊號的時候啟動指令方塊。指令方塊裡設定一個訊息,通知玩家的地圖由於難易度切換到了和平模式導致損壞,需要的怪物已經消失,請重新下載這個地圖。你甚至可以做一個隱形傳輸指令方塊,把那些故意切換到創造模式的玩家換成冒險模式後傳送到一間基岩屋內,並讓他不能使用/kill或/tp指令,並把他的重生點設在那個房子裡,讓他永生見不得光明!(單人的話,可以點「對局域網開放」,或用修改器編輯)

  • 會說話的冒險地圖(有一個任務系統!)

/say指令可以直接給玩家發送訊息。用指令方塊將會更好,這樣你就不需要放很多的告示牌和編頁碼長到不行的書來告訴玩家遊戲規則. 你只需要把指令方塊放成一條線然後在中間鋪中繼器來弄各個語段之間的延遲(so the player isn't spammed)接著你就可以把那堆告示牌和放著書的儲物箱移走。

有一些是和NPC配合使用的。 想象一下你進了鐵匠鋪並且你想要讓裡面的鐵匠說些什麼。在指令方塊出現之前, 你需要一些書和告示牌來充當對話的效果, 然後在鐵匠鋪裡造些房間並放些雜物,這樣會讓這個鐵匠鋪看起來變得非常亂,但是現在,你只需要使用/say指令來製造鐵匠說話的效果。 也許櫃檯後面的豬會求饒!讓我們再舉另外一個例子:你在一家工廠裡,一個報警鈴的聲音提示說工廠陷入危險了。用這個在聊天框中告訴你,特別是如果文字很長,以便保持一個緊張的氣氛;這同樣的可以用在定時炸彈裝置。如果玩家看到了 '10...' '9...' '8...' 顯示在聊天框中,他將可以更好的把情緒帶進地圖。

最後但並非最不重要,他可以更容易的建立一個任務系統。來讓我們的玩家開始進行廝殺。 他透過壓力板啟動了RS NOR鎖存器 (所以他不能被再次啟動) 然後一個有 /say指令的指令方塊去滿足屠夫對玩家的要求。他需要去殺一隻豬 (他真可恥)。 玩家到達站在石制壓板上的豬,當豬死了時就會關閉. 所以,當玩家回到屠宰場時,他啟動另一個電路,包含另一個RS或閂鎖和兩個帶有兩個指令的指令塊。首先,屠夫感謝玩家的「說」指令,另一個指令是「給」指令,玩家獲得獎勵。除此之外,別忘了使用@p指令,所以屠夫會說出玩家的名字。例如,如果指令塊設定為這樣做:/說謝謝,@p.你幫了我很多殺了那頭豬,頻道會說:「@」:謝謝,<name of the player>。你幫我殺了那頭豬。「這讓地圖變得更酷,看起來像是為玩家製作的,上面寫著他/她的名字!

建立商店

透過使用 /give @p[level=<等级>..] <物品> <数量>/experience add @p[level=<等级>..] <等级> levels 指令可以建立一個商店,舉例來說,如果你放了兩個指令方塊,一個輸入 /give @p[level=5..] grass_block 64 指令,另外一個輸入 /experience add @p[level=5..] -5 levels 指令,並連接到相同的紅石電路,當指令方塊被啟動後,會從等級高於5等的玩家扣除5等等級,並給玩家64個草地。

  • 透過使用指令/experience add @p[level=3..] -3 levels將經驗減去作為貨幣。在中括號內可以列出指令執行所需的最低經驗。

可以使用指令方塊建立出售任何物品的自訂村民。
例如: /summon villager ~-2 ~0 ~0 {Profession:3,CustomName:BLACKSMITH,CustomNameVisible:0,Offers:{Recipes:[ {maxUses:13,buy:{id:388,Count:5},sell:{id:283,Count:1,tag:{ench:[{id:16,lvl:9},{id:20,lvl:6}],display:{Name:Molten Gold Sword}}}},{maxUses:13,buy:{id:388,Count:1},sell:{id:280,Count:1,tag:{ench:[{id:16,lvl:5}],display:{Name:Whuppin Stick}}}},{maxUses:13,buy:{id:388,Count:2},sell:{id:369,Count:1,tag:{ench:[{id:16,lvl:5},{id:20,lvl:10}],display:{Name:Radioactive Whuppin Stick}}}},]}}

使用buy標籤的部分是村民的收購物,使用sell標籤的部分是村民的出售物。如果您不希望交易次數耗盡,您可以將maxuses標籤變更為1000;如果您希望使其成為只能交易一次的項目,您可以將maxuses變更為1。注意這裡的第一個物品(金劍)有一個超出範圍的附魔(鋒利9)。是的,這是可行的,但在做出超出範圍的效果之前,一定要研究什麼樣的附魔效果,因為有些東西什麼也不做,甚至會產生負面影響(水下呼吸的「看清水下」副作用使所有東西在高水平上都變成了令人眼花繚亂的白色,就像你潛入充滿泥漿的北極水域一樣)。至於那把金劍,記住金劍磨損得太快了(畢竟人們稱之為黃油劍是有原因的)。一個10級耐久附魔會將一把金劍達到一個體面的耐用性水平。另外注意,另外兩個「武器」實際上是一個木棒和一個帶有武器附魔的烈焰桿。使用任何非武器作為武器都會造成與空手相同的傷害(1(♥),但這些武器上的附魔使它們與未附魔的劍一樣。它的優點是木棒、烈焰桿或其他物品可以無限使用。同樣的技巧也可以用於生物頭顱和水下呼吸3,以製造一個無限耐久的潛水面罩。

生怪箱

Clock
此條目需要更新。

理由:以下部分內容在Java版1.13可能已經不受支援。

你可以透過 /setblock 指令放置生怪箱 例如: /setblock ~1 ~-1 ~0 mob_spawner{EntityId:Zombie,SpawnData:{Equipment:[{id:"minecraft:iron_sword",Count:1}]}} 會放置產生拿著鐵劍殭屍的生怪磚。幾乎所有除了玩家的實體都可以透過自訂生怪磚產生,,包含了礦車、火球、箭、雪球、終界珍珠、飛濺藥水、煙火、點燃的TNT、掉落的沙、掉落的紅沙、掉落的礫石、畫、物品展示框、經驗球甚至是掉落物。

你可以把豬、牛或雞的生怪磚放置於村莊的屠夫家的後院,以便創造永恆的肉類來源,例如:/setblock ~1 ~-1 ~0 mob_spawner{EntityId:Chicken,MaxNearbyEntities:10,RequiredPlayerRange:16,SpawnCount:6,SpawnRange:2,MinSpawnDelay:50,MaxSpawnDelay:200,SpawnData:{Riding:{id:"Pig"}}} 此指令會放置生成"雞騎在豬上"的生怪磚,而且想要多少生物騎在另外一個生物上是沒有限制的,例如你可以放置一隻騎著雞的豬,那隻豬也騎著一隻牛,那隻牛也騎著一隻馬,那隻馬也騎著一隻蠹魚,同時那隻蠹魚也騎著一位村民,這就是"Farmer Brown"。 請注意,如果要使用 RequiredPlayerRange 標籤,那你必須同時使用 MaxNearbyEntities 標籤,同樣的事情也適用於MinSpawnDelayMaxSpawnDelay。最後,請注意,這兩個生怪磚範例指令中使用的y值是~-1,(假設玩家沒有飛行)意思是把生怪磚放在玩家下方一格處。

如果你沒有想要指定特別的玩家,可以使用 @a(所有玩家), @p(最近的玩家)或是 @r(隨機玩家)參數,而不是 <玩家名称>。請記住,你可以在玩家發出的指令中使用@p(最近的玩家)或 @s(自己)作為一個比輸入自己名字更好的替換,因為你對於自己來說最近的玩家將永遠是你。

Part 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:spawner) is the long version and you can leave out the minecraft: part.

/setblock ~2 ~0 ~0 minecraft:spawner{EntityId:Zombie}

This next code is also pretty basic but it includes the 6 basic parameters that can be set.

/setblock ~0 ~-1 ~-3 spawner{EntityId:Skeleton,SpawnRange:4,RequiredPlayerRange:16,SpawnCount:4,MaxNearbyEntities:6,MinSpawnDelay:200,MaxSpawnDelay:800}

Notes:

  • All times are in game ticks (20ths of a second). 200-800 is 10–40 seconds.
  • 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 assuming SpawnCount needs MaxNearbyEntities.
  • 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).
  • 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 occurring spawners have their height cut by 1/3rd due to appearing 1 block above the floor instead of 2.
  • All the values used here are the defaults.

Part 2: Custom monsters

The next thing to do is to modify the spawn data. Spawn data is what tells the spawner you want a non-standard version of a monster, such as a zombie with a diamond sword and a chain helmet.

/setblock ~ ~1 ~ spawner{EntityId:Zombie,SpawnData:{Equipment:[{id:"diamond_sword",Count:1},{},{},{},{id:"minecraft:chain_helmet",Count:1}]}}

Using ~ without any number after it in the coordinates counts as zero. Because of the fact that 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 your custom mob 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. Likewise, if you want him to have leg armor. you have to specify weapon and boot slots, but not chest and helmet slots.
Remember that creatures that burn in sunlight are safe if they have a helmet on, although it damages the helmet instead.
As for 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 its 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 it is highly recommended to use the count tag.

The next example of customized monsters, consists of a skeleton with an enchanted bow (Flame) with a custom mob head (Spider, internet connection required or it's just Steve) with Protection 2 riding a Skeleton Horse.

/setblock ~2 ~1 ~2 spawner replace {EntityId:Skeleton,SpawnData:{Equipment:[{id:261,Count:1,tag:{ench:[{id:50,lvl:1}]}},{},{},{},{id:397,Count:1,Damage:3,tag:{ench:[{id:0,lvl:2}],SkullOwner:MHF_Spider}}],Riding:{id:"EntityHorse",Type:4,Tame:1,SaddleItem:{id:329,Count:1,Damage:0}}}}

Technically, the skeleton would just be sitting on a Skeletal Horse, because the lower creature controls the movement and the horse isn't hostile. Don't try to put zombies on horse back, as 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.

Part 3: SpawnPotentials

Using the SpawnPotentials tag, you can create a mob spawner with multiple mobs in it. It will randomly pick one each time when the timer is reset (a second after spawning the previous mobs). Since these codes contain multiple mobs, they tend to be quite long codes. Thanks to a YouTuber (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 version of the SpawnPotentials code, that is more easy on the eye:br>

/setblock ~0 ~1 ~1 spawner replace {EntityId:Zombie,SpawnRange:6,RequiredPlayerRange:12,SpawnCount:1,MaxNearbyEntities:6,MinSpawnDelay:100,MaxSpawnDelay:600,SpawnData:{Equipment:[{id:268,Count:1},{id:301,Count:1},{id:300,Count:1,tag:{display:{color:5013401}}},{id:299,Count:1,tag:{display:{color:6717235}}},{id:397,Count:1,Damage:3,tag:{SkullOwner:Reimac}}]},SpawnPotentials:[{Type:Zombie,Weight:4,Properties:{Equipment:[{id:268,Count:1,Damage:58},{id:301,Count:1},{id:300,Count:1,tag:{display:{color:5013401}}},{id:299,Count:1,tag:{display:{color:6717235}}},{id:397,Count:1,Damage:3,tag:{SkullOwner:Reimac}}]}},{Type:Skeleton,Weight:2,Properties:{Equipment:[{id:267},{id:301,Count:1,tag:{display:{color:1644825}}},{id:300,Count:1,tag:{display:{color:1644825}}},{id:299,Count:1,tag:{display:{color:1644825}}},{id:397,Count:1,Damage:3,tag:{SkullOwner:2insanepeople}}]}},{Type:Zombie,Weight:4,Properties:{Equipment:[{id:272,Count:1},{id:305,Count:1},{id:304,Count:1},{id:303,Count:1},{id:397,Count:1,Damage:3,tag:{ench:[{id:0,lvl:2}],SkullOwner:Flixnore}}]}},{Type:Zombie,Weight:4,Properties:{Fire:2400,Equipment:[{id:283,Count:1,tag:{ench:[{id:20,lvl:1}]}},{id:317,Count:1},{id:316,Count:1},{id:315,Count:1},{id:86,Count:1,tag:{ench:[{id:0,lvl:2},{id:1,lvl:10}]}}]}},{Type:Zombie,Weight:4,Properties:{Equipment:[{id:267,Count:1,tag:{ench:[{id:16,lvl:2}]}},{id:309,Count:1},{id:308,Count:1},{id:307,Count:1},{id:397,Count:1,Damage:3,tag:{ench:[{id:0,lvl:2}],SkullOwner:2zqa}}]}},{Type:Zombie,Weight:1,Properties:{Equipment:[{id:278,Count:1,tag:{ench:[{id:16,lvl:4},{id:17,lvl:4},{id:18,lvl:4},{id:21,lvl:3},{id:34,lvl:3}]}},{id:313,Count:1,tag:{ench:[{id:1,lvl:4},{id:2,lvl:4}]}},{id:312,Count:1,tag:{ench:[{id:3,lvl:4}]}},{id:311,Count:1,tag:{ench:[{id:0,lvl:4}]}},{id:397,Count:1,Damage:3,tag:{SkullOwner:MHF_Herobrine,ench:[{id:0,lvl:4},{id:1,lvl:4},{id:3,lvl:4},{id:5,lvl:3},{id:6,lvl:1}]}}],CustomNameVisible:1,CustomName:Herobrine,PersistenceRequired:1}}]} It contains a lot of codes, because of the fact that it is actually 6 separate mobs. In order we have:

  • Before the "SpawnPotentials" tag: The starter, which will never pop up again after the first time. If you want to see him again, you have to include him a second time under SpawnPotentials. His appearance is just a random person 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.
  • Same thing, only this time his wooden sword is 2 hits away from breaking.
  • The next one has a ninja-like appearance. This one is a skeleton under his mask, but he's been given an iron sword. All of his leather armor is dyed ninja-black. Skeletons with swords close the gap quicker than zombies, so watch out.
  • Zombie with a stone sword and chain armor, with Protection II on his mobhead.
  • The next one has a gold sword, golden armor, a pumpkin on his head, and he's on fire! The pumpkin is enchanted with Protection II and Fire Resistance X 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.
  • Iron Sword and Armor. Sharpness II on his Sword, Protection II on his mobhead.
  • The final mob, 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 that 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!)

Part 4: Rideable Monsters

Mobs can be ridden by using Minecarts or Boats on their heads. The command is fairly simple:

/setblock ~ ~1 ~ spawner {EntityId:MinecartRideable(or Boat), SpawnData:{Riding:{id:<Entity>}}}

Tips:

  • Some mobs simply can't be spawned with a spawner, such as, sadly, bosses and iron golems. Adding a minecart won't affect them either.
  • 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, which makes them useless to anyone.
  • Endermen cannot be walked around, but they can be forced to teleport by shooting a projectile at them (e.g.; 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 Nether cousins, magma cubes, cannot have their sizes changed.

More commands in fewer command blocks and recursion

There are several ways to combine groups of commands into just one command.

Use the following sets of commands for recursion: /scoreboard objectives add counter dummy
/scoreboard players set target_count counter <target count> /execute if score count counter < target_count counter <chained command>
/execute unless score count counter < target_count counter run scorebard objectives remove counter
/scoreboard players add count counter 1

  • 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 tool that use this tactic. Mr. Garretto makes one-commands and maps here.[即將失效]

Using a map item as a scroll

A YouTuber called SethBling used a map as a scroll to perform commands (summon creatures, teleport). The player will have an empty map in the inventory and when the player uses it, it becomes a filled map which immediately disappears and a redstone task is done.

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 /give.

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.
  • The player may see the map animation when activating the map before it gets deleted.
  • The player cannot use the map item during your playthrough (showing a text message, a path, a drawing, …).

Building the mechanism

The player 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: /give <player> map{display:{Name:"<displayName>",Lore:["<tooltip>"]}}

  • player: the player you want to reach (@p, @a[arguments],...).
  • displayName: the name displayed when you scroll in the hotbar or when you hover the item with your mouse.
  • tooltip: the text below the item name when you hover it.

Detecting the activation of the map

File:Minecraftscroll.jpg

  • 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 the player 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.
  • Check for a fishing rod when the line is reeled in. The /clear syntax involves another argument, the damage value, after the item name:

/clear <player> fishing_rod{Damage:2} Note that spamming the reel, or hooking a mob, may damage it more than 2, so make another one of these every 2.

更多資源

Feare's Command Block Tutorials
Dragnoz' youtube tutorials to a lot of possibilities using data tags
a text tutorial to data tags

另見

Advertisement