init.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. trash = trash or {}
  2. trash.modpath = minetest.get_modpath("trash")
  3. function trash.get_listname()
  4. return "detached:trash", "main"
  5. end
  6. function trash.get_iconname()
  7. return "trash_trash_icon.png"
  8. end
  9. function trash.allow_put(inv, listname, index, stack, player)
  10. if passport.is_passport(stack:get_name()) then
  11. return 0
  12. end
  13. -- Don't allow minegeld to be trashed.
  14. if minetest.get_item_group(stack:get_name(), "minegeld") ~= 0 then
  15. return 0
  16. end
  17. return stack:get_count()
  18. end
  19. function trash.on_put(inv, to_list, to_index, stack, player)
  20. local stack = inv:get_stack(to_list, to_index)
  21. inv:set_stack(to_list, to_index, ItemStack(nil))
  22. if player and player:is_player() then
  23. local pos = player:get_pos()
  24. -- Play a trash sound. Let other players hear it.
  25. minetest.sound_play("trash_trash", {
  26. gain=1.0,
  27. pos=pos,
  28. max_hear_distance=16,
  29. })
  30. minetest.log("action", player:get_player_name() .. " trashes " ..
  31. "\"" .. stack:get_name() .. " " .. stack:get_count() .. "\"" ..
  32. " using inventory trash slot.")
  33. end
  34. end
  35. if not trash.registered then
  36. local inv = minetest.create_detached_inventory("trash", {
  37. allow_put = function(...)
  38. return trash.allow_put(...)
  39. end,
  40. on_put = function(...)
  41. return trash.on_put(...)
  42. end,
  43. })
  44. inv:set_size("main", 1)
  45. local c = "trash:core"
  46. local f = trash.modpath .. "/init.lua"
  47. reload.register_file(c, f, false)
  48. trash.registered = true
  49. end