kitten.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. local S = mobs.intllib_animal
  2. local hairball = minetest.settings:get("mobs_hairball")
  3. local kitten_types = {
  4. { nodes = {"farming:jackolantern_on"},
  5. skins = {"mobs_kitten_black.png"}
  6. }
  7. }
  8. -- Kitten by Jordach / BFD
  9. mobs:register_mob("mobs_animal:kitten", {
  10. stepheight = 0.6,
  11. type = "animal",
  12. specific_attack = {"mobs_animal:rat"},
  13. damage = 1,
  14. attack_type = "dogfight",
  15. attack_animals = true, -- so it can attack rat
  16. attack_players = false,
  17. reach = 1,
  18. stepheight = 1.1,
  19. passive = false,
  20. hp_min = 5,
  21. hp_max = 10,
  22. armor = 200,
  23. collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.1, 0.3},
  24. visual = "mesh",
  25. visual_size = {x = 0.5, y = 0.5},
  26. mesh = "mobs_kitten.b3d",
  27. textures = {
  28. {"mobs_kitten_striped.png"},
  29. {"mobs_kitten_splotchy.png"},
  30. {"mobs_kitten_ginger.png"},
  31. {"mobs_kitten_sandy.png"}
  32. },
  33. makes_footstep_sound = false,
  34. sounds = {
  35. random = "mobs_kitten"
  36. },
  37. walk_velocity = 0.6,
  38. walk_chance = 15,
  39. run_velocity = 2,
  40. runaway = true,
  41. jump = false,
  42. drops = {
  43. {name = "farming:string", chance = 1, min = 0, max = 1}
  44. },
  45. water_damage = 0.01,
  46. lava_damage = 5,
  47. fear_height = 3,
  48. animation = {
  49. speed_normal = 42,
  50. stand_start = 97,
  51. stand_end = 192,
  52. walk_start = 0,
  53. walk_end = 96,
  54. stoodup_start = 0,
  55. stoodup_end = 0,
  56. },
  57. follow = {
  58. "mobs_animal:rat", "group:food_fish_raw",
  59. "mobs_fish:tropical", "mobs_fish:clownfish", "xocean:fish_edible"
  60. },
  61. view_range = 8,
  62. -- check surrounding nodes and spawn a specific kitten
  63. on_spawn = function(self)
  64. local pos = self.object:get_pos() ; pos.y = pos.y - 1
  65. local tmp
  66. for n = 1, #kitten_types do
  67. tmp = kitten_types[n]
  68. if minetest.find_node_near(pos, 1, tmp.nodes) then
  69. self.base_texture = tmp.skins
  70. self.object:set_properties({textures = tmp.skins})
  71. return true
  72. end
  73. end
  74. return true -- run only once, false/nil runs every activation
  75. end,
  76. on_rightclick = function(self, clicker)
  77. if mobs:feed_tame(self, clicker, 4, true, true) then return end
  78. if mobs:protect(self, clicker) then return end
  79. if mobs:capture_mob(self, clicker, 50, 50, 90, false, nil) then return end
  80. -- by right-clicking owner can switch between staying and walking
  81. if self.owner and self.owner == clicker:get_player_name() then
  82. if self.order ~= "stand" then
  83. self.order = "stand"
  84. self.state = "stand"
  85. self.object:set_velocity({x = 0, y = 0, z = 0})
  86. mobs:set_animation(self, "stand")
  87. else
  88. self.order = ""
  89. mobs:set_animation(self, "stoodup")
  90. end
  91. end
  92. end,
  93. do_custom = function(self, dtime)
  94. if hairball == "false" then
  95. return
  96. end
  97. self.hairball_timer = (self.hairball_timer or 0) + dtime
  98. if self.hairball_timer < 10 then
  99. return
  100. end
  101. self.hairball_timer = 0
  102. if self.child or math.random(250) > 1 then
  103. return
  104. end
  105. local pos = self.object:get_pos()
  106. minetest.add_item(pos, "mobs:hairball")
  107. minetest.sound_play("default_dig_snappy", {
  108. pos = pos, gain = 1.0, max_hear_distance = 5}, true)
  109. end
  110. })
  111. local spawn_on = "default:dirt_with_grass"
  112. if minetest.get_modpath("ethereal") then
  113. spawn_on = "ethereal:grove_dirt"
  114. end
  115. if not mobs.custom_spawn_animal then
  116. mobs:spawn({
  117. name = "mobs_animal:kitten",
  118. nodes = {spawn_on},
  119. neighbors = {"group:grass"},
  120. min_light = 14,
  121. interval = 60,
  122. chance = 10000,
  123. min_height = 5,
  124. max_height = 50,
  125. day_toggle = true
  126. })
  127. end
  128. mobs:register_egg("mobs_animal:kitten", S("Kitten"), "mobs_kitten_inv.png", 0)
  129. mobs:alias_mob("mobs:kitten", "mobs_animal:kitten") -- compatibility
  130. local hairball_items = {
  131. "default:stick", "default:coal_lump", "default:dry_shrub", "flowers:rose",
  132. "mobs_animal:rat", "default:grass_1", "farming:seed_wheat", "dye:green", "",
  133. "farming:seed_cotton", "default:flint", "default:sapling", "dye:white", "",
  134. "default:clay_lump", "default:paper", "default:dry_grass_1", "dye:red", "",
  135. "farming:string", "mobs:chicken_feather", "default:acacia_bush_sapling", "",
  136. "default:bush_sapling", "default:copper_lump", "default:iron_lump", "",
  137. "dye:black", "dye:brown", "default:obsidian_shard", "default:tin_lump",
  138. "ethereal:fish_tetra"
  139. }
  140. minetest.register_craftitem(":mobs:hairball", {
  141. description = S("Hairball"),
  142. inventory_image = "mobs_hairball.png",
  143. on_use = function(itemstack, user, pointed_thing)
  144. local pos = user:get_pos()
  145. local dir = user:get_look_dir()
  146. local newpos = {x = pos.x + dir.x, y = pos.y + dir.y + 1.5, z = pos.z + dir.z}
  147. local item = hairball_items[math.random(1, #hairball_items)]
  148. if item ~= ""
  149. and minetest.registered_items[item] then
  150. minetest.add_item(newpos, {name = item})
  151. end
  152. minetest.sound_play("default_place_node_hard", {
  153. pos = newpos, gain = 1.0, max_hear_distance = 5}, true)
  154. itemstack:take_item()
  155. return itemstack
  156. end
  157. })