chicken.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. local S = mobs.intllib
  2. -- Chicken by JK Murray
  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.x",
  13. -- seems a lot of textures but this fixes the problem with the model
  14. textures = {
  15. {"mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png",
  16. "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png"},
  17. {"mobs_chicken_black.png", "mobs_chicken_black.png", "mobs_chicken_black.png", "mobs_chicken_black.png",
  18. "mobs_chicken_black.png", "mobs_chicken_black.png", "mobs_chicken_black.png", "mobs_chicken_black.png", "mobs_chicken_black.png"},
  19. },
  20. child_texture = {
  21. {"mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png",
  22. "mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png", "mobs_chick.png"},
  23. },
  24. makes_footstep_sound = true,
  25. sounds = {
  26. random = "mobs_chicken",
  27. },
  28. walk_velocity = 1,
  29. run_velocity = 3,
  30. runaway = true,
  31. runaway_from = {"player", "mobs_animal:pumba"},
  32. drops = {
  33. {name = "mobs:chicken_raw", chance = 1, min = 1, max = 1},
  34. {name = "mobs:chicken_feather", chance = 1, min = 1, max = 2},
  35. },
  36. water_damage = 1,
  37. lava_damage = 5,
  38. light_damage = 0,
  39. fall_damage = 0,
  40. fall_speed = -8,
  41. fear_height = 5,
  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. follow = {"farming:seed_wheat", "farming:seed_cotton"},
  50. view_range = 5,
  51. on_rightclick = function(self, clicker)
  52. if mobs:feed_tame(self, clicker, 8, true, true) then return end
  53. if mobs:protect(self, clicker) then return end
  54. if mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) then return end
  55. end,
  56. do_custom = function(self, dtime)
  57. self.egg_timer = (self.egg_timer or 0) + dtime
  58. if self.egg_timer < 10 then
  59. return
  60. end
  61. self.egg_timer = 0
  62. if self.child
  63. or math.random(1, 100) > 1 then
  64. return
  65. end
  66. local pos = self.object:get_pos()
  67. minetest.add_item(pos, "mobs:egg")
  68. minetest.sound_play("default_place_node_hard", {
  69. pos = pos,
  70. gain = 1.0,
  71. max_hear_distance = 5,
  72. })
  73. end,
  74. })
  75. local spawn_on = "default:dirt_with_grass"
  76. if minetest.get_modpath("ethereal") then
  77. spawn_on = "ethereal:bamboo_dirt"
  78. end
  79. mobs:spawn({
  80. name = "mobs_animal:chicken",
  81. nodes = {spawn_on},
  82. neighbors = {"group:grass"},
  83. min_light = 14,
  84. interval = 60,
  85. chance = 8000, -- 15000
  86. min_height = 5,
  87. max_height = 200,
  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:get_pos()
  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 = {food_egg = 1, 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. groups = {food_egg_fried = 1, flammable = 2},
  209. })
  210. minetest.register_craft({
  211. type = "cooking",
  212. recipe = "mobs:egg",
  213. output = "mobs:chicken_egg_fried",
  214. })
  215. -- raw chicken
  216. minetest.register_craftitem(":mobs:chicken_raw", {
  217. description = S("Raw Chicken"),
  218. inventory_image = "mobs_chicken_raw.png",
  219. on_use = minetest.item_eat(2),
  220. groups = {food_meat_raw = 1, food_chicken_raw = 1, flammable = 2},
  221. })
  222. -- cooked chicken
  223. minetest.register_craftitem(":mobs:chicken_cooked", {
  224. description = S("Cooked Chicken"),
  225. inventory_image = "mobs_chicken_cooked.png",
  226. on_use = minetest.item_eat(6),
  227. groups = {food_meat = 1, food_chicken = 1, flammable = 2},
  228. })
  229. minetest.register_craft({
  230. type = "cooking",
  231. recipe = "mobs:chicken_raw",
  232. output = "mobs:chicken_cooked",
  233. })
  234. -- feather
  235. minetest.register_craftitem(":mobs:chicken_feather", {
  236. description = S("Feather"),
  237. inventory_image = "mobs_chicken_feather.png",
  238. groups = {flammable = 2},
  239. })
  240. minetest.register_craft({
  241. type = "fuel",
  242. recipe = "mobs:chicken_feather",
  243. burntime = 1,
  244. })