improve collection in item drop, remove max stack

This commit is contained in:
cornernote 2012-08-19 20:16:21 +09:30
parent 1727f5a786
commit 1cb13d68a8

View File

@ -23,6 +23,7 @@ function item_drop(pos, oldnode, digger)
return return
else else
if string.find(oldnode.name, " ") ~= nil then if string.find(oldnode.name, " ") ~= nil then
oldnode.name = oldnode.name:gsub('"',""):gsub("craft ",""):gsub("item ",""):gsub("node ","")
anzahl = string.sub(oldnode.name, string.find(oldnode.name, " ")+1, string.len(oldnode.name)) anzahl = string.sub(oldnode.name, string.find(oldnode.name, " ")+1, string.len(oldnode.name))
oldnode.name = string.sub(oldnode.name, 1, string.find(oldnode.name, " ")-1) oldnode.name = string.sub(oldnode.name, 1, string.find(oldnode.name, " ")-1)
end end
@ -32,16 +33,18 @@ function item_drop(pos, oldnode, digger)
digger:get_inventory():remove_item("main", ItemStack(oldnode.name)) digger:get_inventory():remove_item("main", ItemStack(oldnode.name))
end end
local item = minetest.env:add_item(pos, oldnode) local item = minetest.env:add_item(pos, oldnode)
item:get_luaentity().collect = true if item ~= nil and item:get_luaentity()~=nil then
local x = math.random(1, 5) item:get_luaentity().collect = true
if math.random(1,2) == 1 then local x = math.random(1, 5)
x = -x 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
item:setvelocity({x=1/x, y=item:getvelocity().y, z=1/z})
end end
local z = math.random(1, 5)
if math.random(1,2) == 1 then
z = -z
end
item:setvelocity({x=1/x, y=item:getvelocity().y, z=1/z})
end end
end end
@ -87,10 +90,15 @@ minetest.register_globalstep(function(dtime)
end end
for i,item in ipairs(item_timer) do for i,item in ipairs(item_timer) do
item:get_luaentity().timer = item:get_luaentity().timer + dtime if item ~= nil and item:get_luaentity() ~= nil then
if item:get_luaentity().timer > 1 then if item:get_luaentity().timer == nil then
item:get_luaentity().collect = true item:get_luaentity().timer = 0
table.remove(item_timer, i) end
item:get_luaentity().timer = item:get_luaentity().timer + dtime
if item:get_luaentity().timer > 1 then
item:get_luaentity().collect = true
table.remove(item_timer, i)
end
end end
end end
end) end)
@ -124,7 +132,7 @@ minetest.after(0, function()
local new_node = { local new_node = {
after_dig_node = func, after_dig_node = func,
stack_max = 64, --stack_max = 64,
} }
for str,val in pairs(node) do for str,val in pairs(node) do
new_node[str] = val new_node[str] = val