You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
5.5KB

  1. local S = mobs.intllib
  2. local get_velocity = function(self)
  3. local v = self.object:get_velocity()
  4. return (v.x * v.x + v.z * v.z) ^ 0.5
  5. end
  6. -- Spider by AspireMint (CC-BY-SA 3.0 license)
  7. mobs:register_mob("mobs_monster:spider", {
  8. --docile_by_day = true,
  9. group_attack = true,
  10. type = "monster",
  11. passive = false,
  12. attack_type = "dogfight",
  13. reach = 2,
  14. damage = 3,
  15. hp_min = 10,
  16. hp_max = 30,
  17. armor = 200,
  18. collisionbox = {-0.8, -0.5, -0.8, 0.8, 0, 0.8},
  19. visual_size = {x = 1, y = 1},
  20. visual = "mesh",
  21. mesh = "mobs_spider.b3d",
  22. textures = {
  23. {"mobs_spider_mese.png"},
  24. {"mobs_spider_orange.png"},
  25. {"mobs_spider_snowy.png"},
  26. {"mobs_spider_grey.png"},
  27. {"mobs_spider_crystal.png"},
  28. },
  29. makes_footstep_sound = false,
  30. sounds = {
  31. random = "mobs_spider",
  32. attack = "mobs_spider",
  33. },
  34. walk_velocity = 1,
  35. run_velocity = 3,
  36. jump = true,
  37. view_range = 15,
  38. floats = 0,
  39. drops = {
  40. {name = "farming:string", chance = 1, min = 0, max = 2},
  41. },
  42. water_damage = 5,
  43. lava_damage = 5,
  44. light_damage = 0,
  45. animation = {
  46. speed_normal = 15,
  47. speed_run = 20,--15,
  48. stand_start = 0,
  49. stand_end = 0,
  50. walk_start = 1,
  51. walk_end = 21,
  52. run_start = 1,
  53. run_end = 21,
  54. punch_start = 25,
  55. punch_end = 45,
  56. },
  57. -- what kind of spider are we spawning?
  58. on_spawn = function(self)
  59. local pos = self.object:get_pos() ; pos.y = pos.y - 1
  60. -- snowy spider
  61. if minetest.find_node_near(pos, 1,
  62. {"default:snow", "default:snowblock", "default:dirt_with_snow"}) then
  63. self.base_texture = {"mobs_spider_snowy.png"}
  64. self.object:set_properties({textures = self.base_texture})
  65. self.docile_by_day = true
  66. -- tarantula
  67. elseif minetest.find_node_near(pos, 1,
  68. {"default:dirt_with_rainforest_litter", "default:jungletree"}) then
  69. self.base_texture = {"mobs_spider_orange.png"}
  70. self.object:set_properties({textures = self.base_texture})
  71. self.docile_by_day = true
  72. -- grey spider
  73. elseif minetest.find_node_near(pos, 1,
  74. {"default:stone", "default:gravel"}) then
  75. self.base_texture = {"mobs_spider_grey.png"}
  76. self.object:set_properties({textures = self.base_texture})
  77. -- mese spider
  78. elseif minetest.find_node_near(pos, 1,
  79. {"default:mese", "default:stone_with_mese"}) then
  80. self.base_texture = {"mobs_spider_mese.png"}
  81. self.object:set_properties({textures = self.base_texture})
  82. elseif minetest.find_node_near(pos, 1,
  83. {"ethereal:crystal_dirt", "ethereal:crystal_spike"}) then
  84. self.base_texture = {"mobs_spider_crystal.png"}
  85. self.object:set_properties({textures = self.base_texture})
  86. self.docile_by_day = true
  87. self.drops = {
  88. {name = "farming:string", chance = 1, min = 0, max = 2},
  89. {name = "ethereal:crystal_spike", chance = 15, min = 1, max = 2},
  90. }
  91. end
  92. return true -- run only once, false/nil runs every activation
  93. end,
  94. -- custom function to make spiders climb vertical facings
  95. do_custom = function(self, dtime)
  96. -- quarter second timer
  97. self.spider_timer = (self.spider_timer or 0) + dtime
  98. if self.spider_timer < 0.25 then
  99. return
  100. end
  101. self.spider_timer = 0
  102. -- need to be stopped to go onwards
  103. if get_velocity(self) > 0.2 then
  104. self.disable_falling = false
  105. return
  106. end
  107. local pos = self.object:get_pos()
  108. local yaw = self.object:get_yaw()
  109. pos.y = pos.y + self.collisionbox[2] - 0.2
  110. local dir_x = -math.sin(yaw) * (self.collisionbox[4] + 0.5)
  111. local dir_z = math.cos(yaw) * (self.collisionbox[4] + 0.5)
  112. local nod = minetest.get_node_or_nil({
  113. x = pos.x + dir_x,
  114. y = pos.y + 0.5,
  115. z = pos.z + dir_z
  116. })
  117. -- get current velocity
  118. local v = self.object:get_velocity()
  119. -- can only climb solid facings
  120. if not nod or not minetest.registered_nodes[nod.name]
  121. or not minetest.registered_nodes[nod.name].walkable then
  122. self.disable_falling = nil
  123. v.y = 0
  124. self.object:set_velocity(v)
  125. return
  126. end
  127. --print ("----", nod.name, self.disable_falling, dtime)
  128. -- turn off falling if attached to facing
  129. self.disable_falling = true
  130. -- move up facing
  131. v.y = self.jump_height
  132. mobs:set_animation(self, "jump")
  133. self.object:set_velocity(v)
  134. end
  135. })
  136. -- above ground spawn
  137. mobs:spawn({
  138. name = "mobs_monster:spider",
  139. nodes = {
  140. "default:dirt_with_rainforest_litter", "default:snowblock",
  141. "default:snow", "ethereal:crystal_dirt"
  142. },
  143. min_light = 0,
  144. max_light = 8,
  145. chance = 7000,
  146. active_object_count = 1,
  147. min_height = 25,
  148. max_height = 31000,
  149. })
  150. -- below ground spawn
  151. mobs:spawn({
  152. name = "mobs_monster:spider",
  153. nodes = {"default:stone_with_mese", "default:mese", "default:stone"},
  154. min_light = 0,
  155. max_light = 7,
  156. chance = 7000,
  157. active_object_count = 1,
  158. min_height = -31000,
  159. max_height = -40,
  160. })
  161. mobs:register_egg("mobs_monster:spider", S("Spider"), "mobs_cobweb.png", 1)
  162. mobs:alias_mob("mobs_monster:spider2", "mobs_monster:spider") -- compatibility
  163. mobs:alias_mob("mobs:spider", "mobs_monster:spider")
  164. -- cobweb
  165. minetest.register_node(":mobs:cobweb", {
  166. description = S("Cobweb"),
  167. drawtype = "plantlike",
  168. visual_scale = 1.2,
  169. tiles = {"mobs_cobweb.png"},
  170. inventory_image = "mobs_cobweb.png",
  171. paramtype = "light",
  172. sunlight_propagates = true,
  173. liquid_viscosity = 11,
  174. liquidtype = "source",
  175. liquid_alternative_flowing = "mobs:cobweb",
  176. liquid_alternative_source = "mobs:cobweb",
  177. liquid_renewable = false,
  178. liquid_range = 0,
  179. walkable = false,
  180. groups = {snappy = 1, disable_jump = 1},
  181. drop = "farming:string",
  182. sounds = default.node_sound_leaves_defaults(),
  183. })
  184. minetest.register_craft({
  185. output = "mobs:cobweb",
  186. recipe = {
  187. {"farming:string", "", "farming:string"},
  188. {"", "farming:string", ""},
  189. {"farming:string", "", "farming:string"},
  190. }
  191. })