crafts.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. {"", "farming:string", "farming:string"},
  53. {"farming:string", "", ""}
  54. }
  55. })
  56. end
  57. minetest.register_alias("mobs:magic_lasso", "mobs:lasso")
  58. -- shears (right click to shear animal)
  59. minetest.register_tool("mobs:shears", {
  60. description = S("Steel Shears (right-click to shear)"),
  61. inventory_image = "mobs_shears.png",
  62. groups = {flammable = 2}
  63. })
  64. minetest.register_craft({
  65. output = "mobs:shears",
  66. recipe = {
  67. {"", "default:steel_ingot", ""},
  68. {"", "group:stick", "default:steel_ingot"}
  69. }
  70. })
  71. -- protection rune
  72. minetest.register_craftitem("mobs:protector", {
  73. description = S("Mob Protection Rune"),
  74. inventory_image = "mobs_protector.png",
  75. groups = {flammable = 2}
  76. })
  77. minetest.register_craft({
  78. output = "mobs:protector",
  79. recipe = {
  80. {"default:stone", "default:stone", "default:stone"},
  81. {"default:stone", "default:goldblock", "default:stone"},
  82. {"default:stone", "default:stone", "default:stone"}
  83. }
  84. })
  85. -- saddle
  86. minetest.register_craftitem("mobs:saddle", {
  87. description = S("Saddle"),
  88. inventory_image = "mobs_saddle.png",
  89. groups = {flammable = 2}
  90. })
  91. minetest.register_craft({
  92. output = "mobs:saddle",
  93. recipe = {
  94. {"mobs:leather", "mobs:leather", "mobs:leather"},
  95. {"mobs:leather", "default:steel_ingot", "mobs:leather"},
  96. {"mobs:leather", "default:steel_ingot", "mobs:leather"}
  97. }
  98. })
  99. -- items that can be used as fuel
  100. minetest.register_craft({
  101. type = "fuel",
  102. recipe = "mobs:nametag",
  103. burntime = 3
  104. })
  105. minetest.register_craft({
  106. type = "fuel",
  107. recipe = "mobs:lasso",
  108. burntime = 7
  109. })
  110. minetest.register_craft({
  111. type = "fuel",
  112. recipe = "mobs:net",
  113. burntime = 8
  114. })
  115. minetest.register_craft({
  116. type = "fuel",
  117. recipe = "mobs:leather",
  118. burntime = 4
  119. })
  120. minetest.register_craft({
  121. type = "fuel",
  122. recipe = "mobs:saddle",
  123. burntime = 7
  124. })
  125. -- this tool spawns same mob and adds owner, protected, nametag info
  126. -- then removes original entity, this is used for fixing any issues.
  127. local tex_obj
  128. minetest.register_tool(":mobs:mob_reset_stick", {
  129. description = S("Mob Reset Stick"),
  130. inventory_image = "default_stick.png^[colorize:#ff000050",
  131. stack_max = 1,
  132. groups = {not_in_creative_inventory = 1},
  133. on_use = function(itemstack, user, pointed_thing)
  134. if pointed_thing.type ~= "object" then
  135. return
  136. end
  137. local obj = pointed_thing.ref
  138. local control = user:get_player_control()
  139. local sneak = control and control.sneak
  140. -- spawn same mob with saved stats, with random texture
  141. if obj and not sneak then
  142. local self = obj:get_luaentity()
  143. local obj2 = minetest.add_entity(obj:get_pos(), self.name)
  144. if obj2 then
  145. local ent2 = obj2:get_luaentity()
  146. ent2.protected = self.protected
  147. ent2.owner = self.owner
  148. ent2.nametag = self.nametag
  149. ent2.gotten = self.gotten
  150. ent2.tamed = self.tamed
  151. ent2.health = self.health
  152. ent2.order = self.order
  153. if self.child then
  154. obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
  155. end
  156. obj2:set_properties({nametag = self.nametag})
  157. obj:remove()
  158. end
  159. end
  160. -- display form to enter texture name ending in .png
  161. if obj and sneak then
  162. tex_obj = obj
  163. local name = user:get_player_name()
  164. local tex = ""
  165. minetest.show_formspec(name, "mobs_texture", "size[8,4]"
  166. .. "field[0.5,1;7.5,0;name;"
  167. .. minetest.formspec_escape(S("Enter texture:")) .. ";" .. tex .. "]"
  168. .. "button_exit[2.5,3.5;3,1;mob_texture_change;"
  169. .. minetest.formspec_escape(S("Change")) .. "]")
  170. end
  171. end
  172. })
  173. minetest.register_on_player_receive_fields(function(player, formname, fields)
  174. -- right-clicked with nametag and name entered?
  175. if formname == "mobs_texture"
  176. and fields.name
  177. and fields.name ~= "" then
  178. -- does mob still exist?
  179. if not tex_obj
  180. or not tex_obj:get_luaentity() then
  181. return
  182. end
  183. -- make sure nametag is being used to name mob
  184. local item = player:get_wielded_item()
  185. if item:get_name() ~= "mobs:mob_reset_stick" then
  186. return
  187. end
  188. -- limit name entered to 64 characters long
  189. if fields.name:len() > 64 then
  190. fields.name = fields.name:sub(1, 64)
  191. end
  192. -- update texture
  193. local self = tex_obj:get_luaentity()
  194. self.base_texture = {fields.name}
  195. tex_obj:set_properties({textures = {fields.name}})
  196. -- reset external variable
  197. tex_obj = nil
  198. end
  199. end)