Files
netease-modsdk-wiki/docs/wiki/loot/trading-behavior.md
2025-03-20 11:52:46 +08:00

1.7 KiB
Raw Blame History

title, category, nav_order, mentions
title category nav_order mentions
交易行为 基础 2
Ciosciaa
MedicalJewel105

交易行为

通过 minecraft:trade_tableminecraft:economy_trade_table 组件可以将实体设置为交易者。这两个组件都会根据指定路径打开交易界面但经济交易组件包含更多与村庄与掠夺版本交易机制相关的配置选项。其他需要添加的AI目标包括 minecraft:behavior.trade_with_player,可选添加 minecraft.behavior:trade_interest(允许生物手持/展示交易物品),以及可能需要添加 "minecraft:trade_resupply": {}

对于基础交易界面,使用 trade_table + trade_with_player 组件即可实现。

  1. 在实体组件中添加 "minecraft:behavior.trade_with_player": {}
  2. 将以下代码复制到实体的组件组中(示例组件组命名为 "wiki:trader":

::: code-group

"minecraft:trade_table": {
	"display_name": "交易实体", // 显示的名称文本
	"table": "trading/trading_entity_trades.json", // 交易表文件路径
	"new_screen": true //设置为 false 时,界面会显示为村庄与掠夺版本之前的样式
}

:::

  1. 确保通过事件添加该组件组。建议在 minecraft:entity_spawned 生成事件中添加,该事件会在实体生成时触发。 若对事件和组件组的运作机制不够熟悉,建议先学习实体入门指南中的相关概念。

:::warning 若直接在主组件中components添加该组件将会导致各种问题包括所有实体交易界面显示空白。由于交易类AI目标的机制问题必须通过组件组形式添加。 :::