“Chemdah 开发者文档:自定义对话触发器”的版本间的差异
来自Purtmars Wikipedia —— 普特莫斯维基
第1行: | 第1行: | ||
{{:Chemdah 开发者文档目录}} | {{:Chemdah 开发者文档目录}} | ||
− | = | + | == 实现方法 == |
− | + | 通过以下方法获取有效的对话信息: | |
+ | <syntaxhighlight lang="kotlin" line="line"> | ||
+ | ConversationManager.getConversation("minecraft", name) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | 通过以下方法实现具体逻辑: | ||
<syntaxhighlight lang="kotlin" line="line"> | <syntaxhighlight lang="kotlin" line="line"> | ||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
第10行: | 第15行: | ||
val name = I18n.get().getName(e.rightClicked) | val name = I18n.get().getName(e.rightClicked) | ||
// 获取有效对话 | // 获取有效对话 | ||
− | val conversation = getConversation("minecraft", name) ?: return | + | val conversation = ConversationManager.getConversation("minecraft", name) ?: return |
// 获取原点(对话实体的头顶坐标,用于播放粒子和定位) | // 获取原点(对话实体的头顶坐标,用于播放粒子和定位) | ||
val origin = e.rightClicked.location.add(0.0, e.rightClicked.height, 0.0) | val origin = e.rightClicked.location.add(0.0, e.rightClicked.height, 0.0) |
2021年4月29日 (四) 00:03的版本
目录
- 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
- 对话相关
- 数据相关
- 任务相关
实现方法
通过以下方法获取有效的对话信息:
ConversationManager.getConversation("minecraft", name)
通过以下方法实现具体逻辑:
@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
}
}