crafts.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. -- mob fence (looks like normal fence but collision is 2 high)
  116. default.register_fence("mobs:fence_wood", {
  117. description = S("Mob Fence"),
  118. texture = "default_wood.png",
  119. material = "default:fence_wood",
  120. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  121. sounds = default.node_sound_wood_defaults(),
  122. collision_box = {
  123. type = "fixed",
  124. fixed = {
  125. {-0.5, -0.5, -0.5, 0.5, 1.9, 0.5},
  126. }
  127. }
  128. })
  129. -- mob fence top (has enlarged collisionbox to stop mobs getting over)
  130. minetest.register_node("mobs:fence_top", {
  131. description = S("Mob Fence Top"),
  132. drawtype = "nodebox",
  133. tiles = {"default_wood.png"},
  134. paramtype = "light",
  135. is_ground_content = false,
  136. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  137. sounds = default.node_sound_wood_defaults(),
  138. node_box = {
  139. type = "fixed",
  140. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  141. },
  142. collision_box = {
  143. type = "fixed",
  144. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  145. },
  146. selection_box = {
  147. type = "fixed",
  148. fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
  149. }
  150. })
  151. minetest.register_craft({
  152. output = "mobs:fence_top 12",
  153. recipe = {
  154. {"group:wood", "group:wood", "group:wood"},
  155. {"", "default:fence_wood", ""}
  156. }
  157. })
  158. -- items that can be used as fuel
  159. minetest.register_craft({
  160. type = "fuel",
  161. recipe = "mobs:nametag",
  162. burntime = 3
  163. })
  164. minetest.register_craft({
  165. type = "fuel",
  166. recipe = "mobs:lasso",
  167. burntime = 7
  168. })
  169. minetest.register_craft({
  170. type = "fuel",
  171. recipe = "mobs:net",
  172. burntime = 8
  173. })
  174. minetest.register_craft({
  175. type = "fuel",
  176. recipe = "mobs:leather",
  177. burntime = 4
  178. })
  179. minetest.register_craft({
  180. type = "fuel",
  181. recipe = "mobs:saddle",
  182. burntime = 7
  183. })
  184. minetest.register_craft({
  185. type = "fuel",
  186. recipe = "mobs:fence_wood",
  187. burntime = 7
  188. })
  189. minetest.register_craft({
  190. type = "fuel",
  191. recipe = "mobs:fence_top",
  192. burntime = 2
  193. })
  194. -- this tool spawns same mob and adds owner, protected, nametag info
  195. -- then removes original entity, this is used for fixing any issues.
  196. local tex_obj
  197. minetest.register_tool(":mobs:mob_reset_stick", {
  198. description = S("Mob Reset Stick"),
  199. inventory_image = "default_stick.png^[colorize:#ff000050",
  200. stack_max = 1,
  201. groups = {not_in_creative_inventory = 1},
  202. on_use = function(itemstack, user, pointed_thing)
  203. if pointed_thing.type ~= "object" then
  204. return
  205. end
  206. local obj = pointed_thing.ref
  207. local control = user:get_player_control()
  208. local sneak = control and control.sneak
  209. -- spawn same mob with saved stats, with random texture
  210. if obj and not sneak then
  211. local self = obj:get_luaentity()
  212. local obj2 = minetest.add_entity(obj:get_pos(), self.name)
  213. if obj2 then
  214. local ent2 = obj2:get_luaentity()
  215. ent2.protected = self.protected
  216. ent2.owner = self.owner
  217. ent2.nametag = self.nametag
  218. ent2.gotten = self.gotten
  219. ent2.tamed = self.tamed
  220. ent2.health = self.health
  221. ent2.order = self.order
  222. if self.child then
  223. obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
  224. end
  225. obj2:set_properties({nametag = self.nametag})
  226. obj:remove()
  227. end
  228. end
  229. -- display form to enter texture name ending in .png
  230. if obj and sneak then
  231. tex_obj = obj
  232. local name = user:get_player_name()
  233. local tex = ""
  234. minetest.show_formspec(name, "mobs_texture", "size[8,4]"
  235. .. "field[0.5,1;7.5,0;name;"
  236. .. minetest.formspec_escape(S("Enter texture:")) .. ";" .. tex .. "]"
  237. .. "button_exit[2.5,3.5;3,1;mob_texture_change;"
  238. .. minetest.formspec_escape(S("Change")) .. "]")
  239. end
  240. end
  241. })
  242. minetest.register_on_player_receive_fields(function(player, formname, fields)
  243. -- right-clicked with nametag and name entered?
  244. if formname == "mobs_texture"
  245. and fields.name
  246. and fields.name ~= "" then
  247. local name = player:get_player_name()
  248. -- does mob still exist?
  249. if not tex_obj
  250. or not tex_obj:get_luaentity() then
  251. return
  252. end
  253. -- make sure nametag is being used to name mob
  254. local item = player:get_wielded_item()
  255. if item:get_name() ~= "mobs:mob_reset_stick" then
  256. return
  257. end
  258. -- limit name entered to 64 characters long
  259. if string.len(fields.name) > 64 then
  260. fields.name = string.sub(fields.name, 1, 64)
  261. end
  262. -- update texture
  263. local self = tex_obj:get_luaentity()
  264. self.base_texture = {fields.name}
  265. tex_obj:set_properties({textures = {fields.name}})
  266. -- reset external variable
  267. tex_obj = nil
  268. end
  269. end)