init.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. local S = minetest.get_translator("basic_tools")
  2. --helper functions
  3. do_nothing = function() end
  4. local function wear_out(itemstack, user)
  5. local wear = itemstack:get_wear()
  6. wear = wear + 0x100 --255 uses
  7. --numbers with prefix 0x are in hexadecimal if you didn't know
  8. if wear < 0xFFFF
  9. then
  10. itemstack:set_wear(wear)
  11. return itemstack
  12. else
  13. minetest.sound_play(generic_media.tool_breaks_default(), {object = user})
  14. return ItemStack(itemstack:get_name() .. "_broken")
  15. end
  16. end
  17. local function repair(itemstack)
  18. local wear = itemstack:get_wear()
  19. wear = wear - 0x4000
  20. if wear <= 0
  21. then
  22. itemstack:set_wear(0)
  23. else
  24. itemstack:set_wear(wear)
  25. end
  26. return ItemStack(nil)
  27. end
  28. local broken_color = "#FF9090"
  29. local repair_helpstr = "\n" .. S("Use an anvil to repair")
  30. --shovel
  31. ------------------------------------------------------------------------
  32. minetest.register_craftitem("basic_tools:shovel_broken",
  33. {
  34. description = minetest.colorize(broken_color,
  35. S("Broken Shovel") .. repair_helpstr),
  36. inventory_image = "basic_tools_shovel_broken.png",
  37. groups = {shovel = 1, broken_tool = 1},
  38. stack_max = 1,
  39. wield_scale = {x = 2, y = 2, z = 1},
  40. tool_capabilities =
  41. {
  42. full_punch_interval = 2,
  43. max_drop_level = 3,
  44. groupcaps =
  45. {
  46. crumbly =
  47. {
  48. maxlevel = 3,
  49. times = {4 , 3.5, 3},
  50. }
  51. },
  52. damage_groups =
  53. {
  54. fleshy = 1
  55. }
  56. },
  57. on_drop = do_nothing,
  58. })
  59. minetest.register_tool("basic_tools:shovel",
  60. {
  61. description = S("Shovel"),
  62. inventory_image = "basic_tools_shovel.png",
  63. groups = {shovel = 1, tool = 1},
  64. stack_max = 1,
  65. wield_scale = {x = 2, y = 2, z = 1},
  66. tool_capabilities =
  67. {
  68. full_punch_interval = 2,
  69. max_drop_level = 3,
  70. groupcaps =
  71. {
  72. crumbly =
  73. {
  74. maxlevel = 3,
  75. times = {1.5 , 1, 0.4},
  76. }
  77. },
  78. damage_groups =
  79. {
  80. fleshy = 1
  81. }
  82. },
  83. after_use = wear_out,
  84. on_drop = do_nothing,
  85. })
  86. minetest.register_alias("shovel", "basic_tools:shovel")
  87. minetest.register_alias("broken_shovel", "basic_tools:shovel_broken")
  88. give_initial_stuff.add("shovel")
  89. repairing_anvils.register_recipe("broken_shovel", "shovel 1 65500")
  90. repairing_anvils.register_recipe("shovel", repair)
  91. --pickaxe
  92. ------------------------------------------------------------------------
  93. minetest.register_craftitem("basic_tools:pickaxe_broken",
  94. {
  95. description = minetest.colorize(broken_color,
  96. S("Broken Pickaxe") .. repair_helpstr),
  97. inventory_image = "basic_tools_pickaxe_broken.png",
  98. groups = {shovel = 1, broken_tool = 1},
  99. stack_max = 1,
  100. wield_scale = {x = 2, y = 2, z = 1},
  101. tool_capabilities =
  102. {
  103. full_punch_interval = 2,
  104. max_drop_level = 3,
  105. groupcaps =
  106. {
  107. cracky =
  108. {
  109. maxlevel = 3,
  110. times = {5 , 4, 3.5},
  111. }
  112. },
  113. damage_groups =
  114. {
  115. fleshy = 1
  116. }
  117. },
  118. on_drop = do_nothing,
  119. })
  120. minetest.register_tool("basic_tools:pickaxe",
  121. {
  122. description = S("Pickaxe"),
  123. inventory_image = "basic_tools_pickaxe.png",
  124. groups = {pickaxe = 1, tool = 1},
  125. stack_max = 1,
  126. wield_scale = {x = 2, y = 2, z = 1},
  127. tool_capabilities =
  128. {
  129. full_punch_interval = 2,
  130. max_drop_level = 3,
  131. groupcaps =
  132. {
  133. cracky =
  134. {
  135. maxlevel = 3,
  136. times = {3 , 2, 1.4},
  137. }
  138. },
  139. damage_groups =
  140. {
  141. fleshy = 1
  142. }
  143. },
  144. after_use = wear_out,
  145. on_drop = do_nothing,
  146. })
  147. minetest.register_alias("pickaxe", "basic_tools:pickaxe")
  148. minetest.register_alias("broken_pickaxe", "basic_tools:pickaxe_broken")
  149. give_initial_stuff.add("pickaxe")
  150. repairing_anvils.register_recipe("broken_pickaxe", "pickaxe 1 65500")
  151. repairing_anvils.register_recipe("pickaxe", repair)
  152. --axe
  153. ------------------------------------------------------------------------
  154. minetest.register_craftitem("basic_tools:axe_broken",
  155. {
  156. description = minetest.colorize(broken_color,
  157. S("Broken Axe") .. repair_helpstr),
  158. inventory_image = "basic_tools_axe_broken.png",
  159. groups = {shovel = 1, broken_tool = 1},
  160. stack_max = 1,
  161. wield_scale = {x = 2, y = 2, z = 1},
  162. tool_capabilities =
  163. {
  164. full_punch_interval = 2,
  165. max_drop_level = 3,
  166. groupcaps =
  167. {
  168. choppy =
  169. {
  170. maxlevel = 3,
  171. times = {4 , 3.5, 3},
  172. }
  173. },
  174. damage_groups =
  175. {
  176. fleshy = 1
  177. }
  178. },
  179. on_drop = do_nothing,
  180. })
  181. minetest.register_tool("basic_tools:axe",
  182. {
  183. description = S("Axe"),
  184. inventory_image = "basic_tools_axe.png",
  185. groups = {shovel = 1, tool = 1},
  186. stack_max = 1,
  187. wield_scale = {x = 2, y = 2, z = 1},
  188. tool_capabilities =
  189. {
  190. full_punch_interval = 2,
  191. max_drop_level = 3,
  192. groupcaps =
  193. {
  194. choppy =
  195. {
  196. maxlevel = 3,
  197. times = {2 , 1.5, 0.8},
  198. }
  199. },
  200. damage_groups =
  201. {
  202. fleshy = 1
  203. }
  204. },
  205. after_use = wear_out,
  206. on_drop = do_nothing,
  207. })
  208. minetest.register_alias("axe", "basic_tools:axe")
  209. minetest.register_alias("broken_axe", "basic_tools:axe_broken")
  210. give_initial_stuff.add("axe")
  211. repairing_anvils.register_recipe("broken_axe", "axe 1 65500")
  212. repairing_anvils.register_recipe("axe", repair)