2017-05-19 23:04:11 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Item drop mod
|
|
|
|
-- By PilzAdam
|
|
|
|
-- Tweaked by Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
2019-08-29 23:03:59 +02:00
|
|
|
local nav_mod = minetest.get_modpath("nav") ~= nil
|
|
|
|
|
2017-07-02 22:28:17 +02:00
|
|
|
item_drop = {}
|
|
|
|
|
|
|
|
function item_drop.drop_item(pos, itemstack)
|
|
|
|
local rpos = {
|
|
|
|
x = pos.x + math.random(-0.3, 0.3),
|
|
|
|
y = pos.y,
|
|
|
|
z = pos.z + math.random(-0.3, 0.3)
|
|
|
|
}
|
|
|
|
|
|
|
|
local drop = minetest.add_item(rpos, itemstack)
|
|
|
|
|
|
|
|
if drop ~= nil then
|
|
|
|
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
|
|
|
|
|
2020-12-06 01:53:56 +01:00
|
|
|
local vel = drop:get_velocity()
|
|
|
|
if not vel then
|
|
|
|
vel = {x=0, y=0, z=0}
|
|
|
|
end
|
|
|
|
vel.x = 1 / x
|
|
|
|
vel.z = 1 / z
|
|
|
|
drop:set_velocity(vel)
|
2017-07-02 22:28:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local function valid(object)
|
|
|
|
return object:get_luaentity().timer ~= nil and object:get_luaentity().timer > 1
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_globalstep(
|
2015-09-01 17:15:24 +02:00
|
|
|
function(dtime)
|
2017-05-12 04:29:55 +02:00
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
2017-06-27 21:13:30 +02:00
|
|
|
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
|
2019-03-20 15:04:20 +01:00
|
|
|
local pos = player:get_pos()
|
2015-09-01 17:15:24 +02:00
|
|
|
local inv = player:get_inventory()
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
local in_radius = minetest.get_objects_inside_radius(pos, 6.0)
|
|
|
|
|
|
|
|
for _,object in ipairs(in_radius) do
|
|
|
|
if not object:is_player() and object:get_luaentity()
|
|
|
|
and object:get_luaentity().name == "__builtin:item" and valid(object) then
|
2019-09-15 10:48:27 +02:00
|
|
|
local pos1 = table.copy(pos)
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
pos1.y = pos1.y + 0.2
|
|
|
|
|
2019-03-20 15:04:20 +01:00
|
|
|
local pos2 = object:get_pos()
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
local vec = {
|
|
|
|
x = pos1.x - pos2.x,
|
|
|
|
y = pos1.y - pos2.y,
|
|
|
|
z = pos1.z - pos2.z
|
|
|
|
}
|
|
|
|
|
|
|
|
local len = vector.length(vec)
|
|
|
|
|
|
|
|
if len < 1.35 then
|
|
|
|
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
|
|
if len > 0.5 then
|
|
|
|
vec = vector.divide(vec, len) -- It's a normalize but we have len yet (vector.normalize(vec))
|
|
|
|
|
|
|
|
vec.x = vec.x*3
|
|
|
|
vec.y = vec.y*3
|
|
|
|
vec.z = vec.z*3
|
|
|
|
|
2019-09-15 10:48:27 +02:00
|
|
|
object:get_luaentity().item_magnet = true
|
2019-03-20 15:04:20 +01:00
|
|
|
object:set_velocity(vec)
|
2019-09-15 10:48:27 +02:00
|
|
|
object:set_properties({ physical = false })
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
else
|
|
|
|
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(lua.itemstring)) then
|
2019-08-31 00:20:23 +02:00
|
|
|
if minetest.settings:get_bool("creative_mode") then
|
|
|
|
if not inv:contains_item("main", ItemStack(lua.itemstring), true) then
|
|
|
|
inv:add_item("main", ItemStack(lua.itemstring))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inv:add_item("main", ItemStack(lua.itemstring))
|
|
|
|
end
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
if lua.itemstring ~= "" then
|
|
|
|
minetest.sound_play(
|
|
|
|
"item_drop_pickup",
|
|
|
|
{
|
|
|
|
pos = pos,
|
|
|
|
gain = 0.3,
|
|
|
|
max_hear_distance = 16
|
2020-04-07 01:00:55 +02:00
|
|
|
}, true)
|
2017-05-19 23:04:11 +02:00
|
|
|
end
|
2019-08-29 23:03:59 +02:00
|
|
|
-- Notify nav mod of inventory change
|
|
|
|
if nav_mod and lua.itemstring == "nav:map" then
|
|
|
|
nav.map.update_hud_flags(player)
|
|
|
|
end
|
2017-05-19 23:04:11 +02:00
|
|
|
|
|
|
|
lua.itemstring = ""
|
|
|
|
object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2019-03-20 15:04:20 +01:00
|
|
|
object:set_velocity({x = 0, y = object:get_velocity().y, z = 0})
|
2019-09-15 10:48:27 +02:00
|
|
|
object:get_luaentity().item_magnet = false
|
2017-05-19 23:04:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
2017-05-19 23:04:11 +02:00
|
|
|
end)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
function minetest.handle_node_drops(pos, drops, digger)
|
2019-08-31 00:20:23 +02:00
|
|
|
if minetest.settings:get_bool("creative_mode") then
|
|
|
|
if not digger or not digger:is_player() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local inv = digger:get_inventory()
|
|
|
|
if inv then
|
|
|
|
for _,item in ipairs(drops) do
|
|
|
|
if not inv:contains_item("main", item, true) then
|
|
|
|
inv:add_item("main", item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
for _,item in ipairs(drops) do
|
2020-04-21 19:25:45 +02:00
|
|
|
local obj = minetest.add_item(pos, item)
|
|
|
|
if obj ~= nil then
|
|
|
|
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:set_velocity({x=1/x, y=obj:get_velocity().y, z=1/z})
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-16 21:44:43 +02:00
|
|
|
default.log("mod:item_drop", "loaded")
|