init.lua 6.0 KB

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