You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
6.8KB

  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 = {
  44. "farming:wheat", "default:apple", "farming:oat",
  45. "farming:barley", "farming:corn"},
  46. passive = true,
  47. hp_min = 12,
  48. hp_max = 16,
  49. armor = 200,
  50. lava_damage = 5,
  51. fall_damage = 5,
  52. water_damage = 1,
  53. makes_footstep_sound = true,
  54. drops = {
  55. {name = "mobs:leather", chance = 1, min = 0, max = 2}
  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. self.texture_mods = "^" .. overlay
  146. self.object:set_texture_mod(self.texture_mods)
  147. end
  148. -- show horse speed and jump stats with shoes fitted
  149. minetest.chat_send_player(clicker:get_player_name(),
  150. S("Horse shoes fitted -")
  151. .. S(" speed: ") .. speed
  152. .. S(" , jump height: ") .. jump
  153. .. S(" , stop speed: ") .. reverse)
  154. tool:take_item() ; clicker:set_wielded_item(tool)
  155. return
  156. end
  157. end
  158. -- used to capture horse with magic lasso
  159. mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
  160. end,
  161. })
  162. mobs:spawn({
  163. name = "mob_horse:horse",
  164. nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"},
  165. min_light = 14,
  166. interval = 60,
  167. chance = 16000,
  168. min_height = 10,
  169. max_height = 31000,
  170. day_toggle = true,
  171. })
  172. mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1)
  173. -- steel horseshoes
  174. minetest.register_craftitem(":mobs:horseshoe_steel", {
  175. description = S("Steel HorseShoes (use on horse to apply)"),
  176. inventory_image = "mobs_horseshoe_steel.png",
  177. })
  178. minetest.register_craft({
  179. output = "mobs:horseshoe_steel",
  180. recipe = {
  181. {"", "default:steelblock", ""},
  182. {"default:steel_ingot", "", "default:steel_ingot"},
  183. {"default:steel_ingot", "", "default:steel_ingot"},
  184. }
  185. })
  186. -- bronze horseshoes
  187. minetest.register_craftitem(":mobs:horseshoe_bronze", {
  188. description = S("Bronze HorseShoes (use on horse to apply)"),
  189. inventory_image = "mobs_horseshoe_bronze.png",
  190. })
  191. minetest.register_craft({
  192. output = "mobs:horseshoe_bronze",
  193. recipe = {
  194. {"", "default:bronzeblock", ""},
  195. {"default:bronze_ingot", "", "default:bronze_ingot"},
  196. {"default:bronze_ingot", "", "default:bronze_ingot"},
  197. }
  198. })
  199. -- mese horseshoes
  200. minetest.register_craftitem(":mobs:horseshoe_mese", {
  201. description = S("Mese HorseShoes (use on horse to apply)"),
  202. inventory_image = "mobs_horseshoe_mese.png",
  203. })
  204. minetest.register_craft({
  205. output = "mobs:horseshoe_mese",
  206. recipe = {
  207. {"", "default:mese", ""},
  208. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
  209. {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
  210. }
  211. })
  212. -- diamond horseshoes
  213. minetest.register_craftitem(":mobs:horseshoe_diamond", {
  214. description = S("Diamond HorseShoes (use on horse to apply)"),
  215. inventory_image = "mobs_horseshoe_diamond.png",
  216. })
  217. minetest.register_craft({
  218. output = "mobs:horseshoe_diamond",
  219. recipe = {
  220. {"", "default:diamondblock", ""},
  221. {"default:diamond", "", "default:diamond"},
  222. {"default:diamond", "", "default:diamond"},
  223. }
  224. })
  225. -- lucky blocks
  226. if minetest.get_modpath("lucky_block") then
  227. lucky_block:add_blocks({
  228. {"dro", {"mobs:horseshoe_steel"}},
  229. {"dro", {"mobs:horseshoe_bronze"}},
  230. {"dro", {"mobs:horseshoe_mese"}},
  231. {"dro", {"mobs:horseshoe_diamond"}},
  232. })
  233. end