2017-07-09 17:33:22 +02:00
|
|
|
local pickup = minetest.settings:get_bool("enable_item_pickup")
|
2017-07-09 18:38:44 +02:00
|
|
|
local drop = minetest.settings:get_bool("enable_item_drop")
|
2017-07-09 17:33:22 +02:00
|
|
|
local key = minetest.settings:get_bool("enable_item_pickup_key")
|
|
|
|
local keytype = minetest.settings:get("item_pickup_keytype") or "Use"
|
|
|
|
local gain = tonumber(minetest.settings:get("item_pickup_gain")) or 0.4
|
2017-06-26 15:57:23 +02:00
|
|
|
|
2017-07-09 17:33:22 +02:00
|
|
|
if pickup == nil then pickup = true end
|
2017-07-09 18:38:44 +02:00
|
|
|
if drop == nil then drop = true end
|
2017-07-09 17:33:22 +02:00
|
|
|
if key == nil then key = true end
|
2017-06-26 15:15:48 +02:00
|
|
|
|
2017-07-09 17:33:22 +02:00
|
|
|
local key_press = false
|
|
|
|
|
|
|
|
if pickup then
|
2017-06-26 15:24:56 +02:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
2017-07-11 23:29:18 +02:00
|
|
|
local ctrl = player:get_player_control()
|
2017-07-09 17:33:22 +02:00
|
|
|
if keytype == "Sneak" then
|
2017-07-11 23:29:18 +02:00
|
|
|
key_press = ctrl.sneak
|
2017-07-09 17:33:22 +02:00
|
|
|
elseif keytype == "LeftAndRight" then
|
2017-07-11 23:29:18 +02:00
|
|
|
key_press = ctrl.left and ctrl.right
|
2017-06-26 15:57:23 +02:00
|
|
|
else
|
2017-07-11 23:29:18 +02:00
|
|
|
key_press = ctrl.aux1
|
2017-06-26 15:57:23 +02:00
|
|
|
end
|
2017-07-09 17:33:22 +02:00
|
|
|
if key_press or not key then
|
2017-06-26 15:57:23 +02:00
|
|
|
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
|
|
|
|
local pos = player:getpos()
|
|
|
|
pos.y = pos.y+0.5
|
|
|
|
local inv = player:get_inventory()
|
2017-06-26 15:24:56 +02:00
|
|
|
|
2017-06-26 15:57:23 +02:00
|
|
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) 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(),
|
2017-07-09 17:33:22 +02:00
|
|
|
gain = gain,
|
2017-06-26 15:57:23 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
object:get_luaentity().itemstring = ""
|
|
|
|
object:remove()
|
2017-06-26 15:24:56 +02:00
|
|
|
end
|
2013-03-10 17:58:04 +01:00
|
|
|
end
|
2012-09-01 03:49:44 +02:00
|
|
|
end
|
2017-06-26 15:15:48 +02:00
|
|
|
|
2017-06-26 15:57:23 +02:00
|
|
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
|
|
|
|
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
|
|
|
if object:get_luaentity().collect then
|
|
|
|
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
|
|
local pos1 = pos
|
|
|
|
pos1.y = pos1.y+0.2
|
|
|
|
local pos2 = object:getpos()
|
|
|
|
local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
|
|
|
|
vec.x = vec.x*3
|
|
|
|
vec.y = vec.y*3
|
|
|
|
vec.z = vec.z*3
|
|
|
|
object:setvelocity(vec)
|
|
|
|
object:get_luaentity().physical_state = false
|
|
|
|
object:get_luaentity().object:set_properties({
|
|
|
|
physical = false
|
|
|
|
})
|
2017-06-26 15:15:48 +02:00
|
|
|
|
2017-06-26 15:57:23 +02:00
|
|
|
minetest.after(1, function(args)
|
|
|
|
local lua = object:get_luaentity()
|
|
|
|
if object == nil or lua == nil or lua.itemstring == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if 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(),
|
2017-07-09 17:33:22 +02:00
|
|
|
gain = gain,
|
2017-06-26 15:57:23 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
object:get_luaentity().itemstring = ""
|
|
|
|
object:remove()
|
|
|
|
else
|
|
|
|
object:setvelocity({x=0,y=0,z=0})
|
|
|
|
object:get_luaentity().physical_state = true
|
|
|
|
object:get_luaentity().object:set_properties({
|
|
|
|
physical = true
|
2017-06-26 15:24:56 +02:00
|
|
|
})
|
|
|
|
end
|
2017-06-26 15:57:23 +02:00
|
|
|
end, {player, object})
|
2017-06-26 15:15:48 +02:00
|
|
|
|
2017-06-26 15:57:23 +02:00
|
|
|
end
|
2017-06-26 15:24:56 +02:00
|
|
|
end
|
2013-03-10 17:58:04 +01:00
|
|
|
end
|
2012-09-01 00:52:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-26 15:57:23 +02:00
|
|
|
end)
|
|
|
|
end
|
2012-09-01 03:49:44 +02:00
|
|
|
|
2017-07-09 18:38:44 +02:00
|
|
|
if drop then
|
2017-06-26 15:24:56 +02:00
|
|
|
function minetest.handle_node_drops(pos, drops, digger)
|
|
|
|
local inv
|
|
|
|
if minetest.settings:get_bool("creative_mode") and digger and digger:is_player() then
|
|
|
|
inv = digger:get_inventory()
|
2012-09-03 18:52:59 +02:00
|
|
|
end
|
2017-06-26 15:24:56 +02:00
|
|
|
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})
|
2013-03-10 18:02:57 +01:00
|
|
|
end
|
2012-09-14 17:00:20 +02:00
|
|
|
end
|
2012-09-01 00:52:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-03 18:52:59 +02:00
|
|
|
end
|
2012-10-07 19:44:16 +02:00
|
|
|
|
2017-06-26 15:15:48 +02:00
|
|
|
if minetest.settings:get("log_mods") then
|
2012-10-07 19:44:16 +02:00
|
|
|
minetest.log("action", "item_drop loaded")
|
|
|
|
end
|