init.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. -- intllib
  2. local MP = minetest.get_modpath(minetest.get_current_modname())
  3. local S, NS = dofile(MP .. "/intllib.lua")
  4. -- 0.4.17 or 5.0 check
  5. local y_off = 20
  6. if minetest.registered_nodes["default:permafrost"] then
  7. y_off = 10
  8. end
  9. -- horse shoes (speed, jump, break, overlay texture)
  10. local shoes = {
  11. ["mobs:horseshoe_steel"] = {7, 4, 2, "mobs_horseshoe_steelo.png"},
  12. ["mobs:horseshoe_bronze"] = {7, 4, 4, "mobs_horseshoe_bronzeo.png"},
  13. ["mobs:horseshoe_mese"] = {9, 5, 8, "mobs_horseshoe_meseo.png"},
  14. ["mobs:horseshoe_diamond"] = {10, 6, 6, "mobs_horseshoe_diamondo.png"}
  15. }
  16. -- rideable horse
  17. mobs:register_mob("mob_horse:horse", {
  18. type = "animal",
  19. visual = "mesh",
  20. visual_size = {x = 1.20, y = 1.20},
  21. mesh = "mobs_horse.x",
  22. collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
  23. animation = {
  24. speed_normal = 15,
  25. speed_run = 30,
  26. stand_start = 25,
  27. stand_end = 75,
  28. walk_start = 75,
  29. walk_end = 100,
  30. run_start = 75,
  31. run_end = 100,
  32. },
  33. textures = {
  34. {"mobs_horse.png"}, -- textures by Mjollna
  35. {"mobs_horsepeg.png"},
  36. {"mobs_horseara.png"}
  37. },
  38. fear_height = 3,
  39. runaway = true,
  40. fly = false,
  41. walk_chance = 60,
  42. view_range = 5,
  43. follow = {"farming:wheat", "default:apple"},
  44. passive = true,
  45. hp_min = 12,
  46. hp_max = 16,
  47. armor = 200,
  48. lava_damage = 5,
  49. fall_damage = 5,
  50. water_damage = 1,
  51. makes_footstep_sound = true,
  52. drops = {
  53. {name = "mobs:leather", chance = 1, min = 0, max = 2},
  54. {name = 'bonemeal:bone', chance = 2, min = 1, max = 10},
  55. {name = 'mobs:meat_raw', chance = 1, min = 1, max = 6},
  56. },
  57. do_custom = function(self, dtime)
  58. -- set needed values if not already present
  59. if not self.v2 then
  60. self.v2 = 0
  61. self.max_speed_forward = 6
  62. self.max_speed_reverse = 2
  63. self.accel = 6
  64. self.terrain_type = 3
  65. self.driver_attach_at = {x = 0, y = y_off, z = -2}
  66. self.driver_eye_offset = {x = 0, y = 3, z = 0}
  67. end
  68. -- if driver present allow control of horse
  69. if self.driver then
  70. mobs.drive(self, "walk", "stand", false, dtime)
  71. return false -- skip rest of mob functions
  72. end
  73. return true
  74. end,
  75. on_die = function(self, pos)
  76. -- drop saddle when horse is killed while riding
  77. -- also detach from horse properly
  78. if self.driver then
  79. minetest.add_item(pos, "mobs:saddle")
  80. mobs.detach(self.driver, {x = 1, y = 0, z = 1})
  81. self.saddle = nil
  82. end
  83. -- drop any horseshoes added
  84. if self.shoed then
  85. minetest.add_item(pos, self.shoed)
  86. end
  87. end,
  88. on_rightclick = function(self, clicker)
  89. -- make sure player is clicking
  90. if not clicker or not clicker:is_player() then
  91. return
  92. end
  93. -- feed, tame or heal horse
  94. if mobs:feed_tame(self, clicker, 10, true, true) then
  95. return
  96. end
  97. -- applying protection rune
  98. if mobs:protect(self, clicker) then
  99. return
  100. end
  101. -- make sure tamed horse is being clicked by owner only
  102. if self.tamed and self.owner == clicker:get_player_name() then
  103. local inv = clicker:get_inventory()
  104. local tool = clicker:get_wielded_item()
  105. local item = tool:get_name()
  106. -- detatch player already riding horse
  107. if self.driver and clicker == self.driver then
  108. mobs.detach(clicker, {x = 1, y = 0, z = 1})
  109. -- add saddle back to inventory
  110. if inv:room_for_item("main", "mobs:saddle") then
  111. inv:add_item("main", "mobs:saddle")
  112. else
  113. minetest.add_item(clicker:get_pos(), "mobs:saddle")
  114. end
  115. self.saddle = nil
  116. -- attach player to horse
  117. elseif (not self.driver and not self.child
  118. and clicker:get_wielded_item():get_name() == "mobs:saddle")
  119. or self.saddle then
  120. self.object:set_properties({stepheight = 1.1})
  121. mobs.attach(self, clicker)
  122. -- take saddle from inventory
  123. if not self.saddle then
  124. inv:remove_item("main", "mobs:saddle")
  125. end
  126. self.saddle = true
  127. end
  128. -- apply horseshoes
  129. if item:find("mobs:horseshoe") then
  130. -- drop any existing shoes
  131. if self.shoed then
  132. minetest.add_item(self.object:get_pos(), self.shoed)
  133. end
  134. local speed = shoes[item][1]
  135. local jump = shoes[item][2]
  136. local reverse = shoes[item][3]
  137. local overlay = shoes[item][4]
  138. self.max_speed_forward = speed
  139. self.jump_height = jump
  140. self.max_speed_reverse = reverse
  141. self.accel = speed
  142. self.shoed = item
  143. -- apply horseshoe overlay to current horse texture
  144. if overlay then
  145. local ov = self.base_texture
  146. ov[1] = ov[1] .. "^" .. overlay
  147. self.object:set_properties({textures = ov})
  148. end
  149. -- show horse speed and jump stats with shoes fitted
  150. minetest.chat_send_player(clicker:get_player_name(),
  151. S("Horse shoes fitted -")
  152. .. S(" speed: ") .. speed
  153. .. S(" , jump height: ") .. jump
  154. .. S(" , stop speed: ") .. reverse)
  155. tool:take_item() ; clicker:set_wielded_item(tool)
  156. return
  157. end
  158. end
  159. -- used to capture horse with magic lasso
  160. mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
  161. end,
  162. })
  163. mobs:spawn({
  164. name = "mob_horse:horse",
  165. nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"},
  166. min_light = 14,
  167. interval = 60,
  168. chance = 16000,
  169. min_height = 10,
  170. max_height = 31000,
  171. day_toggle = true,
  172. })
  173. mobs:register_egg("mob_horse:horse", S("Horse"), "wool.png^[multiply:#40230f", 1)
  174. -- steel horseshoes
  175. minetest.register_craftitem(":mobs:horseshoe_steel", {
  176. description = S("Steel HorseShoes (use on horse to apply)"),
  177. inventory_image = "mobs_horseshoe_steel.png",
  178. })
  179. minetest.register_craft({
  180. output = "mobs:horseshoe_steel",
  181. recipe = {
  182. {"", "default:steelblock", ""},
  183. {"default:steel_ingot", "", "default:steel_ingot"},
  184. {"default:steel_ingot", "", "default:steel_ingot"},
  185. }
  186. })
  187. -- bronze horseshoes
  188. minetest.register_craftitem(":mobs:horseshoe_bronze", {
  189. description = S("Bronze HorseShoes (use on horse to apply)"),
  190. inventory_image = "mobs_horseshoe_bronze.png",
  191. })
  192. minetest.register_craft({
  193. output = "mobs:horseshoe_bronze",
  194. recipe = {
  195. {"", "default:bronzeblock", ""},
  196. {"default:bronze_ingot", "", "default:bronze_ingot"},
  197. {"default:bronze_ingot", "", "default:bronze_ingot"},
  198. }
  199. })
  200. -- mese horseshoes
  201. minetest.register_craftitem(":mobs:horseshoe_mese", {
  202. description = S("Mese HorseShoes (use on horse to apply)"),
  203. inventory_image = "mobs_horseshoe_mese.png",
  204. })
  205. minetest.register_craft({
  206. output = "mobs:horseshoe_mese",
  207. recipe = {
  208. {"", "default:mese", ""},
  209. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
  210. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
  211. }
  212. })
  213. -- diamond horseshoes
  214. minetest.register_craftitem(":mobs:horseshoe_diamond", {
  215. description = S("Diamond HorseShoes (use on horse to apply)"),
  216. inventory_image = "mobs_horseshoe_diamond.png",
  217. })
  218. minetest.register_craft({
  219. output = "mobs:horseshoe_diamond",
  220. recipe = {
  221. {"", "default:diamondblock", ""},
  222. {"default:diamond", "", "default:diamond"},
  223. {"default:diamond", "", "default:diamond"},
  224. }
  225. })
  226. -- lucky blocks
  227. if minetest.get_modpath("lucky_block") then
  228. lucky_block:add_blocks({
  229. {"dro", {"mobs:horseshoe_steel"}},
  230. {"dro", {"mobs:horseshoe_bronze"}},
  231. {"dro", {"mobs:horseshoe_mese"}},
  232. {"dro", {"mobs:horseshoe_diamond"}},
  233. })
  234. end