教程:制作附加包/交易表

From Minecraft基岩版开发Wiki
交易表
系列教程
所属系列
难度
初级
前置知识
实践设备
WindowsAndroid
所需软件

在这之前[edit]

我们先要看一下村民交易列表的GUI结构(以图书管理员为例):

这是图书管理员的交易列表。

可以分为以下要点:

  1. Minecraft将交易列表进行分级,只要达到一定等级才可以解锁更多交易。
  2. 交易一次可为村民增加交易经验(交易栏上方的经验条),积累到一定经验后可以解锁下一等级的交易。
  3. 至少要有一级新手级(流浪商人的交易列表默认隐藏)
  4. 每一级中至少有一个或更多的交易。

知道这些游戏内容后,我们可以继续下一步的教程。

基本结构[edit]

交易表的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读取了,下面是一些特殊的定义。

函数引用[edit]

在图书管理员的交易列表中,有一种特殊的交易表,用绿宝石和书交易附魔书,这种交易需用到函数。 函数的基本结构如下:

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

以下是各个函数‌[需要更多信息]

enchant_book_for_trading[edit]

将书附上附魔。
结构如下‌[需要验证]

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

示例[edit]

如果没有错误,交易表应该为如下形式(以图书管理员的交易列表为例):

{
	"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
						}
					]
				}
			]
		}
	]
}

< 生成规则 | 地物 >