init.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. -- Load support for intllib.
  2. local MP = minetest.get_modpath(minetest.get_current_modname()) .. "/"
  3. local S = minetest.get_translator and minetest.get_translator("mob_horse") or
  4. dofile(MP .. "intllib.lua")
  5. -- 0.4.17 or 5.0 check
  6. local y_off = 20
  7. if minetest.features.object_independent_selectionbox then
  8. y_off = 10
  9. end
  10. -- horse shoes (speed, jump, break, overlay texture)
  11. local shoes = {
  12. ["mobs:horseshoe_steel"] = {7, 4, 2, "mobs_horseshoe_steelo.png"},
  13. ["mobs:horseshoe_bronze"] = {7, 4, 4, "mobs_horseshoe_bronzeo.png"},
  14. ["mobs:horseshoe_mese"] = {9, 5, 8, "mobs_horseshoe_meseo.png"},
  15. ["mobs:horseshoe_diamond"] = {10, 6, 6, "mobs_horseshoe_diamondo.png"},
  16. ["mobs:horseshoe_crystal"] = {11, 6, 9, "mobs_horseshoe_crystalo.png"}
  17. }
  18. -- rideable horse
  19. mobs:register_mob("mob_horse:horse", {
  20. type = "animal",
  21. visual = "mesh",
  22. visual_size = {x = 1.20, y = 1.20},
  23. mesh = "mobs_horse.x",
  24. collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
  25. animation = {
  26. speed_normal = 15,
  27. speed_run = 30,
  28. stand_start = 25,
  29. stand_end = 50, -- 75
  30. stand2_start = 25,
  31. stand2_end = 25,
  32. stand3_start = 55,
  33. stand3_end = 75,
  34. stand3_loop = false,
  35. walk_start = 75,
  36. walk_end = 100,
  37. run_start = 75,
  38. run_end = 100
  39. },
  40. textures = {
  41. {"mobs_horse.png"}, -- textures by Mjollna
  42. {"mobs_horsepeg.png"},
  43. {"mobs_horseara.png"}
  44. },
  45. fear_height = 3,
  46. runaway = true,
  47. fly = false,
  48. walk_chance = 60,
  49. view_range = 5,
  50. follow = {
  51. "farming:wheat", "default:apple", "farming:oat",
  52. "farming:barley", "farming:corn"},
  53. passive = true,
  54. hp_min = 12,
  55. hp_max = 16,
  56. armor = 200,
  57. lava_damage = 5,
  58. fall_damage = 5,
  59. water_damage = 1,
  60. makes_footstep_sound = true,
  61. drops = {
  62. {name = "mobs:leather", chance = 1, min = 0, max = 2}
  63. },
  64. do_custom = function(self, dtime)
  65. -- set needed values if not already present
  66. if not self.v2 then
  67. self.v2 = 0
  68. self.max_speed_forward = 6
  69. self.max_speed_reverse = 2
  70. self.accel = 6
  71. self.terrain_type = 3
  72. self.driver_attach_at = {x = 0, y = y_off, z = -2}
  73. self.driver_eye_offset = {x = 0, y = 3, z = 0}
  74. self.driver_scale = {x = 0.8, y = 0.8} -- shrink driver to fit model
  75. end
  76. -- if driver present allow control of horse
  77. if self.driver then
  78. mobs.drive(self, "walk", "stand", false, dtime)
  79. return false -- skip rest of mob functions
  80. end
  81. return true
  82. end,
  83. on_die = function(self, pos)
  84. -- detach player from horse properly
  85. if self.driver then
  86. mobs.detach(self.driver, {x = 1, y = 0, z = 1})
  87. end
  88. -- drop saddle if found
  89. if self.saddle then
  90. minetest.add_item(pos, "mobs:saddle")
  91. end
  92. -- drop any horseshoes added
  93. if self.shoed then
  94. minetest.add_item(pos, self.shoed)
  95. end
  96. end,
  97. do_punch = function(self, hitter)
  98. -- don't cut the branch you're... ah, that's not about that
  99. if hitter ~= self.driver then
  100. return true
  101. end
  102. end,
  103. on_rightclick = function(self, clicker)
  104. -- make sure player is clicking
  105. if not clicker or not clicker:is_player() then
  106. return
  107. end
  108. -- feed, tame or heal horse
  109. if mobs:feed_tame(self, clicker, 10, true, true) then
  110. return
  111. end
  112. -- applying protection rune
  113. if mobs:protect(self, clicker) then
  114. return
  115. end
  116. local player_name = clicker:get_player_name()
  117. -- make sure tamed horse is being clicked by owner only
  118. if self.tamed and self.owner == player_name then
  119. local inv = clicker:get_inventory()
  120. local tool = clicker:get_wielded_item()
  121. local item = tool:get_name()
  122. -- detatch player already riding horse
  123. if self.driver and clicker == self.driver then
  124. mobs.detach(clicker, {x = 1, y = 0, z = 1})
  125. return
  126. end
  127. -- attach saddle to horse
  128. if not self.driver
  129. and not self.child
  130. and clicker:get_wielded_item():get_name() == "mobs:saddle"
  131. and not self.saddle then
  132. self.saddle = true
  133. self.order = "stand"
  134. self.object:set_properties({stepheight = 1.1})
  135. -- take saddle from inventory
  136. inv:remove_item("main", "mobs:saddle")
  137. self.texture_mods = self.texture_mods .. "^mobs_saddle_overlay.png"
  138. self.object:set_texture_mod(self.texture_mods)
  139. return
  140. end
  141. -- apply horseshoes
  142. if item:find("mobs:horseshoe") then
  143. -- drop any existing shoes
  144. if self.shoed then
  145. minetest.add_item(self.object:get_pos(), self.shoed)
  146. end
  147. local speed = shoes[item][1]
  148. local jump = shoes[item][2]
  149. local reverse = shoes[item][3]
  150. local overlay = shoes[item][4]
  151. self.max_speed_forward = speed
  152. self.jump_height = jump
  153. self.max_speed_reverse = reverse
  154. self.accel = speed
  155. self.shoed = item
  156. -- apply horseshoe overlay to current horse texture
  157. if overlay then
  158. self.texture_mods = "^" .. overlay
  159. if self.saddle then
  160. self.texture_mods = self.texture_mods
  161. .. "^mobs_saddle_overlay.png"
  162. end
  163. self.object:set_texture_mod(self.texture_mods)
  164. end
  165. -- show horse speed and jump stats with shoes fitted
  166. minetest.chat_send_player(player_name,
  167. S("Horse shoes fitted -")
  168. .. S(" speed: ") .. speed
  169. .. S(" , jump height: ") .. jump
  170. .. S(" , stop speed: ") .. reverse)
  171. tool:take_item()
  172. clicker:set_wielded_item(tool)
  173. return
  174. end
  175. end
  176. -- used to capture horse with magic lasso
  177. if mobs:capture_mob(self, clicker, nil, nil, 100, false, nil) then return end
  178. -- ride horse if saddled
  179. if self.saddle and self.owner == player_name then
  180. mobs.attach(self, clicker)
  181. end
  182. end
  183. })
  184. -- check for custom spawn.lua
  185. local input = io.open(MP .. "spawn.lua", "r")
  186. if input then
  187. input:close()
  188. input = nil
  189. dofile(MP .. "spawn.lua")
  190. else
  191. mobs:spawn({
  192. name = "mob_horse:horse",
  193. nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"},
  194. min_light = 14,
  195. interval = 60,
  196. chance = 16000,
  197. min_height = 10,
  198. max_height = 31000,
  199. day_toggle = true
  200. })
  201. end
  202. mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1)
  203. -- steel horseshoes
  204. minetest.register_craftitem(":mobs:horseshoe_steel", {
  205. description = S("Steel HorseShoes (use on horse to apply)"),
  206. inventory_image = "mobs_horseshoe_steel.png",
  207. })
  208. minetest.register_craft({
  209. output = "mobs:horseshoe_steel",
  210. recipe = {
  211. {"", "default:steelblock", ""},
  212. {"default:steel_ingot", "", "default:steel_ingot"},
  213. {"default:steel_ingot", "", "default:steel_ingot"}
  214. }
  215. })
  216. -- bronze horseshoes
  217. minetest.register_craftitem(":mobs:horseshoe_bronze", {
  218. description = S("Bronze HorseShoes (use on horse to apply)"),
  219. inventory_image = "mobs_horseshoe_bronze.png"
  220. })
  221. minetest.register_craft({
  222. output = "mobs:horseshoe_bronze",
  223. recipe = {
  224. {"", "default:bronzeblock", ""},
  225. {"default:bronze_ingot", "", "default:bronze_ingot"},
  226. {"default:bronze_ingot", "", "default:bronze_ingot"}
  227. }
  228. })
  229. -- mese horseshoes
  230. minetest.register_craftitem(":mobs:horseshoe_mese", {
  231. description = S("Mese HorseShoes (use on horse to apply)"),
  232. inventory_image = "mobs_horseshoe_mese.png"
  233. })
  234. minetest.register_craft({
  235. output = "mobs:horseshoe_mese",
  236. recipe = {
  237. {"", "default:mese", ""},
  238. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
  239. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"}
  240. }
  241. })
  242. -- diamond horseshoes
  243. minetest.register_craftitem(":mobs:horseshoe_diamond", {
  244. description = S("Diamond HorseShoes (use on horse to apply)"),
  245. inventory_image = "mobs_horseshoe_diamond.png"
  246. })
  247. minetest.register_craft({
  248. output = "mobs:horseshoe_diamond",
  249. recipe = {
  250. {"", "default:diamondblock", ""},
  251. {"default:diamond", "", "default:diamond"},
  252. {"default:diamond", "", "default:diamond"}
  253. }
  254. })
  255. -- crystal horseshoes
  256. if minetest.get_modpath("ethereal") then
  257. minetest.register_craftitem(":mobs:horseshoe_crystal", {
  258. description = S("Crystal HorseShoes (use on horse to apply)"),
  259. inventory_image = "mobs_horseshoe_crystal.png"
  260. })
  261. minetest.register_craft({
  262. output = "mobs:horseshoe_crystal",
  263. recipe = {
  264. {"", "ethereal:crystal_block", ""},
  265. {"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"},
  266. {"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"}
  267. }
  268. })
  269. end
  270. -- lucky blocks
  271. if minetest.get_modpath("lucky_block") then
  272. lucky_block:add_blocks({
  273. {"dro", {"mobs:horseshoe_steel"}},
  274. {"dro", {"mobs:horseshoe_bronze"}},
  275. {"dro", {"mobs:horseshoe_mese"}},
  276. {"dro", {"mobs:horseshoe_diamond"}},
  277. {"dro", {"mobs:horseshoe_crystal"}}
  278. })
  279. end