Drop items out of the crafting inventory when the crafting tab loses focus
This commit is contained in:
parent
f7498130ee
commit
219d544e9c
@ -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)
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
default
|
||||
item_drop
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user