spider.lua 5.7 KB

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