init.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. local stack_count = stack:get_count()
  18. -- Do not allow trashing of tools that have gained rank.
  19. if toolranks.get_tool_level(stack) > 1 then
  20. return 0
  21. end
  22. -- Do not allow trashing of items with engraved names.
  23. if engraver.item_has_custom_description(stack) then
  24. return 0
  25. end
  26. return stack_count
  27. end
  28. function trash.on_put(inv, to_list, to_index, stack, player)
  29. local stack = inv:get_stack(to_list, to_index)
  30. inv:set_stack(to_list, to_index, ItemStack(nil))
  31. if player and player:is_player() then
  32. local pos = player:get_pos()
  33. -- Play a trash sound. Let other players hear it.
  34. minetest.sound_play("trash_trash", {
  35. gain=1.0,
  36. pos=pos,
  37. max_hear_distance=16,
  38. }, true)
  39. minetest.log("action", player:get_player_name() .. " trashes " ..
  40. "\"" .. stack:get_name() .. " " .. stack:get_count() .. "\"" ..
  41. " using inventory trash slot.")
  42. end
  43. end
  44. if not trash.registered then
  45. local inv = minetest.create_detached_inventory("trash", {
  46. allow_put = function(...)
  47. return trash.allow_put(...)
  48. end,
  49. on_put = function(...)
  50. return trash.on_put(...)
  51. end,
  52. })
  53. inv:set_size("main", 1)
  54. local c = "trash:core"
  55. local f = trash.modpath .. "/init.lua"
  56. reload.register_file(c, f, false)
  57. trash.registered = true
  58. end