crafts.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. local S = mobs.intllib
  2. -- name tag
  3. minetest.register_craftitem("mobs:nametag", {
  4. description = S("Name Tag"),
  5. inventory_image = "mobs_nametag.png",
  6. groups = {flammable = 2}
  7. })
  8. if minetest.get_modpath("dye") and minetest.get_modpath("farming") then
  9. minetest.register_craft({
  10. type = "shapeless",
  11. output = "mobs:nametag",
  12. recipe = {"default:paper", "dye:black", "farming:string"}
  13. })
  14. end
  15. -- leather
  16. minetest.register_craftitem("mobs:leather", {
  17. description = S("Leather"),
  18. inventory_image = "mobs_leather.png",
  19. groups = {flammable = 2}
  20. })
  21. -- raw meat
  22. minetest.register_craftitem("mobs:meat_raw", {
  23. description = S("Raw Meat"),
  24. inventory_image = "mobs_meat_raw.png",
  25. on_use = minetest.item_eat(3),
  26. groups = {food_meat_raw = 1, flammable = 2}
  27. })
  28. -- cooked meat
  29. minetest.register_craftitem("mobs:meat", {
  30. description = S("Meat"),
  31. inventory_image = "mobs_meat.png",
  32. on_use = minetest.item_eat(8),
  33. groups = {food_meat = 1, flammable = 2}
  34. })
  35. minetest.register_craft({
  36. type = "cooking",
  37. output = "mobs:meat",
  38. recipe = "mobs:meat_raw",
  39. cooktime = 5
  40. })
  41. -- lasso
  42. minetest.register_tool("mobs:lasso", {
  43. description = S("Lasso (right-click animal to put in inventory)"),
  44. inventory_image = "mobs_magic_lasso.png",
  45. groups = {flammable = 2}
  46. })
  47. if minetest.get_modpath("farming") then
  48. minetest.register_craft({
  49. output = "mobs:lasso",
  50. recipe = {
  51. {"farming:string", "", "farming:string"},
  52. {"", "default:diamond", ""},
  53. {"farming:string", "", "farming:string"}
  54. }
  55. })
  56. end
  57. minetest.register_alias("mobs:magic_lasso", "mobs:lasso")
  58. -- net
  59. minetest.register_tool("mobs:net", {
  60. description = S("Net (right-click animal to put in inventory)"),
  61. inventory_image = "mobs_net.png",
  62. groups = {flammable = 2}
  63. })
  64. if minetest.get_modpath("farming") then
  65. minetest.register_craft({
  66. output = "mobs:net",
  67. recipe = {
  68. {"group:stick", "", "group:stick"},
  69. {"group:stick", "", "group:stick"},
  70. {"farming:string", "group:stick", "farming:string"}
  71. }
  72. })
  73. end
  74. -- shears (right click to shear animal)
  75. minetest.register_tool("mobs:shears", {
  76. description = S("Steel Shears (right-click to shear)"),
  77. inventory_image = "mobs_shears.png",
  78. groups = {flammable = 2}
  79. })
  80. minetest.register_craft({
  81. output = "mobs:shears",
  82. recipe = {
  83. {"", "default:steel_ingot", ""},
  84. {"", "group:stick", "default:steel_ingot"}
  85. }
  86. })
  87. -- protection rune
  88. minetest.register_craftitem("mobs:protector", {
  89. description = S("Mob Protection Rune"),
  90. inventory_image = "mobs_protector.png",
  91. groups = {flammable = 2}
  92. })
  93. minetest.register_craft({
  94. output = "mobs:protector",
  95. recipe = {
  96. {"default:stone", "default:stone", "default:stone"},
  97. {"default:stone", "default:goldblock", "default:stone"},
  98. {"default:stone", "default:stone", "default:stone"}
  99. }
  100. })
  101. -- saddle
  102. minetest.register_craftitem("mobs:saddle", {
  103. description = S("Saddle"),
  104. inventory_image = "mobs_saddle.png",
  105. groups = {flammable = 2}
  106. })
  107. minetest.register_craft({
  108. output = "mobs:saddle",
  109. recipe = {
  110. {"mobs:leather", "mobs:leather", "mobs:leather"},
  111. {"mobs:leather", "default:steel_ingot", "mobs:leather"},
  112. {"mobs:leather", "default:steel_ingot", "mobs:leather"}
  113. }
  114. })
  115. -- make sure we can register fences
  116. if default.register_fence then
  117. -- mob fence (looks like normal fence but collision is 2 high)
  118. default.register_fence("mobs:fence_wood", {
  119. description = S("Mob Fence"),
  120. texture = "default_wood.png",
  121. material = "default:fence_wood",
  122. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  123. sounds = default.node_sound_wood_defaults(),
  124. collision_box = {
  125. type = "fixed",
  126. fixed = {
  127. {-0.5, -0.5, -0.5, 0.5, 1.9, 0.5},
  128. }
  129. }
  130. })
  131. -- mob fence top (has enlarged collisionbox to stop mobs getting over)
  132. minetest.register_node("mobs:fence_top", {
  133. description = S("Mob Fence Top"),
  134. drawtype = "nodebox",
  135. tiles = {"default_wood.png"},
  136. paramtype = "light",
  137. is_ground_content = false,
  138. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  139. sounds = default.node_sound_wood_defaults(),
  140. node_box = {
  141. type = "fixed",
  142. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  143. },
  144. collision_box = {
  145. type = "fixed",
  146. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  147. },
  148. selection_box = {
  149. type = "fixed",
  150. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  151. }
  152. })
  153. minetest.register_craft({
  154. output = "mobs:fence_top 12",
  155. recipe = {
  156. {"group:wood", "group:wood", "group:wood"},
  157. {"", "default:fence_wood", ""}
  158. }
  159. })
  160. end
  161. -- items that can be used as fuel
  162. minetest.register_craft({
  163. type = "fuel",
  164. recipe = "mobs:nametag",
  165. burntime = 3
  166. })
  167. minetest.register_craft({
  168. type = "fuel",
  169. recipe = "mobs:lasso",
  170. burntime = 7
  171. })
  172. minetest.register_craft({
  173. type = "fuel",
  174. recipe = "mobs:net",
  175. burntime = 8
  176. })
  177. minetest.register_craft({
  178. type = "fuel",
  179. recipe = "mobs:leather",
  180. burntime = 4
  181. })
  182. minetest.register_craft({
  183. type = "fuel",
  184. recipe = "mobs:saddle",
  185. burntime = 7
  186. })
  187. minetest.register_craft({
  188. type = "fuel",
  189. recipe = "mobs:fence_wood",
  190. burntime = 7
  191. })
  192. minetest.register_craft({
  193. type = "fuel",
  194. recipe = "mobs:fence_top",
  195. burntime = 2
  196. })
  197. -- this tool spawns same mob and adds owner, protected, nametag info
  198. -- then removes original entity, this is used for fixing any issues.
  199. local tex_obj
  200. minetest.register_tool(":mobs:mob_reset_stick", {
  201. description = S("Mob Reset Stick"),
  202. inventory_image = "default_stick.png^[colorize:#ff000050",
  203. stack_max = 1,
  204. groups = {not_in_creative_inventory = 1},
  205. on_use = function(itemstack, user, pointed_thing)
  206. if pointed_thing.type ~= "object" then
  207. return
  208. end
  209. local obj = pointed_thing.ref
  210. local control = user:get_player_control()
  211. local sneak = control and control.sneak
  212. -- spawn same mob with saved stats, with random texture
  213. if obj and not sneak then
  214. local self = obj:get_luaentity()
  215. local obj2 = minetest.add_entity(obj:get_pos(), self.name)
  216. if obj2 then
  217. local ent2 = obj2:get_luaentity()
  218. ent2.protected = self.protected
  219. ent2.owner = self.owner
  220. ent2.nametag = self.nametag
  221. ent2.gotten = self.gotten
  222. ent2.tamed = self.tamed
  223. ent2.health = self.health
  224. ent2.order = self.order
  225. if self.child then
  226. obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
  227. end
  228. obj2:set_properties({nametag = self.nametag})
  229. obj:remove()
  230. end
  231. end
  232. -- display form to enter texture name ending in .png
  233. if obj and sneak then
  234. tex_obj = obj
  235. local name = user:get_player_name()
  236. local tex = ""
  237. minetest.show_formspec(name, "mobs_texture", "size[8,4]"
  238. .. "field[0.5,1;7.5,0;name;"
  239. .. minetest.formspec_escape(S("Enter texture:")) .. ";" .. tex .. "]"
  240. .. "button_exit[2.5,3.5;3,1;mob_texture_change;"
  241. .. minetest.formspec_escape(S("Change")) .. "]")
  242. end
  243. end
  244. })
  245. minetest.register_on_player_receive_fields(function(player, formname, fields)
  246. -- right-clicked with nametag and name entered?
  247. if formname == "mobs_texture"
  248. and fields.name
  249. and fields.name ~= "" then
  250. -- does mob still exist?
  251. if not tex_obj
  252. or not tex_obj:get_luaentity() then
  253. return
  254. end
  255. -- make sure nametag is being used to name mob
  256. local item = player:get_wielded_item()
  257. if item:get_name() ~= "mobs:mob_reset_stick" then
  258. return
  259. end
  260. -- limit name entered to 64 characters long
  261. if fields.name:len() > 64 then
  262. fields.name = fields.name:sub(1, 64)
  263. end
  264. -- update texture
  265. local self = tex_obj:get_luaentity()
  266. self.base_texture = {fields.name}
  267. tex_obj:set_properties({textures = {fields.name}})
  268. -- reset external variable
  269. tex_obj = nil
  270. end
  271. end)