init.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. tmw_slimes = {}
  2. tmw_slimes.path = minetest.get_modpath("tmw_slimes").."/slimes/"
  3. tmw_slimes.colors = {}
  4. minetest.register_craftitem("tmw_slimes:live_nucleus", {
  5. description = "Living Nucleus",
  6. inventory_image = "tmw_slime_nucleus.png"
  7. })
  8. tmw_slimes.add_slime = function(string, aquatic)
  9. local proper_name = string.upper(string.sub(string,1,1))..string.sub(string,2,-1)
  10. minetest.register_craftitem("tmw_slimes:"..string.."_goo", {
  11. inventory_image = "tmw_slime_goo.png^[colorize:"..tmw_slimes.colors[string],
  12. description = proper_name.." Goo",
  13. groups = {slime = 1},
  14. })
  15. minetest.register_node("tmw_slimes:"..string.."_goo_block", {
  16. tiles = {"tmw_slime_goo_block.png^[colorize:"..tmw_slimes.colors[string].."^[colorize:#0000:25"},
  17. description = proper_name.." Goo Block",
  18. drawtype = "allfaces_optional",
  19. use_texture_alpha = true,
  20. groups = {slippery = 2, crumbly=3, oddly_breakable_by_hand = 1},
  21. sounds = default.node_sound_snow_defaults(),
  22. })
  23. local goo = "tmw_slimes:"..string.."_goo"
  24. minetest.register_craft({
  25. output = "tmw_slimes:"..string.."_goo_block",
  26. recipe = {
  27. {goo,goo,goo},
  28. {goo,goo,goo},
  29. {goo,goo,goo}
  30. }
  31. })
  32. dofile(tmw_slimes.path..string..".lua")
  33. mobs:register_egg("tmw_slimes:"..string.."_slime", proper_name.." Slime", "tmw_slime_".."inventory.png^[colorize:"..tmw_slimes.colors[string]..
  34. (aquatic and "^(tmw_slime_aquatic_inventory.png^[colorize:"..tmw_slimes.colors[string].."^[colorize:#FFF:96)" or ""),
  35. 0)
  36. minetest.register_craft({
  37. output = "tmw_slimes:"..string.."_slime",
  38. recipe = {
  39. {goo,goo,goo},
  40. {goo,"tmw_slimes:live_nucleus",goo},
  41. {goo,goo,goo}
  42. }
  43. })
  44. end
  45. tmw_slimes.weak_dmg = 1
  46. tmw_slimes.medium_dmg = 5
  47. tmw_slimes.strong_dmg = 10
  48. tmw_slimes.deadly_dmg = 50
  49. tmw_slimes.pervasive = 5000
  50. tmw_slimes.common = 10000
  51. tmw_slimes.uncommon = 15000
  52. tmw_slimes.rare = 25000
  53. tmw_slimes.pervasive_max = 8
  54. tmw_slimes.common_max = 6
  55. tmw_slimes.uncommon_max = 4
  56. tmw_slimes.rare_max = 2
  57. tmw_slimes.absorb_nearby_items = function(ent)
  58. local pos = ent.object:get_pos()
  59. for _,obj in pairs(minetest.get_objects_inside_radius(pos, 1.25)) do
  60. local oent = obj:get_luaentity()
  61. if oent and oent.name == "__builtin:item" then
  62. if not ent.stomach then ent.stomach = {} end
  63. if #ent.stomach >= 24 then break end
  64. table.insert(ent.stomach, oent.itemstring)
  65. obj:remove()
  66. minetest.sound_play("item_slurp", {pos = pos, max_hear_distance = 10, gain = 0.7})
  67. ent.lifetimer = (ent.lifetimer and ent.lifetimer > 20000) and ent.lifetimer + 7200 or 27200
  68. -- Keep this slime around even after unload for at least another 2 hours per item picked up,
  69. -- so slimes don't just grab killed players' items and despawn.
  70. break --Pick up only one item per step
  71. end
  72. end
  73. end
  74. tmw_slimes.drop_items = function(self, pos)
  75. if self.stomach then
  76. for _,item in ipairs(self.stomach) do
  77. minetest.add_item({x=pos.x + math.random()/2,y=pos.y+0.5,z=pos.z+math.random()/2}, item)
  78. end
  79. end
  80. end
  81. tmw_slimes.animate = function(ent)
  82. if not (ent and minetest.registered_entities[ent.name] and ent.object) then return end
  83. local pos = ent.object:get_pos()
  84. local velocity = ent.object:get_velocity()
  85. local is_liquid_below = ((minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-0.5,z=pos.z}).name] or {liquidtype = "none"}).liquidtype == "none")
  86. local land_movement = (minetest.registered_entities[ent.name].mesh == "slime_land.b3d") or not is_liquid_below
  87. if velocity.y ~= 0 then
  88. if not land_movement and (math.abs(velocity.x) > math.abs(velocity.y) or math.abs(velocity.z) > math.abs(velocity.y)) then
  89. mobs.set_animation(ent, "move")
  90. return
  91. end
  92. if velocity.y > 0 then
  93. mobs:set_animation(ent, "jump")
  94. return
  95. else
  96. mobs:set_animation(ent, "fall")
  97. return
  98. end
  99. end
  100. if velocity.x ~= 0 or velocity.z ~= 0 then
  101. mobs:set_animation(ent, "move")
  102. return
  103. end
  104. mobs:set_animation(ent, "idle")
  105. end
  106. --Land model
  107. tmw_slimes.colors["poisonous"] = "#205:200"
  108. tmw_slimes.add_slime("poisonous")
  109. tmw_slimes.colors["jungle"] = "#0A1:180"
  110. tmw_slimes.add_slime("jungle")
  111. tmw_slimes.colors["savannah"] = "#204004:200"
  112. tmw_slimes.add_slime("savannah")
  113. tmw_slimes.colors["icy"] = "#8BF:160"
  114. tmw_slimes.add_slime("icy")
  115. --Land model (underground)
  116. tmw_slimes.colors["mineral"] = "#584000:225"
  117. tmw_slimes.add_slime("mineral")
  118. tmw_slimes.colors["dark"] = "#000:220"
  119. tmw_slimes.add_slime("dark")
  120. if minetest.get_modpath("other_worlds") then
  121. tmw_slimes.colors["alien"] = "#800:220"
  122. tmw_slimes.add_slime("alien", true)
  123. end
  124. --Liquid model
  125. tmw_slimes.colors["cloud"] = "#EEF:180"
  126. tmw_slimes.add_slime("cloud", true)
  127. tmw_slimes.colors["algae"] = "#0C9:180"
  128. tmw_slimes.add_slime("algae", true)
  129. tmw_slimes.colors["ocean"] = "#00C:200"
  130. tmw_slimes.add_slime("ocean", true)
  131. tmw_slimes.colors["lava"] = "#F80:190"
  132. tmw_slimes.add_slime("lava", true)
  133. minetest.register_craft({
  134. output = "tmw_slimes:live_nucleus",
  135. recipe = {"tmw_slimes:lava_goo","tmw_slimes:ocean_goo","tmw_slimes:mineral_goo"},
  136. type="shapeless"
  137. })
  138. tmw_slimes.colors["uber"] = "#FD0:200"
  139. dofile(tmw_slimes.path.."uber.lua")
  140. minetest.register_abm({
  141. nodenames = {"group:harmful_slime"},
  142. interval = 2,
  143. chance = 1,
  144. action = function(pos, node)
  145. local dmg = minetest.registered_nodes[node.name].groups.harmful_slime
  146. for _,ent in pairs(minetest.get_objects_inside_radius(pos, 1.75)) do
  147. if ent:is_player() then
  148. ent:punch(ent, nil, {damage_groups={fleshy=dmg}}, nil)
  149. else
  150. local luaent = ent:get_luaentity()
  151. if luaent and
  152. luaent._cmi_is_mob and
  153. not string.find(node.name, string.sub(luaent.name, 11, -7).."_goo")
  154. then
  155. ent:punch(ent, nil, {damage_groups={fleshy=dmg}}, nil)
  156. end
  157. end
  158. end
  159. end
  160. })