crafts.lua 8.7 KB

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