toiling_table.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. local modname = minetest.get_current_modname()
  2. local S = minetest.get_translator(modname)
  3. crafting.register_type("toil")
  4. --context tables are used for remembering which page a player is on
  5. local contexts = {}
  6. minetest.register_on_joinplayer(function(player)
  7. contexts[player:get_player_name()] = {}
  8. end)
  9. minetest.register_on_leaveplayer(function(player)
  10. contexts[player:get_player_name()] = nil
  11. end)
  12. local base_formspec =
  13. {
  14. "formspec_version[1]",
  15. "size[8.1,9]",
  16. "label[0.1,0.1;",
  17. S("Toiling Table"),
  18. "]",
  19. "list[current_player;main;0,5.3;8,4]",
  20. "container[0, 0.7]",
  21. }
  22. base_formspec =
  23. {
  24. table.concat(base_formspec),
  25. nil,
  26. "container_end[]",
  27. }
  28. local result_selector_pos = #base_formspec - 1
  29. local function show_formspec(player, context)
  30. context = contexts[player:get_player_name()]
  31. base_formspec[2] =
  32. crafting.make_result_selector(player, "toil", 1, {x = 8, y = 3}, context)
  33. local formspec = table.concat(base_formspec)
  34. minetest.show_formspec(player:get_player_name(), "toiling_table", formspec)
  35. end
  36. minetest.register_on_player_receive_fields(function(player, formname, fields)
  37. if formname ~= "toiling_table"
  38. then
  39. return
  40. end
  41. local context = contexts[player:get_player_name()]
  42. if crafting.result_select_on_receive_results(player, "toil", 1, context, fields)
  43. then
  44. show_formspec(player, context)
  45. end
  46. return true
  47. end)
  48. minetest.register_node(modname .. ":toiling_table",
  49. {
  50. description = S("Toiling Table"),
  51. drawtype = "mesh",
  52. mesh = modname .. "_toiling_table.obj",
  53. tiles = {"eg_trees_wood_sides.png", "eg_trees_wood_slice.png"},
  54. groups = {deconstructable = 3},
  55. is_ground_content = false,
  56. on_rightclick = function(pos, node, clicker)
  57. show_formspec(clicker)
  58. end,
  59. sounds =
  60. {
  61. dig = "wood_high_dig",
  62. dug = "wood_low_dug",
  63. place = "wood_low_place",
  64. footstep = "wood_low_footstep",
  65. }
  66. })
  67. minetest.register_craft(
  68. {
  69. type = "shapeless",
  70. output = modname .. ":toiling_table",
  71. recipe = {"eg_trees:wood"},
  72. })
  73. crafting.register_recipe(
  74. {
  75. type = "toil",
  76. output = "eg_storage_barrels:barrel",
  77. items = {"eg_trees:wood 4"},
  78. always_known = true,
  79. })
  80. crafting.register_recipe(
  81. {
  82. type = "toil",
  83. output = "eg_woodstuffs:planks 4",
  84. items = {"eg_trees:wood"},
  85. always_known = true,
  86. })