gardener_table.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. local modname = minetest.get_current_modname()
  2. local S = minetest.get_translator(modname)
  3. crafting.register_type("gardening")
  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("Gardening 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[result_selector_pos] =
  32. crafting.make_result_selector(player, "gardening", 1, {x = 8, y = 3}, context)
  33. local formspec = table.concat(base_formspec)
  34. minetest.show_formspec(player:get_player_name(), "gardener_table", formspec)
  35. end
  36. minetest.register_on_player_receive_fields(function(player, formname, fields)
  37. if formname ~= "gardener_table"
  38. then
  39. return
  40. end
  41. local context = contexts[player:get_player_name()]
  42. if crafting.result_select_on_receive_results(player, "gardening", 1, context, fields)
  43. then
  44. show_formspec(player, context)
  45. end
  46. return true
  47. end)
  48. minetest.register_node(modname .. ":gardener_table",
  49. {
  50. description = S("Gardening Table"),
  51. drawtype = "mesh",
  52. mesh = modname .. "_gardener_table.obj",
  53. tiles = {"eg_trees_wood_sides.png", "eg_trees_wood_slice.png", "eg_trees_leaves.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. crafting.register_recipe(
  68. {
  69. type = "toil",
  70. output = modname .. ":gardener_table",
  71. items = {"eg_trees:wood 2", "eg_trees:leaves"},
  72. level = 1,
  73. always_known = true,
  74. })
  75. crafting.register_recipe(
  76. {
  77. type = "gardening",
  78. output = "eg_trees:sapling",
  79. items = {"eg_trees:leaves 4"},
  80. level = 1,
  81. always_known = true,
  82. })
  83. crafting.register_recipe(
  84. {
  85. type = "gardening",
  86. output = "eg_mapgen:grass",
  87. items = {"eg_trees:leaves 4"},
  88. level = 1,
  89. always_known = true,
  90. })
  91. crafting.register_recipe(
  92. {
  93. type = "gardening",
  94. output = "eg_apples:plant",
  95. items = {"eg_trees:leaves 4", "eg_apples:appleapple"},
  96. level = 1,
  97. always_known = true,
  98. })