chicken.lua 6.5 KB

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