chicken.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. local S = mobs.intllib
  2. -- Chicken by JK Murray and Sirrobzeroone
  3. mobs:register_mob("mobs_animal:chicken", {
  4. stepheight = 0.6,
  5. type = "animal",
  6. passive = true,
  7. hp_min = 5,
  8. hp_max = 10,
  9. armor = 200,
  10. collisionbox = {-0.3, -0.75, -0.3, 0.3, 0.1, 0.3},
  11. visual = "mesh",
  12. mesh = "mobs_chicken.b3d",
  13. textures = {
  14. {"mobs_chicken.png"}, -- white
  15. {"mobs_chicken_brown.png"},
  16. {"mobs_chicken_black.png"},
  17. },
  18. child_texture = {
  19. {"mobs_chick.png"},
  20. },
  21. makes_footstep_sound = true,
  22. sounds = {
  23. random = "mobs_chicken",
  24. },
  25. walk_velocity = 1,
  26. run_velocity = 3,
  27. runaway = true,
  28. runaway_from = {"player", "mobs_animal:pumba"},
  29. drops = {
  30. {name = "mobs:chicken_raw", chance = 1, min = 1, max = 1},
  31. {name = "mobs:chicken_feather", chance = 1, min = 0, max = 2},
  32. },
  33. water_damage = 1,
  34. lava_damage = 5,
  35. light_damage = 0,
  36. fall_damage = 0,
  37. fall_speed = -8,
  38. fear_height = 5,
  39. animation = {
  40. speed_normal = 15,
  41. stand_start = 1,
  42. stand_end = 30,
  43. stand_speed = 28,
  44. stand1_start = 31,
  45. stand1_end = 70,
  46. stand1_speed = 32,
  47. walk_start = 71,
  48. walk_end = 90,
  49. walk_speed = 24,
  50. run_start = 91,
  51. run_end = 110,
  52. run_speed = 24,
  53. },
  54. follow = {"farming:seed_wheat", "farming:seed_cotton"},
  55. view_range = 5,
  56. on_rightclick = function(self, clicker)
  57. if mobs:feed_tame(self, clicker, 8, true, true) then return end
  58. if mobs:protect(self, clicker) then return end
  59. if mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) then return end
  60. end,
  61. do_custom = function(self, dtime)
  62. self.egg_timer = (self.egg_timer or 0) + dtime
  63. if self.egg_timer < 10 then
  64. return
  65. end
  66. self.egg_timer = 0
  67. if self.child
  68. or math.random(1, 100) > 1 then
  69. return
  70. end
  71. local pos = self.object:get_pos()
  72. minetest.add_item(pos, "mobs:egg")
  73. minetest.sound_play("default_place_node_hard", {
  74. pos = pos,
  75. gain = 1.0,
  76. max_hear_distance = 5,
  77. })
  78. end,
  79. })
  80. local spawn_on = {"default:dirt_with_grass"}
  81. if minetest.get_modpath("ethereal") then
  82. spawn_on = {"ethereal:bamboo_dirt", "ethereal:prairie_dirt"}
  83. end
  84. mobs:spawn({
  85. name = "mobs_animal:chicken",
  86. nodes = spawn_on,
  87. neighbors = {"group:grass"},
  88. min_light = 14,
  89. interval = 60,
  90. chance = 8000, -- 15000
  91. min_height = 5,
  92. max_height = 200,
  93. day_toggle = true,
  94. })
  95. mobs:register_egg("mobs_animal:chicken", S("Chicken"), "mobs_chicken_inv.png", 0)
  96. mobs:alias_mob("mobs:chicken", "mobs_animal:chicken") -- compatibility
  97. -- egg entity
  98. mobs:register_arrow("mobs_animal:egg_entity", {
  99. visual = "sprite",
  100. visual_size = {x=.5, y=.5},
  101. textures = {"mobs_chicken_egg.png"},
  102. velocity = 6,
  103. hit_player = 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_mob = function(self, player)
  110. player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, {
  111. full_punch_interval = 1.0,
  112. damage_groups = {fleshy = 1},
  113. }, nil)
  114. end,
  115. hit_node = function(self, pos, node)
  116. if math.random(1, 10) > 1 then
  117. return
  118. end
  119. pos.y = pos.y + 1
  120. local nod = minetest.get_node_or_nil(pos)
  121. if not nod
  122. or not minetest.registered_nodes[nod.name]
  123. or minetest.registered_nodes[nod.name].walkable == true then
  124. return
  125. end
  126. local mob = minetest.add_entity(pos, "mobs_animal:chicken")
  127. local ent2 = mob:get_luaentity()
  128. mob:set_properties({
  129. textures = ent2.child_texture[1],
  130. visual_size = {
  131. x = ent2.base_size.x / 2,
  132. y = ent2.base_size.y / 2
  133. },
  134. collisionbox = {
  135. ent2.base_colbox[1] / 2,
  136. ent2.base_colbox[2] / 2,
  137. ent2.base_colbox[3] / 2,
  138. ent2.base_colbox[4] / 2,
  139. ent2.base_colbox[5] / 2,
  140. ent2.base_colbox[6] / 2
  141. },
  142. })
  143. ent2.child = true
  144. ent2.tamed = true
  145. ent2.owner = self.playername
  146. end
  147. })
  148. -- egg throwing item
  149. local egg_GRAVITY = 9
  150. local egg_VELOCITY = 19
  151. -- shoot egg
  152. local mobs_shoot_egg = function (item, player, pointed_thing)
  153. local playerpos = player:get_pos()
  154. minetest.sound_play("default_place_node_hard", {
  155. pos = playerpos,
  156. gain = 1.0,
  157. max_hear_distance = 5,
  158. })
  159. local obj = minetest.add_entity({
  160. x = playerpos.x,
  161. y = playerpos.y +1.5,
  162. z = playerpos.z
  163. }, "mobs_animal:egg_entity")
  164. local ent = obj:get_luaentity()
  165. local dir = player:get_look_dir()
  166. ent.velocity = egg_VELOCITY -- needed for api internal timing
  167. ent.switch = 1 -- needed so that egg doesn't despawn straight away
  168. obj:setvelocity({
  169. x = dir.x * egg_VELOCITY,
  170. y = dir.y * egg_VELOCITY,
  171. z = dir.z * egg_VELOCITY
  172. })
  173. obj:setacceleration({
  174. x = dir.x * -3,
  175. y = -egg_GRAVITY,
  176. z = dir.z * -3
  177. })
  178. -- pass player name to egg for chick ownership
  179. local ent2 = obj:get_luaentity()
  180. ent2.playername = player:get_player_name()
  181. item:take_item()
  182. return item
  183. end
  184. -- egg
  185. minetest.register_node(":mobs:egg", {
  186. description = S("Chicken Egg"),
  187. tiles = {"mobs_chicken_egg.png"},
  188. inventory_image = "mobs_chicken_egg.png",
  189. visual_scale = 0.7,
  190. drawtype = "plantlike",
  191. wield_image = "mobs_chicken_egg.png",
  192. paramtype = "light",
  193. walkable = false,
  194. is_ground_content = true,
  195. sunlight_propagates = true,
  196. selection_box = {
  197. type = "fixed",
  198. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  199. },
  200. groups = {food_egg = 1, snappy = 2, dig_immediate = 3},
  201. after_place_node = function(pos, placer, itemstack)
  202. if placer:is_player() then
  203. minetest.set_node(pos, {name = "mobs:egg", param2 = 1})
  204. end
  205. end,
  206. on_use = mobs_shoot_egg
  207. })
  208. -- fried egg
  209. minetest.register_craftitem(":mobs:chicken_egg_fried", {
  210. description = S("Fried Egg"),
  211. inventory_image = "mobs_chicken_egg_fried.png",
  212. on_use = minetest.item_eat(2),
  213. groups = {food_egg_fried = 1, flammable = 2},
  214. })
  215. minetest.register_craft({
  216. type = "cooking",
  217. recipe = "mobs:egg",
  218. output = "mobs:chicken_egg_fried",
  219. })
  220. -- raw chicken
  221. minetest.register_craftitem(":mobs:chicken_raw", {
  222. description = S("Raw Chicken"),
  223. inventory_image = "mobs_chicken_raw.png",
  224. on_use = minetest.item_eat(2),
  225. groups = {food_meat_raw = 1, food_chicken_raw = 1, flammable = 2},
  226. })
  227. -- cooked chicken
  228. minetest.register_craftitem(":mobs:chicken_cooked", {
  229. description = S("Cooked Chicken"),
  230. inventory_image = "mobs_chicken_cooked.png",
  231. on_use = minetest.item_eat(6),
  232. groups = {food_meat = 1, food_chicken = 1, flammable = 2},
  233. })
  234. minetest.register_craft({
  235. type = "cooking",
  236. recipe = "mobs:chicken_raw",
  237. output = "mobs:chicken_cooked",
  238. })
  239. -- feather
  240. minetest.register_craftitem(":mobs:chicken_feather", {
  241. description = S("Feather"),
  242. inventory_image = "mobs_chicken_feather.png",
  243. groups = {flammable = 2},
  244. })
  245. minetest.register_craft({
  246. type = "fuel",
  247. recipe = "mobs:chicken_feather",
  248. burntime = 1,
  249. })