2019-02-23 09:44:22 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-08 19:11:05 -05:00
|
|
|
local ItemStack, ipairs, minetest, nodecore
|
|
|
|
= ItemStack, ipairs, minetest, nodecore
|
2019-02-23 09:44:22 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
function nodecore.node_inv(pos)
|
|
|
|
return minetest.get_meta(pos):get_inventory()
|
|
|
|
end
|
|
|
|
|
|
|
|
function nodecore.stack_get(pos)
|
|
|
|
return nodecore.node_inv(pos):get_stack("solo", 1)
|
|
|
|
end
|
|
|
|
|
2019-03-08 19:11:05 -05:00
|
|
|
local function update(pos, ...)
|
|
|
|
for _, v in ipairs(nodecore.visinv_update_ents(pos)) do
|
|
|
|
v:get_luaentity():itemcheck()
|
|
|
|
end
|
|
|
|
return ...
|
|
|
|
end
|
|
|
|
|
2019-02-23 09:44:22 -05:00
|
|
|
function nodecore.stack_set(pos, stack)
|
2019-03-08 19:11:05 -05:00
|
|
|
return update(pos, nodecore.node_inv(pos):set_stack("solo", 1, ItemStack(stack)))
|
2019-02-23 09:44:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function nodecore.stack_add(pos, stack)
|
2019-03-02 21:41:25 -05:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local def = minetest.registered_items[node.name]
|
|
|
|
if def and def.stack_allow then
|
2019-03-02 22:53:28 -05:00
|
|
|
local ret = def.stack_allow(pos, node, stack)
|
2019-03-02 21:41:25 -05:00
|
|
|
if ret == false then return stack end
|
|
|
|
if ret and ret ~= true then return ret end
|
|
|
|
end
|
2019-03-08 19:11:05 -05:00
|
|
|
return update(pos, nodecore.node_inv(pos):add_item("solo", ItemStack(stack)))
|
2019-02-23 09:44:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function nodecore.stack_giveto(pos, player)
|
2019-02-23 10:21:27 -05:00
|
|
|
local stack = nodecore.stack_get(pos)
|
2019-02-23 09:44:22 -05:00
|
|
|
stack = player:get_inventory():add_item("main", stack)
|
2019-02-23 10:21:27 -05:00
|
|
|
nodecore.stack_set(pos, stack)
|
|
|
|
return stack:is_empty()
|
2019-02-23 09:44:22 -05:00
|
|
|
end
|