-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
78 lines (73 loc) · 2.36 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local item_drop = false
if minetest.setting_getbool("nodes_drop_items") then
item_drop = true
end
minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
if player:get_hp() > 0 or not minetest.setting_getbool("enable_damage") then
local pos = player:getpos()
pos.y = pos.y + 0.5
local inv = player:get_inventory()
for _, object in ipairs(minetest.get_objects_inside_radius(pos, 0.667)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
if object:get_luaentity().itemstring ~= "" then
minetest.sound_play("item_drop_pickup", {
to_player = player:get_player_name(),
gain = 0.4,
})
end
object:get_luaentity().itemstring = ""
object:remove()
end
end
end
end
end
end)
if item_drop then
function minetest.handle_node_drops(pos, drops, digger)
local inv
if minetest.setting_getbool("creative_mode") and digger and digger:is_player() then
inv = digger:get_inventory()
end
for _, item in ipairs(drops) do
local count, name
if type(item) == "string" then
count = 1
name = item
else
count = item:get_count()
name = item:get_name()
end
if not inv or not inv:contains_item("main", ItemStack(name)) then
for i = 1, count do
local obj = minetest.add_item(pos, name)
if obj ~= nil then
obj:get_luaentity().collect = true
local x = math.random(1, 5)
if math.random(1, 2) == 1 then
x = -x
end
local z = math.random(1, 5)
if math.random(1, 2) == 1 then
z = -z
end
obj:setvelocity({x = 1/x, y = obj:getvelocity().y, z = 1/z})
-- FIXME this doesnt work for deactiveted objects
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
obj:remove()
end, obj)
end
end
end
end
end
end
end
if minetest.setting_get("log_mods") then
minetest.log("action", "[item_drop] Loaded.")
minetest.log("action", "[item_drop] Node drops items: " .. tostring(item_drop) .. ".")
end