mirror of
https://github.com/minetest-mods/item_drop.git
synced 2025-01-03 11:37:36 +01:00
Code touch-up
This commit is contained in:
parent
363b56fc03
commit
5a6f79a5d2
29
init.lua
29
init.lua
@ -43,12 +43,18 @@ if pickup then
|
||||
pos.y = pos.y+0.5
|
||||
local inv = player:get_inventory()
|
||||
|
||||
for _,object in ipairs(minetest.get_objects_inside_radius(pos, pickup_radius)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
local objectlist = minetest.get_objects_inside_radius(pos, pickup_radius)
|
||||
for _,object in ipairs(objectlist) do
|
||||
if not object:is_player()
|
||||
and object:get_luaentity()
|
||||
and object:get_luaentity().name == "__builtin:item" then
|
||||
local pos2 = object:getpos()
|
||||
local distance = math.sqrt(((pos2.x - pos.x) * (pos2.x - pos.x)) + ((pos2.y - pos.y) * (pos2.y - pos.y))
|
||||
+ ((pos2.z - pos.z) * (pos2.z - pos.z)))
|
||||
if distance <= 1 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.chat_send_player(player:get_player_name(), "[ItemPickup] You picked up " .. object:get_luaentity().itemstring)
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
to_player = player:get_player_name(),
|
||||
gain = pickup_gain,
|
||||
@ -57,16 +63,11 @@ if pickup then
|
||||
object:get_luaentity().itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
else
|
||||
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
|
||||
@ -77,10 +78,11 @@ if pickup then
|
||||
physical = false
|
||||
})
|
||||
|
||||
minetest.after(1, function(args)
|
||||
minetest.after(1, function()
|
||||
local lua = object:get_luaentity()
|
||||
if object == nil or lua == nil or lua.itemstring == nil then return end
|
||||
|
||||
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
|
||||
@ -98,9 +100,8 @@ if pickup then
|
||||
physical = true
|
||||
})
|
||||
end
|
||||
|
||||
end, {player, object})
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user