教學:製作附加包/交易表

出自Minecraft基岩版开发Wiki
交易表
系列教學
所屬系列
難易度
初級
前置知識
實踐裝置
WindowsAndroid
所需軟體

在這之前[編輯]

我們先要看一下村民交易列表的GUI結構(以圖書管理員為例):

這是圖書管理員的交易列表。

可以分為以下要點:

  1. Minecraft將交易列表進行分級,只要達到一定等級才可以解鎖更多交易。
  2. 交易一次可為村民增加交易經驗(交易欄上方的經驗條),積累到一定經驗後可以解鎖下一等級的交易。
  3. 至少要有一級新手級(流浪商人的交易列表預設隱藏)
  4. 每一級中至少有一個或更多的交易。

知道這些遊戲內容後,我們可以繼續下一步的教學。

基本結構[編輯]

交易表的json檔案存放在行為包/trades資料夾中。
新建一個json檔案,放入以下欄位:

{
  "tiers":[
  ]
}

可以看到交易表沒有宣告格式版本和賦命名空間識別碼
"tiers"陣列內,每一個JSON物件都代表著一個交易等級,需填入以下欄位:

[
	{
		"total_exp_required": 0,//交易所需经验
		"groups": []
	}
]

注意:交易表中一定要有所需經驗為0的交易等級!!!
到了"groups"陣列,就要定義交易內容了,每個交易欄位是一個JSON物件,格式如下(從圖書管理員中截取):

{
	"num_to_select": 1,//从以下交易中随机选一个,放置到交易列表。
	"trades": [//交易内容
		{
			"wants": [//被交易物品
				//一个物品定义一个JSON对象
				{
					"item": "minecraft:paper",//物品的赋命名空间标识符
					"quantity": 24,//数量
					"price_multiplier": 0.05//价格乘数
				}
			],
			"gives": [//交易后物品
				{
					"item": "minecraft:emerald",
					"quantity": 1
				}
			],
			"trader_exp": 2,//村民交易后获得的经验
			"max_uses": 16,//村民单种交易上限
			"reward_exp": true//是否给予玩家经验
		}
	]
}

到這裡,基本上交易表應該可以被Minecraft讀取了,下面是一些特殊的定義。

函式引用[編輯]

在圖書管理員的交易列表中,有一種特殊的交易表,用綠寶石和書交易附魔書,這種交易需用到函式。 函式的基本結構如下:

"functions":[
	{
		"function": "需要调用的函数"
	},
	{...}
]

以下是各個函式‌[需要更多資訊]

enchant_book_for_trading[編輯]

將書附上附魔。
結構如下‌[需要驗證]

"functions": [
	{
											"function": "enchant_book_for_trading",
											"base_cost": 2,//附魔失败时物品最少需要的绿宝石
											"base_random_cost": 5,//附魔上1级附魔成功时最少需要的绿宝石
											"per_level_random_cost": 10,//附魔书花费的绿宝石上限(此项加下一项的数值)
											"per_level_cost": 3//每高一级需要的绿宝石
										}

範例[編輯]

如果沒有錯誤,交易表應該為如下形式(以圖書管理員的交易列表為例):

{
	"tiers": [
		{
			"total_exp_required": 0,
			"groups": [
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:paper",
									"quantity": 24,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:emerald",
									"quantity": 1
								}
							],
							"trader_exp": 2,
							"max_uses": 16,
							"reward_exp": true
						}
					]
				},
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 9,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:bookshelf",
									"quantity": 1
								}
							],
							"trader_exp": 1,
							"max_uses": 12,
							"reward_exp": true
						},
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"price_multiplier": 0.2
								},
								{
									"item": "minecraft:book",
									"quantity": 1,
									"price_multiplier": 0.2
								}
							],
							"gives": [
								{
									"item": "minecraft:book",
									"quantity": 1,
									"functions": [
										{
											"function": "enchant_book_for_trading",
											"base_cost": 2,
											"base_random_cost": 5,
											"per_level_random_cost": 10,
											"per_level_cost": 3
										}
									]
								}
							],
							"trader_exp": 1,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				}
			]
		},
		{
			"total_exp_required": 10,
			"groups": [
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:book",
									"quantity": 4,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:emerald",
									"quantity": 1
								}
							],
							"trader_exp": 10,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				},
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 1,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:lantern",
									"quantity": 1
								}
							],
							"trader_exp": 5,
							"max_uses": 12,
							"reward_exp": true
						},
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"price_multiplier": 0.2
								},
								{
									"item": "minecraft:book",
									"quantity": 1,
									"price_multiplier": 0.2
								}
							],
							"gives": [
								{
									"item": "minecraft:book",
									"quantity": 1,
									"functions": [
										{
											"function": "enchant_book_for_trading",
											"base_cost": 2,
											"base_random_cost": 5,
											"per_level_random_cost": 10,
											"per_level_cost": 3
										}
									]
								}
							],
							"trader_exp": 5,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				}
			]
		},
		{
			"total_exp_required": 70,
			"groups": [
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:dye:0",
									"quantity": 5,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:emerald",
									"quantity": 1
								}
							],
							"trader_exp": 20,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				},
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 1,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:glass",
									"quantity": 4
								}
							],
							"trader_exp": 10,
							"max_uses": 12,
							"reward_exp": true
						},
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"price_multiplier": 0.2
								},
								{
									"item": "minecraft:book",
									"quantity": 1,
									"price_multiplier": 0.2
								}
							],
							"gives": [
								{
									"item": "minecraft:book",
									"quantity": 1,
									"functions": [
										{
											"function": "enchant_book_for_trading",
											"base_cost": 2,
											"base_random_cost": 5,
											"per_level_random_cost": 10,
											"per_level_cost": 3
										}
									]
								}
							],
							"trader_exp": 10,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				}
			]
		},
		{
			"total_exp_required": 150,
			"groups": [
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:writable_book",
									"quantity": 1,
									"price_multiplier": 0.05
								},
								{
									"item": "minecraft:writable_book",
									"quantity": 1,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:emerald",
									"quantity": 1
								}
							],
							"trader_exp": 30,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				},
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 4,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:compass",
									"quantity": 1
								}
							],
							"trader_exp": 15,
							"max_uses": 12,
							"reward_exp": true
						},
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 5,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:clock",
									"quantity": 1
								}
							],
							"trader_exp": 15,
							"max_uses": 12,
							"reward_exp": true
						},
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"price_multiplier": 0.2
								},
								{
									"item": "minecraft:book",
									"quantity": 1,
									"price_multiplier": 0.2
								}
							],
							"gives": [
								{
									"item": "minecraft:book",
									"quantity": 1,
									"functions": [
										{
											"function": "enchant_book_for_trading",
											"base_cost": 2,
											"base_random_cost": 5,
											"per_level_random_cost": 10,
											"per_level_cost": 3
										}
									]
								}
							],
							"trader_exp": 15,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				}
			]
		},
		{
			"total_exp_required": 250,
			"groups": [
				{
					"num_to_select": 1,
					"trades": [
						{
							"wants": [
								{
									"item": "minecraft:emerald",
									"quantity": 20,
									"price_multiplier": 0.05
								}
							],
							"gives": [
								{
									"item": "minecraft:nametag",
									"quantity": 1
								}
							],
							"trader_exp": 30,
							"max_uses": 12,
							"reward_exp": true
						}
					]
				}
			]
		}
	]
}

< 生成規則 | 地物 >