kitten.lua 4.0 KB

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