mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-16 07:20:41 +01:00
item pick-up overhaul
This commit is contained in:
parent
76c2d8132c
commit
1cbe991a57
|
@ -5,64 +5,21 @@ minetest.register_globalstep(function(dtime)
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
pos.y = pos.y+0.5
|
pos.y = pos.y+0.5
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
for _,object in ipairs(minetest.env: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 not object:is_player() and object:get_luaentity() then
|
||||||
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
local obj=object:get_luaentity()
|
||||||
if object:get_luaentity() and object:get_luaentity().timer > time_pick then
|
if obj.name == "__builtin:item" then
|
||||||
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
if inv:room_for_item("main", ItemStack(obj.itemstring)) then
|
||||||
if object:get_luaentity().itemstring ~= "" then
|
if obj.timer > time_pick then
|
||||||
minetest.sound_play("item_drop_pickup", {
|
inv:add_item("main", ItemStack(obj.itemstring))
|
||||||
to_player = player:get_player_name(),
|
if obj.itemstring ~= "" then
|
||||||
})
|
minetest.sound_play("item_drop_pickup")
|
||||||
end
|
end
|
||||||
object:get_luaentity().itemstring = ""
|
if object:get_luaentity() then
|
||||||
object:remove()
|
object:get_luaentity().itemstring = ""
|
||||||
end
|
object:remove()
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 3)) do
|
|
||||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
|
||||||
--print(dump(object:getpos().y-player:getpos().y))
|
|
||||||
if object:getpos().y-player:getpos().y > 0 then
|
|
||||||
if object:get_luaentity().collect then
|
|
||||||
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
||||||
if object:get_luaentity().timer > time_pick 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)
|
|
||||||
|
|
||||||
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(),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
object:get_luaentity().itemstring = ""
|
|
||||||
object:remove()
|
|
||||||
else
|
|
||||||
object:setvelocity({x=0,y=0,z=0})
|
|
||||||
end
|
|
||||||
end, {player, object})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
minetest.after(0.5, function(entity)
|
|
||||||
entity.collect = true
|
|
||||||
end, object:get_luaentity())
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user