2019-03-09 21:26:15 +03:00
|
|
|
--[[
|
|
|
|
|
2020-08-22 20:42:36 +03:00
|
|
|
TechAge
|
|
|
|
=======
|
2019-03-09 21:26:15 +03:00
|
|
|
|
2020-08-22 20:42:36 +03:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-03-09 21:26:15 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-03-09 21:26:15 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-08-22 20:42:36 +03:00
|
|
|
Tube support for default chests and furnace
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-03-09 21:26:15 +03:00
|
|
|
]]--
|
|
|
|
|
2019-05-03 23:30:06 +03:00
|
|
|
local OwnerCache = {
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Check if the chest is in the protected area of the owner
|
2022-01-03 23:40:31 +03:00
|
|
|
local function is_owner(pos, meta)
|
2019-05-03 23:30:06 +03:00
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
local key = minetest.hash_node_position(pos)
|
|
|
|
-- If successfull, store info in cache
|
|
|
|
if OwnerCache[key] ~= owner then
|
|
|
|
if not minetest.is_protected(pos, owner) then
|
|
|
|
OwnerCache[key] = owner
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return OwnerCache[key] == owner
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-05-03 23:30:06 +03:00
|
|
|
|
2019-06-08 23:57:01 +03:00
|
|
|
techage.register_node({"default:chest", "default:chest_open"}, {
|
2021-03-08 23:27:51 +03:00
|
|
|
on_inv_request = function(pos, in_dir, access_type)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
return meta:get_inventory(), "main"
|
|
|
|
end,
|
2019-03-09 21:26:15 +03:00
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.get_items(pos, inv, "main", num)
|
2019-03-09 21:26:15 +03:00
|
|
|
end,
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2019-05-03 23:30:06 +03:00
|
|
|
return techage.put_items(inv, "main", stack)
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.put_items(inv, "main", stack)
|
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2019-05-03 23:30:06 +03:00
|
|
|
|
2019-06-08 23:57:01 +03:00
|
|
|
techage.register_node({"default:chest_locked", "default:chest_locked_open"}, {
|
2021-03-08 23:27:51 +03:00
|
|
|
on_inv_request = function(pos, in_dir, access_type)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if is_owner(pos, meta) then
|
|
|
|
return meta:get_inventory(), "main"
|
|
|
|
end
|
|
|
|
end,
|
2019-05-03 23:30:06 +03:00
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if is_owner(pos, meta) then
|
|
|
|
local inv = meta:get_inventory()
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.get_items(pos, inv, "main", num)
|
2019-05-03 23:30:06 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2019-03-10 13:36:00 +03:00
|
|
|
return techage.put_items(inv, "main", stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2019-03-10 13:36:00 +03:00
|
|
|
return techage.put_items(inv, "main", stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2019-03-09 21:26:15 +03:00
|
|
|
|
2021-04-22 18:32:02 +03:00
|
|
|
techage.register_node({"shop:shop"}, {
|
|
|
|
on_inv_request = function(pos, in_dir, access_type)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if is_owner(pos, meta) then
|
2024-04-28 20:14:26 +03:00
|
|
|
if access_type == "push" then
|
|
|
|
return meta:get_inventory(), "stock"
|
|
|
|
elseif access_type == "pull" then
|
|
|
|
return meta:get_inventory(), "register"
|
|
|
|
end
|
2021-04-22 18:32:02 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if is_owner(pos, meta) then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.get_items(pos, inv, "register", num)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.put_items(inv, "stock", stack)
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.put_items(inv, "register", stack)
|
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2021-04-22 18:32:02 +03:00
|
|
|
|
2019-06-08 23:57:01 +03:00
|
|
|
techage.register_node({"default:furnace", "default:furnace_active"}, {
|
2019-03-09 21:26:15 +03:00
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.get_items(pos, inv, "dst", num)
|
2019-03-09 21:26:15 +03:00
|
|
|
end,
|
2022-11-21 23:50:37 +03:00
|
|
|
on_push_item = function(pos, in_dir, stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
minetest.get_node_timer(pos):start(1.0)
|
2022-11-21 23:50:37 +03:00
|
|
|
if in_dir == 5 then
|
|
|
|
return techage.put_items(inv, "src", stack)
|
|
|
|
elseif minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
|
2019-03-10 13:36:00 +03:00
|
|
|
return techage.put_items(inv, "fuel", stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
else
|
2020-05-23 15:11:35 +03:00
|
|
|
return techage.put_items(inv, "src", stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
end
|
|
|
|
end,
|
2022-11-21 23:50:37 +03:00
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2020-05-23 15:11:35 +03:00
|
|
|
return techage.put_items(inv, "dst", stack)
|
2019-03-09 21:26:15 +03:00
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2021-02-22 22:35:22 +03:00
|
|
|
|
|
|
|
techage.register_node({"mobs:beehive"}, {
|
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.get_items(pos, inv, "beehive", num)
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.put_items(inv, "beehive", stack)
|
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2021-02-22 22:35:22 +03:00
|
|
|
|
2021-02-22 22:42:16 +03:00
|
|
|
techage.register_node({"xdecor:hive"}, {
|
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.get_items(pos, inv, "honey", num)
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return techage.put_items(inv, "honey", stack)
|
|
|
|
end,
|
2022-01-04 21:40:27 +03:00
|
|
|
})
|