ShadowNinja
2013-07-17 ee0765804c0a21deeb2f33c22ac1a36cb0db5f43
commit | author | age
e139ff 1 dofile(minetest.get_modpath("item_drop").."/item_entity.lua")
R 2 time_pick = 3
3
ee0765 4 if technic.config:get_bool("enable_item_pickup") then
3a3700 5     minetest.register_globalstep(function(dtime)
R 6         for _,player in ipairs(minetest.get_connected_players()) do
7             if player and player:get_hp() > 0 then
ee0765 8                 local pos = player:getpos()
S 9                 pos.y = pos.y + 0.5
10                 local inv = player:get_inventory()
11                 for _, object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
12                     if not object:is_player() and object:get_luaentity() then
13                         local obj = object:get_luaentity()
14                         if obj.name == "__builtin:item" then
15                             if inv and inv:room_for_item("main", ItemStack(obj.itemstring)) then
16                                 if obj.timer > time_pick then
17                                     inv:add_item("main", ItemStack(obj.itemstring))
18                                     if obj.itemstring ~= "" then
19                                         minetest.sound_play("item_drop_pickup",
20                                             {pos = pos, gain = 1.0, max_hear_distance = 10}) 
21                                     end
22                                     if object:get_luaentity() then
23                                         object:get_luaentity().itemstring = ""
24                                         object:remove()
25                                     end
3a3700 26                                 end
R 27                             end
28                         end
29                     end
30                 end
31             end
e139ff 32         end
3a3700 33     end)
R 34 end
35
ee0765 36 if technic.config:get_bool("enable_item_drop") then
3a3700 37     function minetest.handle_node_drops(pos, drops, digger)
R 38         for _,item in ipairs(drops) do
39             local count, name
40             if type(item) == "string" then
41                 count = 1
42                 name = item
43             else
44                 count = item:get_count()
45                 name = item:get_name()
46             end
47             for i=1,count do
48                 local obj = minetest.env:add_item(pos, name)
49                 if obj ~= nil then
50                     obj:get_luaentity().collect = true
51                     local x = math.random(1, 5)
52                     if math.random(1,2) == 1 then
53                         x = -x
54                     end
55                     local z = math.random(1, 5)
56                     if math.random(1,2) == 1 then
57                         z = -z
58                     end
59                     obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
60                     obj:get_luaentity().timer = time_pick
61                     -- FIXME this doesnt work for deactiveted objects
62                     if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
63                         minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
64                             obj:remove()
65                         end, obj)
66                     end
e139ff 67                 end
R 68             end
69         end
70     end
71 end
3a3700 72
e139ff 73 --[[
R 74 minetest.register_on_dieplayer(function(name, pos)
75     local inv = name:get_inventory()
76     local pos = name:getpos()
77     for i = 1, inv:get_size("main"), 1 do
78         srcstack = inv:get_stack("main", i)
79         if srcstack:to_string() ~= "" then
80             pos.y = pos.y + 3
81             local obj = minetest.env:add_item(pos, srcstack:to_string())
82             local x = math.random(-5, 5)
83             if x >= -2 and x <=0 then
84                 local x = x - 3
85             end
86             if x > 0 and x <= 2 then
87                 local x = x + 3
88             end
89             local y = math.random(3, 5)
90             local z = math.random(-5, 5)
91             if z >= -2 and z <= 0 then
92                 local z = z - 3
93             end
94             if z > 0 and z <= 2 then
95                 local z = z + 3
96             end
97             inv:set_stack("main", i, "")
98             obj:setvelocity({x=x, y=y, z=z})
99         end
100         if i == 32 then
101             break
102         end
103     end
104 end)
105 ]]--
3a3700 106 print("DROPS LOADED!")