diff --git a/mods/crafting/api.lua b/mods/crafting/api.lua index d4c228f..2e80af1 100644 --- a/mods/crafting/api.lua +++ b/mods/crafting/api.lua @@ -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) diff --git a/mods/drop_items_on_die/depends.txt b/mods/drop_items_on_die/depends.txt index 4ad96d5..29bda9a 100644 --- a/mods/drop_items_on_die/depends.txt +++ b/mods/drop_items_on_die/depends.txt @@ -1 +1,2 @@ default +item_drop diff --git a/mods/drop_items_on_die/init.lua b/mods/drop_items_on_die/init.lua index 65c74d7..edfa323 100644 --- a/mods/drop_items_on_die/init.lua +++ b/mods/drop_items_on_die/init.lua @@ -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() diff --git a/mods/item_drop/init.lua b/mods/item_drop/init.lua index 9fa7e31..ae5ddce 100644 --- a/mods/item_drop/init.lua +++ b/mods/item_drop/init.lua @@ -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