自定义对话触发器 (Chemdah 开发者文档)
来自Purtmars Wikipedia —— 普特莫斯维基
目录
- Chemdah
- 开始
- 基本
- 事件
- ink.ptms.chemdah.api.event.collect.ConversationEvents
- ink.ptms.chemdah.api.event.collect.ObjectiveEvents
- ink.ptms.chemdah.api.event.collect.PlayerEvents
- ink.ptms.chemdah.api.event.collect.QuestEvents
- ink.ptms.chemdah.api.event.collect.TemplateEvents
- ink.ptms.chemdah.api.event.InferEntityHookEvent
- ink.ptms.chemdah.api.event.InferItemHookEvent
- ink.ptms.chemdah.api.event.PartyHookEvent
- 对话相关
- 数据相关
- 任务相关
实现方法
通过以下方法获取触发器为 minecraft:foo 的对话。
ConversationManager.getConversation("minecraft", "foo")
通过以下方法实现具体逻辑:
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun e(e: PlayerInteractAtEntityEvent) {
// 主手交互实体并不在对话中
if (e.hand == EquipmentSlot.HAND && e.player.conversationSession == null) {
// 获取实体名称
val name = I18n.get().getName(e.rightClicked)
// 获取有效对话
val conversation = ConversationManager.getConversation("minecraft", name) ?: return
// 获取原点(对话实体的头顶坐标,用于播放粒子和定位)
val origin = e.rightClicked.location.add(0.0, e.rightClicked.height, 0.0)
// 打开对话
conversation.open(e.player, origin, npcName = name, npcObject = e.rightClicked)
// 取消事件
e.isCancelled = true
}
}