微软自定义生物
样例中json的配置方式可参考以下链接中的add-on及animation documentation
https://minecraft.gamepedia.com/Add-on
以增加自定义生物minehero:cool_girl为例 行为包behavior_pack/entities目录下增加cool_girl.json
x{
"format_version": "1.8.0",
"minecraft:entity": {
"description": {
"identifier": "minehero:cool_girl",
"is_spawnable": true,
"is_summonable": true,
//is_experimental用于设置该生物是否是实验性的,实验性实体只有在开启实验性玩法时才可生成
"is_experimental": true,
"runtime_identifier": "minecraft:armor_stand"
},
"component_groups": {
"minecraft:skeleton_horse_adult": {
"minecraft:collision_box": {
"width": 0.25,
"height": 2
},
"minecraft:rideable": {
"priority": 0,
"seat_count": 1,
"family_types": [
"player"
],
"interact_text": "action.interact.ride.horse",
"seats": {
"position": [ 0.0, 0.2, -0.2 ]
}
},
"minecraft:behavior.player_ride_tamed": {
},
"minecraft:input_ground_controlled": {
}
}
},
"components": {
"minecraft:type_family": {
"family": [ "skeletonhorse", "undead" ]
},
"minecraft:breathable": {
"totalSupply": 15,
"suffocateTime": 0,
"breathesWater": true
},
"minecraft:health": {
"value": 15,
"max": 15
},
"minecraft:fall_damage": {
"value": 0.0
},
"minecraft:movement": {
"value": 0.3
},
"minecraft:underwater_movement": {
"value": 0.08
},
"minecraft:tamemount": {},
"minecraft:navigation.walk": {
"is_amphibious": true,
"avoid_water": true
},
"minecraft:movement.basic": {
},
"minecraft:jump.static": {
},
"minecraft:nameable": {
},
"minecraft:balloonable": {
},
"minecraft:is_tamed": {
},
"minecraft:physics": {
}
},
"events": {
"minecraft:entity_spawned": {
"randomize": [
{
"weight": 36,
"add": {
"component_groups": [
"minecraft:skeleton_horse_adult"
]
}
}
]
}
}
}
}
资源包resource_pack/animation_controllers目录下增加cool_girl.json
xxxxxxxxxx
{
"format_version": "1.8.0",
"animation_controllers": {
"controller.animation.cool_girl.general": {
"states": {
"default": {
"animations": [
//animations字段必填,格式为list的格式,list内为多个dict,dict的key为动作名,value为list,用于配置动作融合的值,默认为1.0
{"rotate": []}
],
"transitions": [
//transitions可选,用于设置动作的切换
{"moving":"query.ground_speed"}
]
},
"moving": {
//parameters字段可选,用来做animations的动画融合参数
"parameters": ["query.ground_speed"],
"animations": [
//key为"0.0"表示的是上述参数"query.ground_speed"值为0.0时的融合取值为0.0,融合取值的范围为0.0~1.0
{"move": [{"0.0": 0.0, "8.0": 1.0, "10.0": 0.0}]},
{"speed_up": [{"10.0": 0.0, "12": 1.0, "18.0": 0.0}]},
{"rush": [{"12": 0.0, "15.8": 1.0}]}
],
"transitions": [
//以“query.mod.”开头的字段表示mod脚本驱动的字段,需要在脚本的客户端系统里调用RegisterExpressionNode(str, function),参见本文档中“脚本注册驱动节点”部分
{"default":"query.mod.is_rotating"}
]
}
}
}
}
}
资源包resource_pack/animations目录下增加cool_girl.json
xxxxxxxxxx
{
"format_version": "1.8.0",
"animations": {
"animation.cool_girl.rush": {
"loop": true,
"animation_length": 0.83333,
"bones": {
"Body": {
"rotation": {
"0.0333": [5, 0, 0],
"0.0833": [5, -5, 0],
"0.15": [5, 0, 0],
"0.2167": [0, 0, 0],
"0.3": [5, 0, 0],
"0.3667": [5, 5, 0],
"0.4333": [0, 0, 0],
"0.5167": [5, -5, 0],
"0.6": [5, -5, -5],
"0.6667": [5, -5, 5],
"0.7167": [0, -10, 2.67],
"0.7667": [5, -5, 0],
"0.8167": [-5, -1.5, 0],
"0.8333": [5, 0, 0]
},
"position": {
"0.0": [0, 10, 0],
"0.35": [0, 0, 0],
"0.6833": [0, 10, 0],
"1.0": [0, 0, 0],
"1.3333": [0, 10, 0]
}
}
}
},
"animation.cool_girl.speed_up": {
"loop": true,
"animation_length": 1.34,
"bones": {
"Body": {
"rotation": {
"0.0": [0, 0, 0],
"0.35": [25, 0, 0],
"0.6833": [0, 0, 0],
"1.0": [-25, 0, 0],
"1.3333": [0, 0, 0]
},
"position": {
"0.0": [0, 1, 0],
"0.35": [0, 0, 0],
"0.6833": [0, 1, 0],
"1.0": [0, 0, 0],
"1.3333": [0, 1, 0]
}
}
}
},
"animation.cool_girl.move": {
"loop": true,
"animation_length": 1.01,
"bones": {
"Body": {
"rotation": {
"0.0": [0, 0, 0],
"0.35": [5, 0, 0],
"0.6833": [0, 0, 0],
"1.0": [-5, 0, 0]
},
"position": {
"0.0": [0, 0, 0],
"0.5": [0, 1, 0],
"1.0": [0, 0, 0]
}
}
}
},
"animation.cool_girl.rotate": {
"loop": true,
"animation_length": 1.01,
"bones": {
"Body": {
"rotation": {
"0.0": [0, 0, 0],
"0.5": [0, 180, 0],
"0.75": [0, 270, 0],
"1.0": [0, 360, 0]
}
}
}
}
}
}
资源包resource_pack/entity目录下增加cool_girl.json
xxxxxxxxxx
{
"format_version": "1.8.0",
"minecraft:client_entity": {
"description": {
"identifier": "minehero:cool_girl",
"materials": {
"default": "armor_stand"
},
"textures": {
"default": "textures/entity/cool_girl"
},
"animations": {
"speed_up": "animation.cool_girl.speed_up",
"rush": "animation.cool_girl.rush",
"move": "animation.cool_girl.move"
},
"animation_controllers": [
{"general": "controller.animation.cool_girl.general"}
],
"geometry": {
"default": "geometry.cool_girl"
},
"render_controllers": [ "controller.render.function_block" ],
"spawn_egg": {
"texture": "spawn_egg",
"texture_index": 18
}
}
}
}
资源包resource_pack/models/entity目录下增加cool_girl.json
xxxxxxxxxx
{
"format_version": "1.8.0",
"geometry.cool_girl": {
"texturewidth": 256,
"textureheight": 256,
"visible_bounds_width": 4,
"visible_bounds_height": 2,
"visible_bounds_offset": [0, 1, 0],
"bones": [
{
"name": "Body",
"pivot": [0, 13, 9],
"cubes": [
{"origin": [-5, 5, -15], "size": [10, 8, 7], "uv": [0, 40]},
{"origin": [5, 7, 3], "size": [5, 9, 5], "uv": [21, 75]},
{"origin": [-8, 2, -8], "size": [16, 5, 11], "uv": [0, 56]},
{"origin": [-10, 7, 8], "size": [20, 8, 5], "uv": [27, 0]},
{"origin": [-10, 8, 13], "size": [20, 6, 4], "uv": [32, 14]},
{"origin": [-9, 7, 17], "size": [18, 6, 3], "uv": [43, 27]},
{"origin": [-9, 5, 20], "size": [18, 6, 3], "uv": [36, 41]},
{"origin": [-10, 7, 3], "size": [5, 9, 5], "uv": [21, 75]},
{"origin": [-5, 7, 6], "size": [10, 10, 3], "uv": [0, 89]},
{"origin": [-5, 7, 5], "size": [10, 7, 1], "uv": [0, 80]},
{"origin": [-9, 17, 12], "size": [18, 1, 3], "uv": [179, 1]},
{"origin": [-5, 7, 1], "size": [10, 1, 4], "uv": [0, 74]},
{"origin": [-5, 3, -24], "size": [10, 9, 9], "uv": [0, 21]},
{"origin": [-5, 2, -26], "size": [10, 9, 2], "uv": [0, 9]},
{"origin": [-5, 2, -27], "size": [10, 6, 1], "uv": [0, 0]},
{"origin": [9, 3, -7], "size": [2, 7, 14], "uv": [99, 39]},
{"origin": [7, 3, -8], "size": [2, 5, 11], "uv": [70, 74]},
{"origin": [-9, 3, -8], "size": [2, 5, 11], "uv": [70, 74]},
{"origin": [-11, 3, -7], "size": [2, 7, 14], "uv": [223, 0]},
{"origin": [-13, 1, -8], "size": [6, 8, 1], "uv": [28, 94]},
{"origin": [-12, 0, -24], "size": [6, 8, 1], "uv": [51, 80]},
{"origin": [-13, 0, -23], "size": [7, 9, 15], "uv": [134, 41]},
{"origin": [-11, 9, -22], "size": [5, 1, 14], "uv": [29, 78]},
{"origin": [-9, 10, -19], "size": [3, 1, 11], "uv": [175, 12]},
{"origin": [6, 15, 11], "size": [1, 2, 2], "uv": [178, 14]},
{"origin": [-7, 15, 11], "size": [1, 2, 2], "uv": [178, 14]},
{"origin": [-10, 10, -4], "size": [1, 1, 7], "uv": [78, 1]},
{"origin": [9, 10, -4], "size": [1, 1, 7], "uv": [109, 1]},
{"origin": [-10, 2, -7], "size": [2, 1, 13], "uv": [84, 37]},
{"origin": [8, 2, -7], "size": [2, 1, 13], "uv": [84, 37]},
{"origin": [-6, 2, 4], "size": [12, 5, 1], "uv": [132, 0]},
{"origin": [-6, 2, 6], "size": [12, 5, 1], "uv": [132, 0]},
{"origin": [-6, 2, 8], "size": [12, 5, 1], "uv": [132, 0]},
{"origin": [-6, 2, 10], "size": [12, 5, 1], "uv": [132, 0]},
{"origin": [-6, 2, 12], "size": [12, 5, 1], "uv": [132, 0]},
{"origin": [-5, 3, 4], "size": [10, 4, 18], "uv": [134, 9]},
{"origin": [3, 2, 14], "size": [5, 3, 10], "uv": [46, 54]},
{"origin": [-8, 2, 14], "size": [5, 3, 10], "uv": [46, 54]},
{"origin": [-16, 0, 11], "size": [6, 14, 13], "uv": [84, 0]},
{"origin": [6, 2, -19], "size": [3, 3, 33], "uv": [183, 37]},
{"origin": [-5, 10, -8], "size": [10, 2, 1], "uv": [121, 40]},
{"origin": [-1, 11, -7], "size": [2, 2, 1], "uv": [41, 72]},
{"origin": [-3, 10, -6], "size": [1, 4, 1], "uv": [52, 72]},
{"origin": [2, 10, -6], "size": [1, 4, 1], "uv": [52, 72]},
{"origin": [-2, 10, -6], "size": [4, 1, 1], "uv": [68, 72]},
{"origin": [-6, 10, -10], "size": [12, 4, 1], "uv": [82, 65]},
{"origin": [-3, 13, -15], "size": [6, 1, 5], "uv": [88, 72]},
{"origin": [-2, 12, -24], "size": [4, 1, 9], "uv": [72, 91]},
{"origin": [-2, 11, -26], "size": [4, 1, 2], "uv": [112, 63]},
{"origin": [-1, 8, -28], "size": [2, 4, 2], "uv": [124, 62]},
{"origin": [6, 10, -19], "size": [3, 1, 11], "uv": [175, 12]},
{"origin": [6, 9, -22], "size": [5, 1, 14], "uv": [29, 78]},
{"origin": [6, 0, -24], "size": [6, 8, 1], "uv": [51, 80]},
{"origin": [6, 0, -23], "size": [7, 9, 15], "uv": [134, 41]},
{"origin": [10, 0, 11], "size": [6, 14, 13], "uv": [84, 0]},
{"origin": [7, 1, -8], "size": [6, 8, 1], "uv": [28, 94]},
{"origin": [-9, 2, -19], "size": [3, 3, 33], "uv": [183, 37]},
{"origin": [-7, 6, -28], "size": [14, 1, 2], "uv": [0, 109]},
{"origin": [-7, 4, -28], "size": [14, 1, 2], "uv": [0, 109]},
{"origin": [-10, 1, -28], "size": [20, 3, 3], "uv": [0, 129]},
{"origin": [-12, 1, -30], "size": [24, 1, 3], "uv": [0, 143]},
{"origin": [10, 0, -27], "size": [2, 4, 3], "uv": [0, 116]},
{"origin": [-12, 0, -27], "size": [2, 4, 3], "uv": [0, 116]},
{"origin": [12, 0, -27], "size": [2, 4, 3], "uv": [0, 116]},
{"origin": [-14, 0, -27], "size": [2, 4, 3], "uv": [0, 116]}
]
},
{
"name": "S",
"parent": "Body",
"pivot": [0, 13, 9],
"cubes": [
{"origin": [-12, 12, -17], "size": [1, 2, 5], "uv": [108, 74]},
{"origin": [-12, 10, -19], "size": [1, 2, 6], "uv": [107, 83]},
{"origin": [-12, 9, -20], "size": [1, 1, 9], "uv": [129, 78]},
{"origin": [-4, 11.5, -17], "size": [8, 2, 1], "uv": [165, 137]},
{"origin": [-16.5, 2.5, 10], "size": [7, 12, 14], "uv": [216, 141]},
{"origin": [-17, 0, 8], "size": [6, 1, 13], "uv": [169, 185]},
{"origin": [-1, 17, 11], "size": [2, 3, 20], "uv": [163, 209]},
{"origin": [-1, 14, 10], "size": [2, 3, 7], "uv": [14, 116]},
{"origin": [-8, 15, 9], "size": [1, 2, 1], "uv": [59, 252]},
{"origin": [-8, 17, -8], "size": [1, 1, 17], "uv": [219, 237]},
{"origin": [-8, 16, -12], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [-8, 15, -16], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [-8, 14, -20], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [-8, 13, -21], "size": [1, 1, 1], "uv": [41, 253]},
{"origin": [-8, 10, -22], "size": [1, 3, 1], "uv": [33, 238]},
{"origin": [-4, 4, 6], "size": [8, 8, 21], "uv": [68, 137]},
{"origin": [-3, 12, 20], "size": [6, 1, 5], "uv": [158, 74]},
{"origin": [-5, 5, 5], "size": [1, 6, 21], "uv": [211, 108]},
{"origin": [-3, 3, 5], "size": [6, 1, 21], "uv": [158, 74]},
{"origin": [4, 5, 5], "size": [1, 6, 21], "uv": [211, 108]},
{"origin": [11, 9, -20], "size": [1, 1, 9], "uv": [129, 78]},
{"origin": [11, 10, -19], "size": [1, 2, 6], "uv": [107, 83]},
{"origin": [11, 12, -17], "size": [1, 2, 5], "uv": [108, 74]},
{"origin": [-4, 11.5, -19], "size": [8, 2, 1], "uv": [165, 137]},
{"origin": [-4, 11.5, -21], "size": [8, 2, 1], "uv": [165, 137]},
{"origin": [-4, 11.5, -23], "size": [8, 2, 1], "uv": [165, 137]},
{"origin": [-5, 8.5, -30], "size": [2, 2, 4], "uv": [108, 97]},
{"origin": [9.5, 2.5, 10], "size": [7, 12, 14], "uv": [216, 141]},
{"origin": [7, 10, -22], "size": [1, 3, 1], "uv": [33, 238]},
{"origin": [7, 13, -21], "size": [1, 1, 1], "uv": [41, 253]},
{"origin": [7, 14, -20], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [7, 15, -16], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [7, 16, -12], "size": [1, 1, 4], "uv": [52, 250]},
{"origin": [7, 17, -8], "size": [1, 1, 17], "uv": [219, 237]},
{"origin": [7, 15, 9], "size": [1, 2, 1], "uv": [59, 252]},
{"origin": [3, 8.5, -30], "size": [2, 2, 4], "uv": [108, 97]}
]
}
]
}
}
资源包resource_pack/render_controllers目录下增加function_block.json
xxxxxxxxxx
{
"format_version": "1.8.0",
"render_controllers": {
"controller.render.function_block": {
"geometry": "Geometry.default",
"materials": [ { "*": "Material.default" } ],
"textures": [ "Texture.default" ]
}
}
}
资源包resource_pack/textures/entity目录下增加cool_girl.png贴图
创建微软自定义生物
xxxxxxxxxx
self.CreateEngineEntityByTypeStr("minehero:cool_girl", pos, rot)
脚本注册驱动节点
xxxxxxxxxx
import client.extraClientApi as clientApi
ClientSystem = clientApi.GetClientSystemCls()
class AnimationTestClientSystem(ClientSystem):
def __init__(self, namespace, systemName):
ClientSystem.__init__(self, namespace, systemName)
self.mRotating = False
# 这里注册了"query.mod.is_rotating"的计算节点,调用self.HandleMolangScriptPyEvent
self.RegisterExpressionNode("query.mod.is_rotating", self.HandleMolangScriptPyEvent)
#参数为entityId,函数返回float或者int的值
def HandleMolangScriptPyEvent(self, entityId):
if self.mRotating:
self.mRotating = False
return 1
return 0
tool_table战利品表
- 自定义物品的identifier可用作loot_table配置掉落物。可参考CustomItemsMod行为包的
loot_tables\entities\zombie.json
,里面将僵尸的掉落物由腐肉改为customitems:test0物品。原生生物只需要在该路径下添加对应的生物名.json
文件来为其配置战利品表即可,如果需要为自定义生物添加对应的战利品表,首先需要在行为包behavior_pack/entities
目录对应的json文件比如上面微软自定义生物例子的cool_girl.json中的"conponents"
下添加一个"minecraft:loot"
组件来指定对应的战利品表:
xxxxxxxxxx
"conponents": {
"minecraft:loot": {
"table": "loot_tables/entities/cool_girls.json"
}
}
需要注意的是,behavior_pack/entities
目录下的json文件中,"runtime_identifier": "minecraft:chicken"
这一行所继承的是可掉落物品的生物时,其战利品表才能生效。
- 以
zombie.json
为例,该战利品表的格式如下:
xxxxxxxxxx
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "customitems:test0",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 2
}
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
}
]
},
{
"conditions": [
{
"condition": "killed_by_player"
},
{
"condition": "random_chance_with_looting",
"chance": 0.025,
"looting_multiplier": 0.01
}
],
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:iron_ingot",
"weight": 1
},
{
"type": "item",
"name": "minecraft:carrot",
"weight": 1
},
{
"type": "item",
"name": "minecraft:potato",
"weight": 1
}
]
}
]
}
下面对部分节点进行解释说明,详细的节点数据可参考 我的世界wiki战利品表
"pools": 这个实体的随机池的列表。每个随机池中都会随机抽取列表(entries)里面的物品。每个随机池都会指定其抽取次数(rolls)。
"conditions": 决定了使用这个随机池的条件。如果指定了多个条件,则必须都满足。
"rolls":决定了在此随机池中抽奖的次数。
"entries": 这个池中能抽出的东西列表。每一次抽奖会随机根据权重选择一个被抽出项(如果它符合指定条件)。
"type": 被抽出项种类的命名空间ID值。 可以填写
item
选择物品项、tag
选择物品标签、loot_table
以另一个战利品表生成物品、group
选择子项、alternatives
从列表中选择一个子项、sequence
选择子项,直到有一个子项无法选择为止、dynamic
生成方块的特定掉落物、empty
什么都不生成。"name":
- 如果type是'item',则填写物品的ID。比如
diamond
。默认在没有被functions
影响的情况下,其数量为1。也可以是自定义物品的ID,比如customitems:test0
。 - 如果type是'tag',则填写使用的物品标签。比如
arrows
。 - 如果type是'loot_table',则填写使用的战利品表。比如
gameplay/fishing/junk
。 - 如果type是'dynamic',则填写
contents
指定方块实体的内容物或self
指定旗帜或玩家的头颅。
- 如果type是'item',则填写物品的ID。比如
"weight": 决定了这个物品被选择的权重。 这个值越高物品便越容易被选择(概率为这个物品的权重/所有考虑的物品权重之和) 。
"functions": 决定了抽中这个物品时对其执行函数(不是数据包中的函数)。如果没有被设置,它将不会被使用。必须按照顺序排放(会按照顺序执行)