crafts.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. local mod_def = minetest.get_modpath("default")
  130. if mod_def and default.register_fence then
  131. -- mob fence (looks like normal fence but collision is 2 high)
  132. default.register_fence("mobs:fence_wood", {
  133. description = S("Mob Fence"),
  134. texture = "default_wood.png",
  135. material = "default:fence_wood",
  136. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  137. sounds = mod_def and default.node_sound_wood_defaults(),
  138. collision_box = {
  139. type = "fixed",
  140. fixed = {
  141. {-0.5, -0.5, -0.5, 0.5, 1.9, 0.5},
  142. }
  143. }
  144. })
  145. end
  146. -- mob fence top (has enlarged collisionbox to stop mobs getting over)
  147. minetest.register_node("mobs:fence_top", {
  148. description = S("Mob Fence Top"),
  149. drawtype = "nodebox",
  150. tiles = {"default_wood.png"},
  151. paramtype = "light",
  152. is_ground_content = false,
  153. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  154. sounds = mod_def and default.node_sound_wood_defaults(),
  155. node_box = {
  156. type = "fixed",
  157. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  158. },
  159. collision_box = {
  160. type = "fixed",
  161. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  162. },
  163. selection_box = {
  164. type = "fixed",
  165. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  166. }
  167. })
  168. minetest.register_craft({
  169. output = "mobs:fence_top 12",
  170. recipe = {
  171. {"group:wood", "group:wood", "group:wood"},
  172. {"", "default:fence_wood", ""}
  173. }
  174. })
  175. -- items that can be used as fuel
  176. minetest.register_craft({
  177. type = "fuel",
  178. recipe = "mobs:nametag",
  179. burntime = 3
  180. })
  181. minetest.register_craft({
  182. type = "fuel",
  183. recipe = "mobs:lasso",
  184. burntime = 7
  185. })
  186. minetest.register_craft({
  187. type = "fuel",
  188. recipe = "mobs:net",
  189. burntime = 8
  190. })
  191. minetest.register_craft({
  192. type = "fuel",
  193. recipe = "mobs:leather",
  194. burntime = 4
  195. })
  196. minetest.register_craft({
  197. type = "fuel",
  198. recipe = "mobs:saddle",
  199. burntime = 7
  200. })
  201. minetest.register_craft({
  202. type = "fuel",
  203. recipe = "mobs:fence_wood",
  204. burntime = 7
  205. })
  206. minetest.register_craft({
  207. type = "fuel",
  208. recipe = "mobs:fence_top",
  209. burntime = 2
  210. })
  211. -- this tool spawns same mob and adds owner, protected, nametag info
  212. -- then removes original entity, this is used for fixing any issues.
  213. -- also holding sneak while punching mob lets you change texture name.
  214. local tex_obj
  215. minetest.register_tool(":mobs:mob_reset_stick", {
  216. description = S("Mob Reset Stick"),
  217. inventory_image = "default_stick.png^[colorize:#ff000050",
  218. stack_max = 1,
  219. groups = {not_in_creative_inventory = 1},
  220. on_use = function(itemstack, user, pointed_thing)
  221. if pointed_thing.type ~= "object" then
  222. return
  223. end
  224. local obj = pointed_thing.ref
  225. local control = user:get_player_control()
  226. local sneak = control and control.sneak
  227. -- spawn same mob with saved stats, with random texture
  228. if obj and not sneak then
  229. local self = obj:get_luaentity()
  230. local obj2 = minetest.add_entity(obj:get_pos(), self.name)
  231. if obj2 then
  232. local ent2 = obj2:get_luaentity()
  233. ent2.protected = self.protected
  234. ent2.owner = self.owner
  235. ent2.nametag = self.nametag
  236. ent2.gotten = self.gotten
  237. ent2.tamed = self.tamed
  238. ent2.health = self.health
  239. ent2.order = self.order
  240. if self.child then
  241. obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
  242. end
  243. obj2:set_properties({nametag = self.nametag})
  244. obj:remove()
  245. end
  246. end
  247. -- display form to enter texture name ending in .png
  248. if obj and sneak then
  249. tex_obj = obj
  250. -- get base texture
  251. local bt = tex_obj:get_luaentity().base_texture[1]
  252. if type(bt) ~= "string" then
  253. bt = ""
  254. end
  255. local name = user:get_player_name()
  256. minetest.show_formspec(name, "mobs_texture", "size[8,4]"
  257. .. "field[0.5,1;7.5,0;name;"
  258. .. minetest.formspec_escape(S("Enter texture:")) .. ";" .. bt .. "]"
  259. .. "button_exit[2.5,3.5;3,1;mob_texture_change;"
  260. .. minetest.formspec_escape(S("Change")) .. "]")
  261. end
  262. end
  263. })
  264. minetest.register_on_player_receive_fields(function(player, formname, fields)
  265. -- right-clicked with nametag and name entered?
  266. if formname == "mobs_texture"
  267. and fields.name
  268. and fields.name ~= "" then
  269. -- does mob still exist?
  270. if not tex_obj
  271. or not tex_obj:get_luaentity() then
  272. return
  273. end
  274. -- make sure nametag is being used to name mob
  275. local item = player:get_wielded_item()
  276. if item:get_name() ~= "mobs:mob_reset_stick" then
  277. return
  278. end
  279. -- limit name entered to 64 characters long
  280. if fields.name:len() > 64 then
  281. fields.name = fields.name:sub(1, 64)
  282. end
  283. -- update texture
  284. local self = tex_obj:get_luaentity()
  285. self.base_texture = {fields.name}
  286. tex_obj:set_properties({textures = {fields.name}})
  287. -- reset external variable
  288. tex_obj = nil
  289. end
  290. end)
  291. -- Meat Block
  292. minetest.register_node("mobs:meatblock", {
  293. description = S("Meat Block"),
  294. tiles = {"mobs_meat_top.png", "mobs_meat_bottom.png", "mobs_meat_side.png"},
  295. paramtype2 = "facedir",
  296. groups = {choppy = 1, oddly_breakable_by_hand = 1, flammable = 2},
  297. sounds = mod_def and default.node_sound_leaves_defaults(),
  298. on_place = minetest.rotate_node,
  299. on_use = minetest.item_eat(20)
  300. })
  301. minetest.register_craft({
  302. output = "mobs:meatblock",
  303. recipe = {
  304. {"group:food_meat", "group:food_meat", "group:food_meat"},
  305. {"group:food_meat", "group:food_meat", "group:food_meat"},
  306. {"group:food_meat", "group:food_meat", "group:food_meat"}
  307. }
  308. })
  309. -- Meat Block (raw)
  310. minetest.register_node("mobs:meatblock_raw", {
  311. description = S("Raw Meat Block"),
  312. tiles = {"mobs_meat_raw_top.png", "mobs_meat_raw_bottom.png", "mobs_meat_raw_side.png"},
  313. paramtype2 = "facedir",
  314. groups = {choppy = 1, oddly_breakable_by_hand = 1, flammable = 2},
  315. sounds = mod_def and default.node_sound_leaves_defaults(),
  316. on_place = minetest.rotate_node,
  317. on_use = minetest.item_eat(20)
  318. })
  319. minetest.register_craft({
  320. output = "mobs:meatblock_raw",
  321. recipe = {
  322. {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"},
  323. {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"},
  324. {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"}
  325. }
  326. })
  327. minetest.register_craft({
  328. type = "cooking",
  329. output = "mobs:meatblock",
  330. recipe = "mobs:meatblock_raw",
  331. cooktime = 30
  332. })