diff --git a/technic_chests/depends.txt b/technic_chests/depends.txt index 5d9ea6c..3fcc834 100644 --- a/technic_chests/depends.txt +++ b/technic_chests/depends.txt @@ -4,3 +4,4 @@ moreblocks? moreores? pipeworks? intllib? +tubelib? diff --git a/technic_chests/mod.conf b/technic_chests/mod.conf new file mode 100644 index 0000000..9478b19 --- /dev/null +++ b/technic_chests/mod.conf @@ -0,0 +1,3 @@ +name=technic_chests +depends=default,basic_materials +optional_depends=moreblocks,moreores,pipeworks,intllib,tubelib diff --git a/technic_chests/register.lua b/technic_chests/register.lua index 61d49d3..0d5150e 100644 --- a/technic_chests/register.lua +++ b/technic_chests/register.lua @@ -2,6 +2,7 @@ local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end local pipeworks = rawget(_G, "pipeworks") local fs_helpers = rawget(_G, "fs_helpers") +local tubelib_exists = minetest.global_exists("tubelib") local allow_label = "" local tube_entry = "" @@ -330,12 +331,46 @@ function technic.chests:definition(name, data) return def end +local _TUBELIB_CALLBACKS = { + on_pull_item = function(pos, side, player_name) + if not minetest.is_protected(pos, player_name) then + local inv = minetest.get_meta(pos):get_inventory() + for _, stack in pairs(inv:get_list("main")) do + if not stack:is_empty() then + return inv:remove_item("main", stack:get_name()) + end + end + end + return nil + end, + on_push_item = function(pos, side, item, player_name) + local inv = minetest.get_meta(pos):get_inventory() + if inv:room_for_item("main", item) then + inv:add_item("main", item) + return true + end + return false + end, + on_unpull_item = function(pos, side, item, player_name) + local inv = minetest.get_meta(pos):get_inventory() + if inv:room_for_item("main", item) then + inv:add_item("main", item) + return true + end + return false + end, +} + function technic.chests:register(name, data) local def = technic.chests:definition(name, data) local nn = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" minetest.register_node(":"..nn, def) + if tubelib_exists then + tubelib.register_node(nn, {}, _TUBELIB_CALLBACKS) + end + if data.color then local mk_front if string.find(def.tiles[6], "%^") then @@ -353,8 +388,10 @@ function technic.chests:register(name, data) colordef.groups = self.groups_noinv colordef.tiles = { def.tiles[1], def.tiles[2], def.tiles[3], def.tiles[4], def.tiles[5], mk_front("technic_chest_overlay"..postfix..".png") } minetest.register_node(":"..nn..postfix, colordef) + if tubelib_exists then + tubelib.register_node(nn..postfix, {}, _TUBELIB_CALLBACKS) + end end end - end