kitten.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 = {"mobs_animal:rat", "fishing:tuna", "fishing:salmon", "fishing:clownfish", "mobs_fish:clownfish", "mobs_fish:tropical"},
  53. view_range = 8,
  54. on_rightclick = function(self, clicker)
  55. if mobs:feed_tame(self, clicker, 4, true, true) then return end
  56. if mobs:protect(self, clicker) then return end
  57. if mobs:capture_mob(self, clicker, 50, 50, 90, false, nil) then return end
  58. -- by right-clicking owner can switch between staying and walking
  59. if self.owner and self.owner == clicker:get_player_name() then
  60. if self.order ~= "stand" then
  61. self.order = "stand"
  62. self.state = "stand"
  63. self.object:set_velocity({x = 0, y = 0, z = 0})
  64. mobs:set_animation(self, "stand")
  65. else
  66. self.order = ""
  67. mobs:set_animation(self, "stoodup")
  68. end
  69. end
  70. end,
  71. do_custom = function(self, dtime)
  72. if hairball == "false" then
  73. return
  74. end
  75. self.hairball_timer = (self.hairball_timer or 0) + dtime
  76. if self.hairball_timer < 10 then
  77. return
  78. end
  79. self.hairball_timer = 0
  80. if self.child
  81. or math.random(1, 250) > 1 then
  82. return
  83. end
  84. local pos = self.object:get_pos()
  85. minetest.add_item(pos, "mobs:hairball")
  86. minetest.sound_play("default_dig_snappy", {
  87. pos = pos,
  88. gain = 1.0,
  89. max_hear_distance = 5,
  90. })
  91. end,
  92. })
  93. local spawn_on = "default:dirt_with_grass"
  94. if minetest.get_modpath("ethereal") then
  95. spawn_on = "ethereal:grove_dirt"
  96. end
  97. mobs:spawn({
  98. name = "mobs_animal:kitten",
  99. nodes = {spawn_on},
  100. neighbors = {"group:grass"},
  101. min_light = 14,
  102. interval = 60,
  103. chance = 10000, -- 22000
  104. min_height = 5,
  105. max_height = 50,
  106. day_toggle = true,
  107. })
  108. mobs:register_egg("mobs_animal:kitten", S("Kitten"), "mobs_kitten_inv.png", 0)
  109. mobs:alias_mob("mobs:kitten", "mobs_animal:kitten") -- compatibility
  110. local hairball_items = {
  111. "default:stick", "default:coal_lump", "default:dry_shrub", "flowers:rose",
  112. "mobs_animal:rat", "default:grass_1", "farming:seed_wheat", "dye:green", "",
  113. "farming:seed_cotton", "default:flint", "default:sapling", "dye:white", "",
  114. "default:clay_lump", "default:paper", "default:dry_grass_1", "dye:red", "",
  115. "farming:string", "mobs:chicken_feather", "default:acacia_bush_sapling", "",
  116. "default:bush_sapling", "default:copper_lump", "default:iron_lump", "",
  117. "dye:black", "dye:brown", "default:obsidian_shard", "default:tin_lump"
  118. }
  119. minetest.register_craftitem(":mobs:hairball", {
  120. description = S("Hairball"),
  121. inventory_image = "mobs_hairball.png",
  122. on_use = function(itemstack, user, pointed_thing)
  123. local pos = user:get_pos()
  124. local dir = user:get_look_dir()
  125. local newpos = {x = pos.x + dir.x, y = pos.y + dir.y + 1.5, z = pos.z + dir.z}
  126. local item = hairball_items[math.random(1, #hairball_items)]
  127. if item ~= "" then
  128. minetest.add_item(newpos, {name = item})
  129. end
  130. minetest.sound_play("default_place_node_hard", {
  131. pos = newpos,
  132. gain = 1.0,
  133. max_hear_distance = 5,
  134. })
  135. itemstack:take_item()
  136. return itemstack
  137. end,
  138. })