init.lua 7.2 KB

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