init.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. local old_craftreg = minetest.register_craft
  2. minetest.register_craft = function(c)
  3. if (c.type == "" or not c.type) and c.output then
  4. local tooltype =
  5. (string.find(c.output, ":hoe_") and "hoe") or
  6. (string.find(c.output, ":shovel_") and "shovel") or
  7. (string.find(c.output, ":pick_") and "pick") or
  8. (string.find(c.output, ":axe_") and "axe") or
  9. (string.find(c.output, ":sword_") and "sword")
  10. if not tooltype then old_craftreg(c); return end
  11. if type(c.recipe) ~= "table" or #c.recipe ~= 3 or type(c.recipe[3]) ~= "table" then old_craftreg(c); return end
  12. local A = c.recipe[1][math.min(#c.recipe[1], 2)]
  13. local B = c.recipe[3][math.min(#c.recipe[3], 2)]
  14. if tooltype == "hoe" then
  15. c.recipe = {
  16. {A, A, B},
  17. {"",B,""},
  18. {B,"",""}
  19. }
  20. elseif tooltype == "shovel" then
  21. c.recipe = {
  22. {"",A, A},
  23. {"",B, A},
  24. {B,"",""}
  25. }
  26. elseif tooltype == "pick" then
  27. c.recipe = {
  28. {A, A,""},
  29. {"",B, A},
  30. {B,"", A}
  31. }
  32. elseif tooltype == "axe" then
  33. c.recipe = {
  34. {A, A,""},
  35. {A, B,""},
  36. {B,"",""}
  37. }
  38. elseif tooltype == "sword" then
  39. c.recipe = {
  40. {"","",A},
  41. {A, A,""},
  42. {B, A,""}
  43. }
  44. end
  45. end
  46. old_craftreg(c)
  47. end