1. Wiki
  2. /实体
  3. /客户端实体文件

客户端实体文件

基岩版生物的资源包部分:客户端实体文件中的材质、纹理、几何体、动画、渲染控制器、脚本和刷怪蛋。

行为文件决定生物做什么,客户端实体文件决定它长什么样:用哪个模型、哪套皮肤、哪些动画,以及它的刷怪蛋是什么样子。它放在资源包里。

可以把它看作一份简称列表。你在这里给每个模型、纹理和动画起一个简短的名字,资源包的其他文件就用这些名字来引用它们。

文件

资源包
RP/
  entity/
    ruby_golem.entity.json
  models/
    entity/
      ruby_golem.geo.json
  textures/
    entity/
      ruby_golem.png
      ruby_golem_angry.png
  animations/
    ruby_golem.animation.json
  animation_controllers/
    ruby_golem.animation_controllers.json
  render_controllers/
    ruby_golem.render_controllers.json

只有 entity 文件、一个模型和一张纹理是必需的。其他都是可选的:你可以借用原版的动画和渲染控制器,而不必自己写。

文件名可以随便起。把它和行为包关联起来的是 identifier。

完整示例

下面是实体文件中红宝石傀儡的客户端文件。当傀儡的 wiki:mood 属性为 angry 时,它会显示愤怒的纹理。

RP/entity/ruby_golem.entity.json
{
  "format_version": "1.10.0",
  "minecraft:client_entity": {
    "description": {
      "identifier": "wiki:ruby_golem",
      "materials": {
        "default": "entity_alphatest"
      },
      "textures": {
        "default": "textures/entity/ruby_golem",
        "angry": "textures/entity/ruby_golem_angry"
      },
      "geometry": {
        "default": "geometry.wiki.ruby_golem"
      },
      "animations": {
        "walk": "animation.wiki.ruby_golem.walk",
        "attack": "animation.wiki.ruby_golem.attack",
        "look_at_target": "animation.common.look_at_target",
        "attack_controller": "controller.animation.wiki.ruby_golem.attack"
      },
      "scripts": {
        "scale": "1.2",
        "animate": [
          { "walk": "q.modified_move_speed" },
          "look_at_target",
          "attack_controller"
        ]
      },
      "render_controllers": ["controller.render.wiki.ruby_golem"],
      "spawn_egg": {
        "base_color": "#9b111e",
        "overlay_color": "#f4c2c2"
      }
    }
  }
}

大多数原版客户端文件使用 "format_version": "1.10.0",你的文件用它也是个好选择。本页其余部分会逐一讲解每个字段。

identifier

生物的 ID,必须和行为包中的完全一致:wiki:ruby_golem。如果两者不匹配,生物就会隐形。

materials

材质告诉游戏如何绘制像素:不透明、半透明、发光等等。你从游戏中已有的材质里挑选,并给每个材质起一个简称。

RP/entity/ruby_golem.entity.json(description)
"materials": {
  "default": "entity_alphatest",
  "glow": "entity_emissive_alpha"
}
材质用途
entity完全不透明的皮肤,没有透明像素
entity_alphatest带有完全透明镂空的皮肤。最稳妥的默认选择。
entity_alphablend半透明像素,比如玻璃或史莱姆
entity_emissive_alpha在黑暗中发光的部分,由纹理的 alpha 通道决定

很多原版生物都有以自己命名的材质(pig、iron_golem)。这些是为某一种生物专门调校的,所以你自己的生物最好还是使用通用的 entity... 材质。

textures

每套皮肤的简称。路径从资源包根目录开始,并且不要写 .png。

RP/entity/ruby_golem.entity.json(description)
"textures": {
  "default": "textures/entity/ruby_golem",
  "angry": "textures/entity/ruby_golem_angry"
}

想列多少个都可以。显示哪一个由渲染控制器决定。绘制皮肤的技巧请看像素纹理。

geometry

每个模型的简称。值是写在 .geo.json 文件里面的 identifier,而不是文件名。

RP/entity/ruby_golem.entity.json(description)
"geometry": {
  "default": "geometry.wiki.ruby_golem"
}

一个生物可以有多个模型。比如原版的鸡就有普通、寒带和幼年三种模型。

animations

动画和动画控制器的简称。你可以把自己的和原版的混在一起用。

RP/entity/ruby_golem.entity.json(description)
"animations": {
  "walk": "animation.wiki.ruby_golem.walk",
  "look_at_target": "animation.common.look_at_target",
  "attack_controller": "controller.animation.wiki.ruby_golem.attack"
}

只起名字是不够的:只有列在 scripts.animate(见下文)中,或者由动画控制器启动,它们才会播放。

如果你的骨骼名称对得上,可以借用这些好用的原版动画:

动画动的部位需要的骨骼
animation.common.look_at_target头部转向生物看着的东西head
animation.quadruped.walk行走时的四条腿leg0 到 leg3
animation.humanoid.move行走时的手臂和腿leftarm、rightarm、leftleg、rightleg

animation_controllers

较旧的客户端文件会把控制器单独列在一个数组中,而不是放在 animations 里:

旧写法
"animation_controllers": [
  { "attack": "controller.animation.wiki.ruby_golem.attack" }
]

每一项都是带一个简称的对象。列在这里的控制器会自动运行,不需要 scripts.animate。在 format_version 为 1.10.0 及更新的版本中,通常的做法是把控制器放在 animations 中,再从 scripts.animate 启动它们,就像完整示例里那样。

render_controllers

渲染控制器负责挑选要绘制的几何体、纹理和材质。这个列表可以包含多个控制器,它们都会进行绘制。

RP/entity/ruby_golem.entity.json(description)
"render_controllers": ["controller.render.wiki.ruby_golem"]

对于只有一个模型、一套皮肤和一种材质的生物,你不需要自己写渲染控制器。原版的 controller.render.default 会绘制名为 default 的那些。如果要切换纹理,就自己写一个小控制器:

RP/render_controllers/ruby_golem.render_controllers.json
{
  "format_version": "1.8.0",
  "render_controllers": {
    "controller.render.wiki.ruby_golem": {
      "geometry": "Geometry.default",
      "materials": [{ "*": "Material.default" }],
      "textures": [
        "q.property('wiki:mood') == 'angry' ? Texture.angry : Texture.default"
      ]
    }
  }
}

Geometry.default、Material.default 和 Texture.angry 指的是客户端文件中的简称。materials 中的 * 表示“所有骨骼”。纹理那一行是一个 Molang 判断:生气的傀儡使用愤怒的皮肤。

这之所以能生效,是因为该属性在行为包中设置了 "client_sync": true。没有它,资源包就看不到这个值。

你还可以用 Molang 条件来开关整个渲染控制器。原版苦力怕就是这样实现充能光效的:

带条件的渲染控制器
"render_controllers": [
  "controller.render.wiki.ruby_golem",
  { "controller.render.wiki.ruby_golem_glow": "q.property('wiki:mood') == 'angry'" }
]

scripts

scripts 里存放的是在玩家设备上运行的一小段一小段 Molang。

脚本何时运行用途
initialize生物首次出现时运行一次设置变量的初始值
pre_animation每帧运行,在动画之前计算动画所需的数值
animate每帧运行播放哪些动画和控制器
scale每帧运行让整个模型变大或变小
variables不是脚本,而是一个列表把变量标记为 public,让附着物可以读取

animate

每一项都是 animations 中的一个简称。把它包进一个对象里,就能以 0 到 1 之间的强度播放:

RP/entity/ruby_golem.entity.json(scripts)
"animate": [
  { "walk": "q.modified_move_speed" },
  "look_at_target",
  "attack_controller"
]

傀儡移动得越快,walk 播放得越明显;站着不动时就停下来。look_at_target 则一直播放。

scale

RP/entity/ruby_golem.entity.json(scripts)
"scale": "q.is_baby ? 0.5 : 1.2"

这只会改变生物的外观。它在行为包中设置的碰撞箱大小保持不变。原版蝙蝠就用 "0.35" 来缩小模型。

pre_animation

RP/entity/ruby_golem.entity.json(scripts)
"pre_animation": [
  "v.is_angry = q.property('wiki:mood') == 'angry';"
]

在这里把值计算一次,然后就可以在很多动画中使用 v.is_angry,而不必到处重复同一个长表达式。

spawn_egg

没有 spawn_egg 的话,生物在创造模式物品栏中就没有刷怪蛋。制作刷怪蛋有两种方法。

两种颜色。 游戏会绘制一个标准的蛋,带有底色和斑点:

RP/entity/ruby_golem.entity.json(description)
"spawn_egg": {
  "base_color": "#9b111e",
  "overlay_color": "#f4c2c2"
}

你自己的图片。 使用 item_texture.json 中的一个简称,就像物品图标一样(参见物品纹理):

RP/entity/ruby_golem.entity.json(description)
"spawn_egg": {
  "texture": "wiki_ruby_golem_egg"
}

如果这个简称对应的是多张纹理的列表,就添加 "texture_index" 来选择其中一张,从 0 开始计数。刷怪蛋还需要在行为包中设置 "is_spawnable": true,并在语言文件中添加名称:

RP/texts/en_US.lang
entity.wiki:ruby_golem.name=Ruby Golem
item.spawn_egg.entity.wiki:ruby_golem.name=Ruby Golem Spawn Egg

其他字段

字段作用
enable_attachables设为 true 时,会使用附着物在生物身上显示盔甲和手持物品
hide_armor设为 true 时,隐藏生物穿戴的所有盔甲
held_item_ignores_lighting设为 true 时,手持物品始终以全亮绘制,即使在黑暗中也一样
locators模型上的命名点,比如拴绳的连接位置
particle_effects粒子的简称,供动画使用
sound_effects声音的简称,供动画使用
min_engine_version只有当包的目标版本是这个游戏版本或更新时,才加载此文件

出问题时

你看到的现象最可能的原因
生物隐形了,只看得到影子identifier 与行为包不匹配,或者几何体名称写错了
紫黑色方格纹理路径错误,或者结尾带了 .png
镂空处是黑色而不是透明的用 entity_alphatest 代替 entity
某个动画从不播放它在 animations 中,但不在 scripts.animate 或任何控制器中
没有刷怪蛋缺少 spawn_egg,或者行为包中 is_spawnable 为 false
纹理从不变化该属性缺少 "client_sync": true

更多帮助请看故障排除。完整的生物制作流程请看你的第一个自定义生物。

We use cookies to improve your experience and analyse site traffic. Learn more