发射器村民交易
Dispenser Villager Trading 是一个 Paper 插件,允许发射器自动执行村民交易。
当发射器面朝村民且其库存中包含某项村民交易的所需材料时,它将自动:
- 选择一项有效交易(随机选取,保留原版发射器行为),
- 使用其库存中的物品支付费用,
- 将结果掉落至发射器后方(或将其放入直接位于其后方的箱子中),
- 更新村民经验与交易使用次数,如同玩家手动交易一般。
此插件还添加了一种仅村民可用的压力板,只有村民才能激活它。
功能
- 发射器交易:发射器可使用自身库存完成任何可用的村民交易——包括双材料交易。村民会正常获得经验,交易也会按正常逻辑锁定/解锁。
- 玩家经验:当发射器执行交易时,玩家将获得如手动交易般的经验。与熔炉经验机制相同。
- 仅村民压力板:一种可合成的自定义压力板(石质压力板 + 绿宝石),仅村民可激活。
公共 API(事件系统)
专用的 API 模块为其他插件暴露了事件接口。
首个事件为:
DispenserVillagerTradeDepositEvent
每当插件尝试将村民交易结果存入箱子时,该事件便会触发。
可用方法如下:
public Inventory getSource();
public Inventory getDestination();
public ItemStack getItem();
public void setItem(ItemStack item);
public boolean isCancelled();
public void setCancelled(boolean cancel);
public HandlerList getHandlers();
public static HandlerList getHandlerList();
要求
- Paper 1.21.10(或任何基于
1.21.10 API 的 Paper 构建版本)
- 服务端需运行 Java 21 运行时环境
安装
- 构建插件 JAR(见下文)或从发布页面下载。
- 将 JAR 文件放入服务器的
plugins/ 目录。
- 启动或重载你的 Paper 服务器。
构建
本项目使用 Gradle。常用任务如下:
你可以仅构建插件 JAR、将其复制到服务器,或运行本地测试服务器。
./gradlew build — 在 plugin/build/libs/ 下构建插件 JAR。
./gradlew copyToServer — 构建 JAR 并将其复制到由 secrets.properties 中 SERVER_LOCATION 指定的服务器目录。
配置
生成的 config.yml 提供以下选项:
allowVillagerDispenserInteractions (布尔值):
若设为 false,除非存在匹配的交易,否则村民站在发射器前方时发射器不会触发。
默认值为 false。
使用提示
- 将发射器面朝村民放置,装入所需的交易材料并通电。插件会选择一项有效交易,扣除费用,并在发射器后方输出结果。
- 合成仅村民压力板(石质压力板 + 绿宝石),以允许村民——以及可选的玩家——激活机械装置,同时防止其他生物触发它们。
- 在发射器正后方放置一个箱子,即可自动收集交易产物。
注意事项
本插件专为 Paper 设计,在其他类型的服务器上可能无法正常运行。
旨在保留核心原版行为的同时添加实用机制:
- 交易随机选取,符合原版发射器行为。
- 村民经验与交易使用次数正常更新。
- 结果物品以自然方式弹出,如同由发射器射出。
- 额外便利功能:
- 交易物品被弹出至发射器后方,避免村民拾取。
- 置于发射器后方的箱子会自动收集交易产出。
- 仅村民压力板允许村民驱动红石电路,而无需担心其他生物干扰。
未来计划
- 通过红石信号强度选择特定交易。
- 将仅村民压力板移至独立插件。或添加更多类型的压力板。
- 向公共 API 添加更多事件以实现更深度的集成。
- 添加对 barrels(木桶)的支持以收集交易结果。
- 增加更多配置选项以更好地模拟原版行为。
反馈与贡献
欢迎提供反馈、报告问题及提交 Pull Request!
访问 GitHub 仓库:DispenserVillagerTrading
Dispenser Villager Trading
Dispenser Villager Trading is a Paper plugin that allows dispensers to perform villager trades automatically.
When a dispenser faces a villager and contains the required ingredients for one of the villager’s trades, it will automatically:
- Select a valid trade (at random, preserving vanilla dispenser behavior),
- Pay the cost using items from its inventory,
- Drop the result behind the dispenser (or insert it into a chest located directly behind it),
- Update villager experience and trade usage as if a player traded manually.
This plugin also adds a villager-only pressure plate that only villagers can activate.
Features
- Dispenser trading: Dispensers can fulfill any available villager trade — including two-ingredient trades — using their own inventory. Villagers gain experience and trades lock/unlock as normal.
- Player Experience: Players gain experience as if they traded manually when dispensers perform trades. Same as Furnace Experience.
- Villager-only pressure plate: A custom craftable pressure plate (stone pressure plate + emerald) that only villagers can activate.
Public API (Event System)
A dedicated API module exposes events for other plugins.
The first event is:
DispenserVillagerTradeDepositEvent
This event fires whenever the plugin attempts to deposit a villager trade result into a chest.
Available methods:
public Inventory getSource();
public Inventory getDestination();
public ItemStack getItem();
public void setItem(ItemStack item);
public boolean isCancelled();
public void setCancelled(boolean cancel);
public HandlerList getHandlers();
public static HandlerList getHandlerList();
Requirements
- Paper 1.21.10 (or any Paper build targeting the
1.21.10 API)
- Java 21 runtime on the server
Installation
- Build the plugin JAR (see below) or download one from the releases page.
- Place the JAR into your server’s
plugins/ directory.
- Start or reload your Paper server.
Building
This project uses Gradle. Common tasks:
You can build only the plugin JAR, copy it to a server, or run a local test server.
./gradlew build — Builds the plugin JAR under plugin/build/libs/.
./gradlew copyToServer — Builds the JAR and copies it to the server directory specified by SERVER_LOCATION in secrets.properties.
Configuration
The generated config.yml provides the following option:
allowVillagerDispenserInteractions (boolean):
If false, dispensers will not fire when a villager stands in front of them unless a matching trade exists.
Defaults to false.
Usage Tips
- Place a dispenser facing a villager, load it with the required trade ingredients, and power it. The plugin selects a valid trade, consumes the payment, and outputs the result behind the dispenser.
- Craft the villager-only pressure plate (stone pressure plate + emerald) to allow villagers — and optionally players — to activate contraptions while preventing other mobs from triggering them.
- Place a chest directly behind the dispenser to automatically collect traded items.
Notes
The plugin is designed specifically for Paper and may not function correctly on other server types.
It aims to preserve core vanilla behavior while adding helpful mechanics:
- Trades are selected randomly, matching vanilla dispenser behavior.
- Villager experience and trade usage update normally.
- Result items are dispensed naturally, as if fired by a dispenser.
- Additional quality-of-life features:
- Traded items are dispensed behind the dispenser so villagers don’t pick them up.
- Chests placed behind the dispenser collect trade outputs automatically.
- A villager-only pressure plate allows villager-driven redstone without mob interference.
Future Plans
- Selecting a specific trade via redstone signal strength.
- Moving the villager-only pressure plate to a dedicated plugin. Or adding more pressure plate types.
- Add more events to the public API for deeper integration.
- Add barrels support for trade result collection.
- Add more configuration options to better mimic vanilla behavior.
Feedback and Contributions
Feedback, issues, and pull requests are welcome!
Visit the GitHub repository: DispenserVillagerTrading
评论 0
登录后参与评分
还没有评论,来抢沙发吧