如何手搓Java數(shù)據(jù)包
這次咱們用到的是數(shù)據(jù)包中的functions,用這個Functions做一點特殊的物品,那么下文開始制作。?
#首先?
先創(chuàng)建一個任意名稱的文件夾,然后在文件夾里面創(chuàng)建一個data的新文件夾和一個pack.mcmeta文件,然后咱們先在data文件夾里面再創(chuàng)建兩個新文件夾,一個是MC原版的命名空間另一個是我們自定義的新命名空間,那么我們先在data文件夾里面創(chuàng)建一個minecraft的文件夾,然后再創(chuàng)建一個Tutorial_pack的文件夾,接下來我們在/data/minecraft/路徑下的Minecraft文件夾里創(chuàng)建一個tags文件夾,并再到這個tags文件夾里再創(chuàng)建一個functions文件夾。?
#接下來?
咱們先到/data/minecraft/tags/functions路徑下的functions文件夾里創(chuàng)建一個load.json和一個tick.json的文件。
提示:load.json文件中的代碼意思是當玩家在地圖里面輸入/reload并回車時就會運行的命令,
tick.json文件中的代碼意思是重復執(zhí)行某條命令,接下來開始寫這兩個文件里的代碼:?
load.json:
{"replace":false,"values":["Tutorial_pack:load"]};?
tick.json:
{"replace":false,"values":["Tutorial_pack:tick"]}?
#第2部分(Tutorial_pack內(nèi)部文件)?
首先在/data/Tutorial_pack/路徑下的文件夾內(nèi)再創(chuàng)建一個functions文件夾,咱們在這個functions文件夾里面創(chuàng)建三個新文件:?
load.mcfunction?
pos.load.mcfunction?
tick.mcfunction?
開始繼續(xù)寫代碼時間,三個文件里面不同的指令。?
load.mcfunction中含有的指令:?
#創(chuàng)建記分板??
scoreboard objectives add pos_store dummy?
scoreboard objectives add hp health?
scoreboard objectives add login dummy?
scoreboard objectives add signin dummy? ?
#創(chuàng)建boss欄并顯示在上方的位置??
bossbar add pos [{"text":"所屬坐標值>>","color":"blue","bold":true},{"text":" ","color":"red"},{"text":" X:","color":"red","bold":true},{"score":{"name":"x","objective":"pos_store"},"color":"red"},{"text":" ","color":"yellow"},{"text":"Y:","color":"yellow","bold":true},{"score":{"name":"y","objective":"pos_store"},"color":"yellow"},{"text":" ","color":"green"},{"text":"Z:","color":"green","bold":true},{"score":{"name":"z","objective":"pos_store"},"color":"green"},{"text":"您的血量:"},{"score":{"name":"@p","objective":"hp"}},{"text":" "},{"text":"<<","color":"blue","bold":true}]??
#預設置?
bossbar set pos players @p? ?
bossbar set pos color green? ?
bossbar set pos style notched_10??
bossbar set pos max 20?
#加載成功之后輸出?
tellraw @a [{"text":"[","color":"blue","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":"GoldPack","color":"yellow","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":"]","color":"blue","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false},{"text":"內(nèi)置數(shù)據(jù)包加載完畢","color":"green","bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false}]?
pos.mcfunction文件中含有的指令:?
#獲取坐標??
execute store result score x pos_store run data get entity @p Pos[0] 1000?
execute store result score y pos_store run data get entity @p Pos[1] 1000??
execute store result score z pos_store run data get entity @p Pos[2] 1000?
#顯示在快捷物品欄?
title @a actionbar [{"text":"所屬坐標值>>","color":"blue","bold":true},{"text":" ","color":"red"},{"text":" X:","color":"red","bold":true},{"score":{"name":"x","objective":"pos_store"},"color":"red"},{"text":" ","color":"yellow"},{"text":"Y:","color":"yellow","bold":true},{"score":{"name":"y","objective":"pos_store"},"color":"yellow"},{"text":" ","color":"green"},{"text":"Z:","color":"green","bold":true},{"score":{"name":"z","objective":"pos_store"},"color":"green"},{"text":" "},{"text":"您的血量:","color":"green","bold":true},{"score":{"name":"@p","objective":"hp"}},{"text":" "},{"text":"<<","color":"blue","bold":true}]? ?
#使記分板的數(shù)值與boss欄的數(shù)值保持同步(這么做是為了方便下一步的制作)?
execute store result bossbar pos value run data get entity @a[limit=1] Health? ?
execute store result score @p hp run data get entity @a[limit=1] Health?
tick.mcfunction文件中含有的指令:?
#運行主文件?
function gold_pack:pos? ?
#使boss欄的坐標實時顯示?
bossbar set pos name [{"text":"所屬坐標值>>","color":"blue","bold":true},{"text":" ","color":"red"},{"text":" X:","color":"red","bold":true},{"score":{"name":"x","objective":"pos_store"}},{"text":" ","color":"yellow"},{"text":"Y:","color":"yellow","bold":true},{"score":{"name":"y","objective":"pos_store"}},{"text":" ","color":"green"},{"text":"Z:","color":"green","bold":true},{"score":{"name":"z","objective":"pos_store"}},{"text":" "},{"text":"<<","color":"blue","bold":true}]?
#達到或超過限定數(shù)值(20)時變色?
execute if score @p hp matches ..20 run bossbar set pos color green?
execute if score @p hp matches 20.. run bossbar set pos color red?
?
這次數(shù)據(jù)包玩法就這樣,可以自己制作,當然這個只是用來快速鎖定坐標的。?