kitten.lua 4.0 KB

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