init.lua 6.4 KB

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