Drop items out of the crafting inventory when the crafting tab loses focus

This commit is contained in:
KaadmY 2017-07-02 13:28:17 -07:00
parent f7498130ee
commit 219d544e9c
4 changed files with 54 additions and 22 deletions

View File

@ -327,14 +327,39 @@ function crafting.get_formspec(name)
end
local function on_player_receive_fields(player, form_name, fields)
local inv = player:get_inventory()
if fields.quit then
local pos = player:getpos()
for i = 1, inv:get_size("craft_in") do
local itemstack = inv:get_stack("craft_in", i)
item_drop.drop_item(pos, itemstack)
itemstack:clear()
inv:set_stack("craft_in", i, itemstack)
end
for i = 1, inv:get_size("craft_out") do
local itemstack = inv:get_stack("craft_out", i)
item_drop.drop_item(pos, itemstack)
itemstack:clear()
inv:set_stack("craft_out", i, itemstack)
end
end
if fields.crafting_tracker == nil then
return
end
local name = player:get_player_name()
local inv = player:get_inventory()
if fields.do_craft_1 or fields.do_craft_10 then
local craftitems = crafting.get_crafts(nil)

View File

@ -1 +1,2 @@
default
item_drop

View File

@ -22,26 +22,7 @@ local function on_die(player)
for i = 1, inv:get_size(listname) do
local item = inv:get_stack(listname, i)
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, item)
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
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
end
item_drop.drop_item(pos, item)
item:clear()

View File

@ -5,6 +5,31 @@
-- Tweaked by Kaadmy, for Pixture
--
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
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
end
end
local function valid(object)
return object:get_luaentity().timer ~= nil and object:get_luaentity().timer > 1
end