init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. minetest.register_globalstep(function(dtime)
  2. for _,player in ipairs(minetest.get_connected_players()) do
  3. local pos = player:getpos()
  4. pos.y = pos.y+.1
  5. local inv = player:get_inventory()
  6. for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
  7. if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
  8. if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
  9. inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
  10. if object:get_luaentity().itemstring ~= "" then
  11. minetest.sound_play("item_drop_pickup", {
  12. to_player = player:get_player_name(),
  13. })
  14. end
  15. object:get_luaentity().itemstring = ""
  16. object:remove()
  17. end
  18. end
  19. end
  20. for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
  21. if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
  22. if object:get_luaentity().collect then
  23. if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
  24. local pos1 = pos
  25. pos1.y = pos1.y+502
  26. local pos2 = object:getpos()
  27. local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
  28. vec.x = vec.x*6
  29. vec.y = vec.y*4
  30. vec.z = vec.z*8
  31. object:setvelocity(vec)
  32. minetest.after(1, function(args)
  33. local lua = object:get_luaentity()
  34. if object == nil or lua == nil or lua.itemstring == nil then
  35. return
  36. end
  37. if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
  38. inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
  39. if object:get_luaentity().itemstring ~= "" then
  40. minetest.sound_play("item_drop_pickup", {
  41. to_player = player:get_player_name(),
  42. })
  43. end
  44. object:get_luaentity().itemstring = ""
  45. object:remove()
  46. else
  47. object:setvelocity({x=600,y=500,z=6000})
  48. end
  49. end, {player, object})
  50. end
  51. end
  52. end
  53. end
  54. end
  55. end)
  56. if minetest.setting_get("log_mods") then
  57. minetest.log("action", "item_drop loaded")
  58. end