duck.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. local S = mobs.intllib
  2. -- Duck by JK Murray and Tirifto
  3. mobs:register_mob("mobs_animal:duck", {
  4. type = "animal",
  5. passive = true,
  6. hp_min = 10,
  7. hp_max = 40,
  8. armor = 200,
  9. collisionbox = {-0.3, -0.75, -0.3, 0.3, 0.1, 0.3},
  10. visual = "mesh",
  11. mesh = "mobs_chicken.x",
  12. -- seems a lot of textures but this fixes the problem with the model
  13. textures = {
  14. {"mobs_duck_drake.png", "mobs_duck_drake.png", "mobs_duck_drake.png", "mobs_duck_drake.png",
  15. "mobs_duck_drake.png", "mobs_duck_drake.png", "mobs_duck_drake.png", "mobs_duck_drake.png",
  16. "mobs_duck_drake.png"},
  17. {"mobs_duck_female.png", "mobs_duck_female.png", "mobs_duck_female.png", "mobs_duck_female.png",
  18. "mobs_duck_female.png", "mobs_duck_female.png", "mobs_duck_female.png", "mobs_duck_female.png",
  19. "mobs_duck_female.png"},
  20. },
  21. child_texture = {
  22. {"mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png",
  23. "mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png"},
  24. },
  25. makes_footstep_sound = true,
  26. sounds = {
  27. random = "mobs_duck",
  28. },
  29. walk_velocity = 3,
  30. run_velocity = 5,
  31. runaway = true,
  32. drops = {
  33. {name = "mobs:duck_raw", chance = 3, min = 1, max = 2},
  34. {name = "mobs:chicken_feather", chance = 5, min = 1, max = 3},
  35. },
  36. water_damage = 0,
  37. lava_damage = 5,
  38. light_damage = 0,
  39. fall_damage = 0,
  40. fall_speed = -8,
  41. fear_height = 100,
  42. animation = {
  43. speed_normal = 15,
  44. stand_start = 0,
  45. stand_end = 1, -- 20
  46. walk_start = 20,
  47. walk_end = 40,
  48. },
  49. floats = 1,
  50. follow = {"farming:wheat_seed", "farming:cotton_seed"},
  51. view_range = 5,
  52. on_rightclick = function(self, clicker)
  53. if mobs:feed_tame(self, clicker, 8, true, true) then return end
  54. if mobs:protect(self, clicker) then return end
  55. if mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) then return end
  56. end,
  57. do_custom = function(self, dtime)
  58. self.egg_timer = (self.egg_timer or 0) + dtime
  59. if self.egg_timer < 10 then
  60. return
  61. end
  62. self.egg_timer = 0
  63. if self.child
  64. or math.random(1, 100) > 1 then
  65. return
  66. end
  67. local pos = self.object:getpos()
  68. minetest.add_item(pos, "mobs:duck_egg")
  69. minetest.sound_play("default_place_node_hard", {
  70. pos = pos,
  71. gain = 1.0,
  72. max_hear_distance = 5,
  73. })
  74. end,
  75. })
  76. local spawn_on = "default:water_source"
  77. if minetest.get_modpath("ethereal") then
  78. spawn_on = "ethereal:bamboo_dirt"
  79. end
  80. mobs:spawn({
  81. name = "mobs_animal:duck",
  82. nodes = {spawn_on},
  83. min_light = 5,
  84. chance = 15000,
  85. active_object_count = 2,
  86. min_height = 0,
  87. day_toggle = true,
  88. })
  89. mobs:register_egg("mobs_animal:duck", S("Duck"), "mobs_duck_inv.png", 0)
  90. mobs:alias_mob("mobs:duck", "mobs_animal:duck") -- compatibility
  91. -- duck egg entity
  92. mobs:register_arrow("mobs_animal:duck_egg_entity", {
  93. visual = "sprite",
  94. visual_size = {x=.5, y=.5},
  95. textures = {"mobs_duck_egg.png"},
  96. velocity = 6,
  97. hit_player = function(self, player)
  98. player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, {
  99. full_punch_interval = 1.0,
  100. damage_groups = {fleshy = 1},
  101. }, nil)
  102. end,
  103. hit_mob = function(self, player)
  104. player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, {
  105. full_punch_interval = 1.0,
  106. damage_groups = {fleshy = 1},
  107. }, nil)
  108. end,
  109. hit_node = function(self, pos, node)
  110. if math.random(1, 10) > 1 then
  111. return
  112. end
  113. pos.y = pos.y + 1
  114. local nod = minetest.get_node_or_nil(pos)
  115. if not nod
  116. or not minetest.registered_nodes[nod.name]
  117. or minetest.registered_nodes[nod.name].walkable == true then
  118. return
  119. end
  120. local mob = minetest.add_entity(pos, "mobs_animal:duck")
  121. local ent2 = mob:get_luaentity()
  122. mob:set_properties({
  123. textures = ent2.child_texture[1],
  124. visual_size = {
  125. x = ent2.base_size.x / 2,
  126. y = ent2.base_size.y / 2
  127. },
  128. collisionbox = {
  129. ent2.base_colbox[1] / 2,
  130. ent2.base_colbox[2] / 2,
  131. ent2.base_colbox[3] / 2,
  132. ent2.base_colbox[4] / 2,
  133. ent2.base_colbox[5] / 2,
  134. ent2.base_colbox[6] / 2
  135. },
  136. })
  137. ent2.child = true
  138. ent2.tamed = true
  139. ent2.owner = self.playername
  140. end
  141. })
  142. -- egg throwing item
  143. local egg_GRAVITY = 9
  144. local egg_VELOCITY = 19
  145. -- shoot egg
  146. local mobs_shoot_egg = function (item, player, pointed_thing)
  147. local playerpos = player:getpos()
  148. minetest.sound_play("default_place_node_hard", {
  149. pos = playerpos,
  150. gain = 1.0,
  151. max_hear_distance = 5,
  152. })
  153. local obj = minetest.add_entity({
  154. x = playerpos.x,
  155. y = playerpos.y +1.5,
  156. z = playerpos.z
  157. }, "mobs_animal:duck_egg_entity")
  158. local ent = obj:get_luaentity()
  159. local dir = player:get_look_dir()
  160. ent.velocity = egg_VELOCITY -- needed for api internal timing
  161. ent.switch = 1 -- needed so that egg doesn't despawn straight away
  162. obj:setvelocity({
  163. x = dir.x * egg_VELOCITY,
  164. y = dir.y * egg_VELOCITY,
  165. z = dir.z * egg_VELOCITY
  166. })
  167. obj:setacceleration({
  168. x = dir.x * -3,
  169. y = -egg_GRAVITY,
  170. z = dir.z * -3
  171. })
  172. -- pass player name to egg for chick ownership
  173. local ent2 = obj:get_luaentity()
  174. ent2.playername = player:get_player_name()
  175. item:take_item()
  176. return item
  177. end
  178. -- egg
  179. minetest.register_node(":mobs:duck_egg", {
  180. description = S("Duck Egg"),
  181. tiles = {"mobs_duck_egg.png"},
  182. inventory_image = "mobs_duck_egg.png",
  183. visual_scale = 0.7,
  184. drawtype = "plantlike",
  185. wield_image = "mobs_duck_egg.png",
  186. paramtype = "light",
  187. walkable = false,
  188. is_ground_content = true,
  189. sunlight_propagates = true,
  190. selection_box = {
  191. type = "fixed",
  192. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  193. },
  194. groups = {snappy = 2, dig_immediate = 3},
  195. after_place_node = function(pos, placer, itemstack)
  196. if placer:is_player() then
  197. minetest.set_node(pos, {name = "mobs:duck_egg", param2 = 1})
  198. end
  199. end,
  200. on_use = mobs_shoot_egg
  201. })
  202. minetest.register_craft({
  203. type = "cooking",
  204. recipe = "mobs:duck_egg",
  205. output = "mobs:chicken_egg_fried",
  206. })
  207. -- raw chicken
  208. minetest.register_craftitem(":mobs:duck_raw", {
  209. description = S("Raw Duck"),
  210. inventory_image = "mobs_duck_raw.png",
  211. on_use = minetest.item_eat(3),
  212. })
  213. -- cooked chicken
  214. minetest.register_craftitem(":mobs:duck_cooked", {
  215. description = S("Cooked Duck"),
  216. inventory_image = "mobs_duck_cooked.png",
  217. on_use = minetest.item_eat(9),
  218. })
  219. minetest.register_craft({
  220. type = "cooking",
  221. recipe = "mobs:duck_raw",
  222. output = "mobs:duck_cooked",
  223. })
  224. -- feather
  225. minetest.register_craftitem(":mobs:chicken_feather", {
  226. description = S("Feather"),
  227. inventory_image = "mobs_chicken_feather.png",
  228. })