init.lua 8.7 KB

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