# 让水鸭活动起来

# 作者:境界

在材质包完成了水鸭的一切工作后,开发者回到行为包上。在这里,我们可以使用原版的鸡行为去掉一部分多余的内容,增加一些新的行为,来模拟出水鸭的行为状态。

{
  "format_version": "1.16.0",
  "minecraft:entity": {
    "description": {
      "identifier": "design:green_head_duck",
      "is_spawnable": true,
      "is_summonable": true,
      "is_experimental": false,
      "runtime_identifier": "design:green_head_duck"
    }
    },
    "component_groups": {
    },
}
    "components": {
      "minecraft:type_family": {
        "family": [ "duck", "mob" ]
      },
      "minecraft:breathable": {
        "total_supply": 15,
        "suffocate_time": 0
      },
      "minecraft:collision_box": {
        "width": 0.6,
        "height": 0.8
      },
      "minecraft:nameable": {
      },
      "minecraft:health": {
        "value": 4,
        "max": 4
      },
      "minecraft:hurt_on_condition": {
        "damage_conditions": [
          {
            "filters": { "test": "in_lava", "subject": "self", "operator": "==", "value": true },
            "cause": "lava",
            "damage_per_tick": 4
          }
        ]
      },
      "minecraft:movement": {
        "value": 0.25
      },
      "minecraft:damage_sensor": {
        "triggers": {
          "cause": "fall",
          "deals_damage": false
        }
      },
      "minecraft:behavior.rise_to_liquid_level": {
        "priority": 0,
        "liquid_y_offset": -0.5,
        "rise_delta": 0.01,
        "sink_delta": 0.01
      },
      "minecraft:leashable": {
        "soft_distance": 4.0,
        "hard_distance": 6.0,
        "max_distance": 10.0
      },
      "minecraft:balloonable": {
        "mass": 0.5
      },
      "minecraft:navigation.walk": {
        "can_path_over_water": true,
        "can_sink": false,
        "avoid_damage_blocks": true
      },
      "minecraft:movement.basic": {
      },
      "minecraft:jump.static": {
      },
      "minecraft:can_climb": {
      },
      "minecraft:despawn": {
        "despawn_from_distance": {}
      },
      "minecraft:behavior.panic": {
        "priority": 1,
        "speed_multiplier": 1.5
      },
      "minecraft:behavior.tempt": {
        "priority": 4,
        "speed_multiplier": 1.0,
        "items": [
          "wheat_seeds",
          "beetroot_seeds",
          "melon_seeds",
          "pumpkin_seeds"
        ]
      },
      "minecraft:behavior.random_stroll": {
        "priority": 6,
        "speed_multiplier": 1.0
      },
      "minecraft:behavior.look_at_player": {
        "priority": 7,
        "look_distance": 6.0,
        "probability": 0.02
      },
      "minecraft:behavior.random_look_around": {
        "priority": 8
      },
      "minecraft:physics": {
      },
      "minecraft:pushable": {
        "is_pushable": true,
        "is_pushable_by_piston": true
      }
    },

    "events": {
    }
  }
}

1)将format_version格式设置为最新的1.16.0,水鸭作为一个带有生物蛋的生物,我们将is_summonable(可用指令生成的)设置为true(真),is_spawnable(可用生物蛋)设置为true(真),is_experimental(是否是实验玩法打开才能看到的生物)设置为false(否)。同时将runtime_identifier指向自己。

2)行为组内的组合都清空,同时在原本鸡的行为上,加入”minecraft:behavior.rise_to_liquid_level“行为,这是一个来自炽足兽的新行为。可以让生物在水面上下起伏,就像水上的鸭子一样。

3)其中行为内部属性里,priority设置为0,即最高级优先使用的行为。liquid_y_offset设置为-0.5。rise_delta是上升增量,sink_delta是下降增量,来模拟鸭子的上下起伏。这里都设置为0.01。这样一个可爱的绿头鸭就做好了。

https://mc.res.netease.com/pc/zt/20201109161633/mc-dev/assets/img/14_1.199826f4.jpg

进阶

25分钟