add tubelib support to chests

This commit is contained in:
y 2019-05-27 03:31:56 +01:00
parent a9b10cc4b1
commit 98949482f8
3 changed files with 43 additions and 1 deletions

View File

@ -4,3 +4,4 @@ moreblocks?
moreores?
pipeworks?
intllib?
tubelib?

3
technic_chests/mod.conf Normal file
View File

@ -0,0 +1,3 @@
name=technic_chests
depends=default,basic_materials
optional_depends=moreblocks,moreores,pipeworks,intllib,tubelib

View File

@ -330,12 +330,48 @@ function technic.chests:definition(name, data)
return def
end
local _TUBELIB_CALLBACKS = {
on_pull_item = function(pos, side, player_name)
local inv = minetest.get_meta(pos):get_inventory()
if not minetest.is_protected(pos, player_name) then
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,
on_recv_message = function(pos, topic, payload)
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 minetest.get_modpath("tubelib") then
tubelib.register_node(nn, {}, _TUBELIB_CALLBACKS)
end
if data.color then
local mk_front
if string.find(def.tiles[6], "%^") then
@ -353,8 +389,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 minetest.get_modpath("tubelib") then
tubelib.register_node(nn..postfix, {}, _TUBELIB_CALLBACKS)
end
end
end
end