stylus.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local ItemStack, minetest, nodecore, pairs
  3. = ItemStack, minetest, nodecore, pairs
  4. -- LUALOCALS > ---------------------------------------------------------
  5. local modname = minetest.get_current_modname()
  6. minetest.register_tool(modname .. ":stylus", {
  7. description = "Stone-Tipped Stylus",
  8. tool_wears_to = "nc_tree:stick",
  9. inventory_image = modname .. "_tool_stylus.png",
  10. groups = {
  11. flammable = 2
  12. },
  13. tool_capabilities = nodecore.toolcaps({
  14. scratchy = 3
  15. }),
  16. on_ignite = "nc_stonework:chip",
  17. sounds = nodecore.sounds("nc_terrain_stony"),
  18. on_stack_touchtip = function(stack, desc)
  19. local patt = stack:get_meta():get_string("pattern")
  20. if not patt then return desc end
  21. for _, def in pairs(nodecore.registered_concrete_patterns) do
  22. if patt == def.name and def.description then
  23. return desc .. "\n" .. def.description
  24. end
  25. end
  26. return desc
  27. end
  28. })
  29. for _, patt in pairs(nodecore.registered_concrete_patterns) do
  30. nodecore.translate_inform(patt.description)
  31. end
  32. nodecore.register_craft({
  33. label = "assemble stylus",
  34. normal = {y = 1},
  35. indexkeys = {"nc_stonework:chip"},
  36. nodes = {
  37. {match = "nc_stonework:chip", replace = "air"},
  38. {y = -1, match = "nc_tree:stick", replace = "air"},
  39. },
  40. after = function(pos)
  41. pos.y = pos.y - 1
  42. local item = ItemStack(modname .. ":stylus")
  43. item:get_meta():set_string("pattern",
  44. nodecore.pickrand(nodecore.registered_concrete_patterns).name)
  45. return nodecore.item_eject(pos, item)
  46. end
  47. })
  48. local function getdefs(node)
  49. local def = minetest.registered_items[node.name] or {}
  50. return def.pattern_def, def.etch_def
  51. end
  52. nodecore.register_craft({
  53. label = "stylus etch",
  54. action = "pummel",
  55. toolgroups = {scratchy = 1},
  56. indexkeys = {"group:concrete_etchable"},
  57. nodes = {
  58. {
  59. match = {groups = {concrete_etchable = true}}
  60. }
  61. },
  62. after = function(pos, data)
  63. local pattdef, etchdef = getdefs(minetest.get_node(pos))
  64. if not (pattdef and etchdef) then return end
  65. local setpref = modname .. ":" .. etchdef.name .. "_"
  66. local wieldpatt = data.wield and data.wield:get_meta():get_string("pattern")
  67. if wieldpatt and wieldpatt ~= "" and wieldpatt ~= pattdef.name then
  68. nodecore.set_loud(pos, {name = setpref .. wieldpatt .. "_ply"})
  69. return
  70. end
  71. local nxpatt = pattdef.next.name
  72. nodecore.set_loud(pos, {name = setpref .. nxpatt .. "_ply"})
  73. if data.wield and data.crafter then
  74. nodecore.player_discover(data.crafter, "stylus train")
  75. data.wield:get_meta():set_string("pattern", nxpatt)
  76. data.crafter:set_wielded_item(data.wield)
  77. end
  78. end
  79. })
  80. nodecore.register_soaking_abm({
  81. label = "pliable concrete cure",
  82. interval = 1,
  83. chance = 1,
  84. limited_max = 100,
  85. nodenames = {"group:concrete_etchable"},
  86. fieldname = "plycuring",
  87. soakrate = function(pos)
  88. if minetest.find_node_near(pos,
  89. 1, {"group:concrete_flow", "group:water"}) then
  90. return false
  91. end
  92. local found = nodecore.find_nodes_around(pos, "group:igniter", 1)
  93. return #found + 1
  94. end,
  95. soakcheck = function(data, pos)
  96. if data.total < 100 then
  97. nodecore.smokefx(pos, 1, data.rate)
  98. return
  99. end
  100. local pattdef, etchdef = getdefs(minetest.get_node(pos))
  101. if not (pattdef and etchdef) then return end
  102. local curename = modname .. ":" .. etchdef.name .. "_" .. pattdef.name
  103. if pattdef.blank then curename = etchdef.basename end
  104. nodecore.witness(pos, "cure pliant concrete")
  105. nodecore.set_loud(pos, {name = curename})
  106. return false
  107. end
  108. })