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