在《我的世界》手机版(基岩版)中,想要实现"打一下动物就骑上去"的功能,需要使用行为包(Behavior Pack)配合JavaScript(GameTest框架)或者直接修改实体行为,纯JS无法直接实现,因为基岩版的JS API主要用于GameTest,不支持直接修改骑乘逻辑。

以下是可行的实现方案:

使用行为包修改实体(推荐,无需JS)
通过修改动物的行为文件,让玩家攻击时触发骑乘。
创建行为包结构
behavior_pack/
├── manifest.json
├── entities/
│ └── pig.json (以猪为例)
└── pack_icon.png
manifest.json
{
"format_version": 2,
"header": {
"name": "RideOnHit",
"description": "打一下就骑上",
"uuid": "你的UUID1",
"version": [1, 0, 0],
"min_engine_version": [1, 20, 0]
},
"modules": [
{
"type": "data",
"uuid": "你的UUID2",
"version": [1, 0, 0]
}
]
}
修改 pig.json(关键部分)
在 minecraft:behavior.rider 或使用触发器:
{
"format_version": "1.20.0",
"minecraft:entity": {
"description": {
"identifier": "minecraft:pig",
"is_spawnable": true,
"is_summonable": true
},
"components": {
"minecraft:rideable": {
"seat_count": 1,
"family_types": ["player"],
"interact_text": "action.interact.ride",
"controlling_seat": 0,
"crouching_skip_interact": true,
"pull_in_entities": true,
"rider_can_interact": true,
"seat_positions": [...]
},
"minecraft:damage_sensor": {
"triggers": [
{
"on_damage": {
"filters": {
"test": "is_family",
"subject": "other",
"value": "player"
},
"event": "minecraft:on_player_hit"
},
"deals_damage": false
}
]
}
},
"events": {
"minecraft:on_player_hit": {
"run_command": {
"command": ["ride @s rider @p"]
}
}
}
}
}
使用 GameTest JS(有限支持)
基岩版的JS API(@minecraft/server)在较新版本中支持部分事件:
import { world } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((event) => {
const { damagingEntity, hitEntity } = event;
// 判断攻击者是玩家,被击的是可骑乘动物
if (damagingEntity.typeId === "minecraft:player" &&
["minecraft:pig", "minecraft:horse", "minecraft:cow"].includes(hitEntity.typeId)) {
// 让玩家骑上动物
try {
hitEntity.getComponent("minecraft:rideable")?.addRider(damagingEntity);
} catch (e) {
console.warn("骑乘失败:" + e);
}
}
});
使用JS的注意事项:
- 需要开启实验性玩法(Beta APIs)
- 需要将JS文件放入行为包的
scripts/目录 - manifest.json 中要声明
script模块 - 手机版需要特定版本(1.20.50+)才稳定支持
entityHitEntity
JS的manifest示例:
{
"format_version": 2,
"header": {
"name": "RideOnHitJS",
"uuid": "UUID-A",
"version": [1, 0, 0],
"min_engine_version": [1, 20, 50]
},
"modules": [
{
"type": "data",
"uuid": "UUID-B",
"version": [1, 0, 0]
},
{
"type": "script",
"language": "javascript",
"uuid": "UUID-C",
"entry": "scripts/main.js",
"version": [1, 0, 0]
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.9.0"
}
]
}
手机版操作步骤
- 用文件管理器找到
Android/data/com.mojang.minecraftpe/files/games/com.mojang/ - 把行为包放进
development_behavior_packs/(手机版需用第三方工具如MT管理器编辑zip) - 创建世界时启用该行为包 + 开启"实验性玩法"
- 进入游戏,打动物即可骑上
注意事项
- ⚠️ 手机版直接编辑文件较麻烦,建议在电脑上做包再传到手机
- ⚠️
damage_sensor方式会让动物受伤但不掉血 - ⚠️ JS方案依赖版本,建议用 1.20.50 以上
- ⚠️ 某些动物(如马、骆驼)本身有骑乘逻辑,需覆盖原有行为
需要我帮你写一个完整的、可直接打包的行为包(含manifest和JS文件内容)吗?告诉我你想针对哪些动物(猪/牛/羊/鸡/马/全部),我可以给你完整代码。

