在我的世界地下城开发mod的第一天

主要代码:

javascript 复制代码
// peeper_behavior.json
{
  "format_version": "1.19.0",
  "minecraft:entity": {
    "description": {
      "identifier": "dungeons:peeper_creeper",
      "is_spawnable": true,
      "is_summonable": true,
      "is_experimental": false
    },
    "components": {
      // 基础属性
      "minecraft:physics": {},
      "minecraft:health": {
        "value": 20
      },
      "minecraft:movement": {
        "value": 0.25
      },
      
      // 视线检测组件
      "minecraft:sensor": {
        "sensors": {
          "player_looking": {
            "event": "dungeons:player_looking",
            "event_filters": {
              "all_of": [
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "player"
                },
                {
                  "test": "facing_entity",
                  "subject": "other",
                  "operator": "<",
                  "value": 15 // 15度视角阈值
                }
              ]
            }
          }
        }
      },

      // AI行为树
      "minecraft:behavior.melee_attack": {
        "priority": 3,
        "speed_multiplier": 1.0
      },
      "minecraft:behavior.explode": {
        "priority": 1,
        "fuse_length": 0.5, // 半秒后爆炸
        "power": 4,
        "breaks_blocks": true,
        "conditions": {
          "distance_to_target": "< 3"
        }
      }
    },
    
    // 事件响应
    "events": {
      "dungeons:player_looking": {
        // 被注视时冻结移动
        "add": {
          "component_groups": ["freeze_movement"]
        }
      },
      "dungeons:start_chase": {
        // 开始追击时同步玩家速度
        "trigger": {
          "event": "minecraft:entity_spawned",
          "target": "self"
        },
        "set_property": {
          "movement_speed": "query.target(0).movement_speed"
        }
      }
    },
    
    // 组件组
    "component_groups": {
      "freeze_movement": {
        "minecraft:movement": {
          "value": 0
        }
      }
    }
  }
}

实现说明:

  1. 视线检测

    使用facing_entity检测组件,当玩家视角与生物角度小于15度时触发冻结事件。

  2. 动态速度同步

    通过set_property在追击事件中实时获取玩家速度值,并应用到生物移动组件。

  3. 快速爆炸机制

    设置fuse_length为0.5秒,当距离玩家小于3格时立即触发爆炸。

  4. 状态切换

    使用组件组动态修改移动速度,实现冻结/追击的状态切换。

相关推荐
红海云4 分钟前
Kimi 双端接入 CloudBase 的工程价值
人工智能·语言模型
+VX:Fegn089535 分钟前
计算机毕业设计|基于springboot + vue蛋糕店管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·课程设计
计算机编程-吉哥1 小时前
YOLO26 vs YOLO11 vs YOLOv8:深度学习咖啡果实成熟度分割系统【计算机毕业设计选题推荐】
人工智能·python·深度学习·yolo·django·毕业设计
冬奇Lab1 小时前
一年前没启动 AI 提效的团队,今年在付什么钱?
人工智能
彧azz1 小时前
算法设计与分析:贪心与动态规划
数据结构·学习·算法·贪心算法·动态规划
NeoGressAI外贸数字化2 小时前
IOR新规9月18日生效:Form 5106六项资料自查清单
人工智能
Nicander2 小时前
我给 Excalidraw 做了一个本地工作区:DrawSpace
前端·开源
根目录下的猫2 小时前
RK3588适配的轻量级AI模型推荐
人工智能·后端·python·目标检测
weixin_6682 小时前
Cursor 插件使用说明:Linear 与 Figma
人工智能·cursor
一条小小yu3 小时前
基于数据库唯一索引 + 过期时间的分布式锁
学习