stations.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. -- Crafting Mod - semi-realistic crafting in minetest
  2. -- Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
  3. --
  4. -- This library is free software; you can redistribute it and/or
  5. -- modify it under the terms of the GNU Lesser General Public
  6. -- License as published by the Free Software Foundation; either
  7. -- version 2.1 of the License, or (at your option) any later version.
  8. --
  9. -- This library is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. -- Lesser General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU Lesser General Public
  15. -- License along with this library; if not, write to the Free Software
  16. -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. crafting.register_type("inv")
  18. crafting.register_type("furnace")
  19. if minetest.global_exists("sfinv") then
  20. local player_inv_hashes = {}
  21. local trash = minetest.create_detached_inventory("crafting_trash", {
  22. -- Allow the stack to be placed and remove it in on_put()
  23. -- This allows the creative inventory to restore the stack
  24. allow_put = function(inv, listname, index, stack, player)
  25. return stack:get_count()
  26. end,
  27. on_put = function(inv, listname)
  28. inv:set_list(listname, {})
  29. end,
  30. })
  31. trash:set_size("main", 1)
  32. sfinv.override_page("sfinv:crafting", {
  33. get = function(self, player, context)
  34. player_inv_hashes[player:get_player_name()] =
  35. crafting.calc_inventory_list_hash(player:get_inventory(), "main")
  36. local formspec = crafting.make_result_selector(player, "inv", 1, { x = 8, y = 3 }, context)
  37. formspec = formspec .. "list[detached:crafting_trash;main;0,3.4;1,1;]" ..
  38. "image[0.05,3.5;0.8,0.8;crafting_trash_icon.png]"
  39. return sfinv.make_formspec(player, context, formspec, true)
  40. end,
  41. on_player_receive_fields = function(self, player, context, fields)
  42. if crafting.result_select_on_receive_results(player, "inv", 1, context, fields) then
  43. sfinv.set_player_inventory_formspec(player)
  44. end
  45. return true
  46. end
  47. })
  48. local function check_for_changes()
  49. for _, player in pairs(minetest.get_connected_players() or {}) do
  50. if sfinv.get_or_create_context(player).page == "sfinv:crafting" then
  51. local hash = crafting.calc_inventory_list_hash(player:get_inventory(), "main")
  52. local old_hash = player_inv_hashes[player:get_player_name()]
  53. if hash ~= old_hash then
  54. sfinv.set_page(player, "sfinv:crafting")
  55. end
  56. end
  57. end
  58. minetest.after(1, check_for_changes)
  59. end
  60. check_for_changes()
  61. end
  62. minetest.register_node("crafting:work_bench", {
  63. description = "Work Bench",
  64. groups = { snappy = 1 },
  65. on_rightclick = crafting.make_on_rightclick("inv", 2, { x = 8, y = 3 }),
  66. })
  67. crafting.create_async_station("crafting:furnace", "furnace", 1, {
  68. description = "Furnace",
  69. tiles = {
  70. "crafting_furnace_top.png", "crafting_furnace_bottom.png",
  71. "crafting_furnace_side.png", "crafting_furnace_side.png",
  72. "crafting_furnace_side.png", "crafting_furnace_front.png"
  73. },
  74. paramtype2 = "facedir",
  75. groups = {cracky=2},
  76. legacy_facedir_simple = true,
  77. is_ground_content = false,
  78. }, {
  79. description = "Furnace (active)",
  80. tiles = {
  81. "crafting_furnace_top.png", "crafting_furnace_bottom.png",
  82. "crafting_furnace_side.png", "crafting_furnace_side.png",
  83. "crafting_furnace_side.png",
  84. {
  85. image = "crafting_furnace_front_active.png",
  86. backface_culling = false,
  87. animation = {
  88. type = "vertical_frames",
  89. aspect_w = 16,
  90. aspect_h = 16,
  91. length = 1.5
  92. },
  93. }
  94. },
  95. paramtype2 = "facedir",
  96. light_source = 8,
  97. drop = "crafting:furnace",
  98. groups = {cracky=2, not_in_creative_inventory=1},
  99. legacy_facedir_simple = true,
  100. is_ground_content = false,
  101. })