trash.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. -- internationalization boilerplate
  2. local MP = minetest.get_modpath(minetest.get_current_modname())
  3. local S, NS = dofile(MP.."/intllib.lua")
  4. local function get_trash_formspec(pos)
  5. local spos = hopper.get_string_pos(pos)
  6. local formspec =
  7. "size[8,7]"
  8. .. hopper.formspec_bg
  9. .. "list[nodemeta:" .. spos .. ";main;3,0.3;2,2;]"
  10. .. "list[current_player;main;0,2.85;8,1;]"
  11. .. "list[current_player;main;0,4.08;8,3;8]"
  12. .. "listring[nodemeta:" .. spos .. ";main]"
  13. .. "listring[current_player;main]"
  14. return formspec
  15. end
  16. minetest.register_node("hopper:trash", {
  17. description = S("Hopper trash"),
  18. _doc_items_longdesc = hopper.doc.chute_long_desc,
  19. _doc_items_usagehelp = hopper.doc.chute_usage,
  20. drop = "hopper:trash",
  21. groups = {cracky = 3},
  22. sounds = hopper.metal_sounds,
  23. drawtype = "nodebox",
  24. paramtype = "light",
  25. paramtype2 = "facedir",
  26. tiles = {
  27. "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_chute_arrow_" .. hopper.config.texture_resolution .. ".png^[colorize:red:60",
  28. "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^(hopper_chute_arrow_" .. hopper.config.texture_resolution .. ".png^[transformR180)^[colorize:red:60",
  29. "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^(hopper_chute_arrow_" .. hopper.config.texture_resolution .. ".png^[transformR270)^[colorize:red:60",
  30. "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^(hopper_chute_arrow_" .. hopper.config.texture_resolution .. ".png^[transformR90)^[colorize:red:60",
  31. "hopper_top_" .. hopper.config.texture_resolution .. ".png^[colorize:red:60",
  32. "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^[colorize:red:60"
  33. },
  34. use_texture_alpha = "clip",
  35. node_box = {
  36. type = "fixed",
  37. fixed = {
  38. {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
  39. {-0.2, -0.2, 0.3, 0.2, 0.2, 0.7},
  40. },
  41. },
  42. on_construct = function(pos)
  43. local inv = minetest.get_meta(pos):get_inventory()
  44. inv:set_size("main", 2*2)
  45. end,
  46. on_place = function(itemstack, placer, pointed_thing, node_name)
  47. local pos = pointed_thing.under
  48. local pos2 = pointed_thing.above
  49. if not placer then
  50. return itemstack
  51. end
  52. local pos = pointed_thing.above
  53. if minetest.is_protected(pos, placer:get_player_name()) then
  54. return itemstack
  55. end
  56. local returned_stack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
  57. if success then
  58. local meta = minetest.get_meta(pos2)
  59. meta:set_string("placer", placer:get_player_name())
  60. end
  61. return returned_stack
  62. end,
  63. can_dig = function(pos,player)
  64. local inv = minetest.get_meta(pos):get_inventory()
  65. return inv:is_empty("main")
  66. end,
  67. on_rightclick = function(pos, node, clicker, itemstack)
  68. if minetest.is_protected(pos, clicker:get_player_name()) and not minetest.check_player_privs(clicker, "protection_bypass") then
  69. return
  70. end
  71. minetest.show_formspec(clicker:get_player_name(),
  72. "hopper_formspec:"..minetest.pos_to_string(pos), get_trash_formspec(pos))
  73. end,
  74. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  75. return stack:get_count()
  76. end,
  77. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  78. minetest.log("action", S("@1 moves stuff to trash at @2",
  79. player:get_player_name(), minetest.pos_to_string(pos)))
  80. local timer = minetest.get_node_timer(pos)
  81. if not timer:is_started() then
  82. timer:start(1)
  83. end
  84. end,
  85. on_timer = function(pos, elapsed)
  86. local meta = minetest.get_meta(pos);
  87. local inv = meta:get_inventory()
  88. local node = minetest.get_node(pos)
  89. local dir = minetest.facedir_to_dir(node.param2)
  90. local destination_pos = vector.add(pos, dir)
  91. local output_direction
  92. if dir.y == 0 then
  93. output_direction = "horizontal"
  94. end
  95. for i = 1, inv:get_size("main") do
  96. local stack = inv:get_stack("main", i)
  97. stack:take_item(1)
  98. inv:set_stack("main", i, stack)
  99. end
  100. if not inv:is_empty("main") then
  101. minetest.get_node_timer(pos):start(1)
  102. end
  103. end,
  104. })