kitten.lua 3.9 KB

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