mirror of
https://github.com/minetest-mods/item_drop.git
synced 2024-11-16 06:50:16 +01:00
Update item dropping code
This commit is contained in:
parent
4912d3c828
commit
729397b6c9
32
init.lua
32
init.lua
|
@ -204,19 +204,22 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false then
|
if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false then
|
||||||
|
local creative_enabled = minetest.settings:get_bool("creative_mode")
|
||||||
|
|
||||||
function minetest.handle_node_drops(pos, drops, digger)
|
function minetest.handle_node_drops(pos, drops, digger)
|
||||||
|
|
||||||
local inv
|
local inv
|
||||||
local diggerPos = pos
|
local diggerPos = pos
|
||||||
|
|
||||||
if minetest.settings:get_bool("creative_mode")
|
if creative_enabled
|
||||||
and digger
|
and digger
|
||||||
and digger:is_player() then
|
and digger:is_player() then
|
||||||
inv = digger:get_inventory()
|
inv = digger:get_inventory()
|
||||||
diggerPos = digger:getpos()
|
diggerPos = digger:getpos()
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,item in ipairs(drops) do
|
for i = 1,#drops do
|
||||||
|
local item = drops[i]
|
||||||
local count, name
|
local count, name
|
||||||
if type(item) == "string" then
|
if type(item) == "string" then
|
||||||
count = 1
|
count = 1
|
||||||
|
@ -226,20 +229,21 @@ if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false then
|
||||||
name = item:get_name()
|
name = item:get_name()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not inv or not inv:contains_item("main", ItemStack(name)) then
|
if not inv
|
||||||
for i=1,count do
|
or not inv:contains_item("main", ItemStack(name)) then
|
||||||
|
for _ = 1,count do
|
||||||
|
local obj = minetest.add_item(diggerPos, name)
|
||||||
|
|
||||||
local adjustedPos = {x=diggerPos.x, y=diggerPos.y,
|
if obj then
|
||||||
z=diggerPos.z}
|
|
||||||
local obj = minetest.add_item(adjustedPos, name)
|
|
||||||
|
|
||||||
if obj ~= nil then
|
|
||||||
obj:get_luaentity().collect = true
|
obj:get_luaentity().collect = true
|
||||||
local x = math.random(1, 5)
|
local x = math.random(-5, 4)
|
||||||
if math.random(1,2) == 1 then x = -x end
|
if x >= 0 then
|
||||||
|
x = x+1
|
||||||
local z = math.random(1, 5)
|
end
|
||||||
if math.random(1,2) == 1 then z = -z end
|
local z = math.random(-5, 4)
|
||||||
|
if z >= 0 then
|
||||||
|
z = z+1
|
||||||
|
end
|
||||||
|
|
||||||
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user