tools.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local ipairs, minetest, nodecore, pairs, type
  3. = ipairs, minetest, nodecore, pairs, type
  4. -- LUALOCALS > ---------------------------------------------------------
  5. local modname = minetest.get_current_modname()
  6. local function toolhead(name, groups, prills)
  7. local n = name:lower()
  8. if type(groups) == "string" then groups = {groups} end
  9. local function toolcap(nn)
  10. local t = {}
  11. for _, k in ipairs(groups) do t[k] = nn end
  12. return nodecore.toolcaps(t)
  13. end
  14. nodecore.register_lode("toolhead_" .. n, {
  15. type = "craft",
  16. description = "## Lode " .. name .. " Head",
  17. inventory_image = modname .. "_#.png^[mask:" ..
  18. modname .. "_toolhead_" .. n .. ".png",
  19. stack_max = 1,
  20. tool_head_capabilities = toolcap(4),
  21. bytemper = function(t, d)
  22. if t.name == "tempered" then
  23. d.tool_head_capabilities = toolcap(5)
  24. else if t.name == "hot" then
  25. d.tool_head_capabilities = toolcap(3)
  26. end
  27. end
  28. end
  29. })
  30. nodecore.register_lode("tool_" .. n, {
  31. type = "tool",
  32. description = "## Lode " .. name,
  33. inventory_image = modname .. "_tool_handle.png^(" ..
  34. modname .. "_#.png^[mask:" ..
  35. modname .. "_tool_" .. n .. ".png)",
  36. stack_max = 1,
  37. tool_capabilities = toolcap(4),
  38. bytemper = function(t, d)
  39. if t.name == "tempered" then
  40. d.tool_capabilities = toolcap(5)
  41. end
  42. d.skip_register = (t.name == "hot") or nil
  43. end,
  44. groups = {flammable = 4},
  45. metal_alt_hot = modname .. ":prill_hot " .. prills,
  46. tool_wears_to = prills > 1 and (modname .. ":prill_# " .. (prills - 1)) or nil,
  47. on_ignite = modname .. ":prill_# " .. prills
  48. })
  49. for _, t in pairs({"annealed", "tempered"}) do
  50. nodecore.register_craft({
  51. label = "assemble lode " .. n,
  52. normal = {y = 1},
  53. indexkeys = {modname .. ":toolhead_" .. n .. "_" .. t},
  54. nodes = {
  55. {match = modname .. ":toolhead_" .. n .. "_" .. t,
  56. replace = "air"},
  57. {y = -1, match = "nc_woodwork:staff", replace = "air"},
  58. },
  59. items = {
  60. {y = -1, name = modname .. ":tool_" .. n .. "_" .. t},
  61. }
  62. })
  63. end
  64. end
  65. toolhead("Mallet", "thumpy", 3)
  66. toolhead("Spade", "crumbly", 2)
  67. toolhead("Hatchet", "choppy", 2)
  68. toolhead("Pick", "cracky", 1)
  69. local function forgecore(from, fromqty, to, prills, fromtemper, anviltemper)
  70. return nodecore.register_craft({
  71. label = anviltemper .. " anvil making " .. fromtemper .. " lode " .. (to or "prills"),
  72. action = "pummel",
  73. toolgroups = {thumpy = 3},
  74. indexkeys = {modname .. ":" .. from .. "_" .. fromtemper},
  75. nodes = {
  76. {
  77. match = {name = modname .. ":" .. from .. "_" .. fromtemper,
  78. count = fromqty},
  79. replace = "air"
  80. },
  81. {
  82. y = -1,
  83. match = modname .. ":block_" .. anviltemper
  84. }
  85. },
  86. items = {
  87. to and (modname .. ":" .. to .. "_" .. fromtemper) or nil,
  88. prills and {name = modname .. ":prill_" .. fromtemper, count = prills,
  89. scatter = 5} or nil
  90. }
  91. })
  92. end
  93. local function forge(from, fromqty, to, prills)
  94. forgecore(from, fromqty, to, prills, "hot", "annealed")
  95. forgecore(from, fromqty, to, prills, "hot", "tempered")
  96. return forgecore(from, fromqty, to, prills, "annealed", "tempered")
  97. end
  98. forge("prill", 3, "toolhead_mallet")
  99. forge("toolhead_mallet", nil, "toolhead_spade", 1)
  100. forge("toolhead_spade", nil, "toolhead_hatchet")
  101. forge("toolhead_hatchet", nil, "toolhead_pick", 1)
  102. forge("toolhead_pick", nil, nil, 1)
  103. toolhead("Mattock", {"cracky", "crumbly"}, 3)
  104. local function mattock(a, b)
  105. return nodecore.register_craft({
  106. label = "assemble lode mattock head",
  107. action = "pummel",
  108. toolgroups = {thumpy = 3},
  109. normal = {y = 1},
  110. indexkeys = {modname .. (a == 0 and ":toolhead_pick_hot" or ":toolhead_spade_hot")},
  111. nodes = {
  112. {
  113. y = a,
  114. match = modname .. ":toolhead_pick_hot",
  115. replace = "air"
  116. },
  117. {
  118. y = b,
  119. match = modname .. ":toolhead_spade_hot",
  120. replace = "air"
  121. }
  122. },
  123. items = {
  124. modname .. ":toolhead_mattock_hot"
  125. }
  126. })
  127. end
  128. mattock(0, -1)
  129. mattock(-1, 0)