Fix torches not being craftable
[MineClone.git] / mods / item_drop / init.lua
blob7013b9d8e1033945dd0d4df3be66a73d10c0abb7
1 minetest.register_globalstep(function(dtime)
2 for _,player in ipairs(minetest.get_connected_players()) do
3 if player:get_hp() > 0 or not minetest.setting_getbool("enable_damage") then
4 local pos = player:getpos()
5 pos.y = pos.y+0.5
6 local inv = player:get_inventory()
7 local ctrl = player:get_player_control()
8 if ctrl.up or ctrl.left or ctrl.right then
10 for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
11 local en = object:get_luaentity()
12 if not object:is_player() and en and en.name == "__builtin:item" then
13 if inv and
14 inv:room_for_item("main", ItemStack(en.itemstring)) then
15 inv:add_item("main", ItemStack(en.itemstring))
16 if en.itemstring ~= "" then
17 minetest.sound_play("item_drop_pickup", {
18 to_player = player:get_player_name(),
19 gain = 0.4,
21 end
22 en.itemstring = ""
23 object:remove()
24 end
25 end
26 end
28 end
29 end
30 end
31 end)
33 function minetest.handle_node_drops(pos, drops, digger)
34 local inv
35 if minetest.setting_getbool("creative_mode") and digger and digger:is_player() then
36 inv = digger:get_inventory()
37 end
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 if not inv or not inv:contains_item("main", ItemStack(name)) then
48 for i=1,count do
49 local obj = minetest.env:add_item(pos, name)
50 if obj ~= nil then
51 obj:get_luaentity().collect = true
52 local x = math.random(1, 5)
53 if math.random(1,2) == 1 then
54 x = -x
55 end
56 local z = math.random(1, 5)
57 if math.random(1,2) == 1 then
58 z = -z
59 end
60 obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
62 -- FIXME this doesnt work for deactiveted objects
63 if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
64 minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
65 obj:remove()
66 end, obj)
67 end
68 end
69 end
70 end
71 end
72 end