Support tubelib for item transfer
This commit is contained in:
parent
fc7fd3f70f
commit
dfc0ae5ac0
@ -2,6 +2,7 @@
|
|||||||
-- Machine definitions
|
-- Machine definitions
|
||||||
|
|
||||||
local pw = minetest.get_modpath("pipeworks") ~= nil
|
local pw = minetest.get_modpath("pipeworks") ~= nil
|
||||||
|
local tl = minetest.get_modpath("tubelib") ~= nil
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Groups:
|
Groups:
|
||||||
@ -144,8 +145,25 @@ local tube = {
|
|||||||
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
|
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local tubelib_tube = {
|
||||||
|
on_pull_item = function(pos, side, player_name)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
return tubelib.get_item(meta, "dst")
|
||||||
|
end,
|
||||||
|
on_push_item = function(pos, side, item, player_name)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
return tubelib.put_item(meta, "src", item)
|
||||||
|
end,
|
||||||
|
on_unpull_item = function(pos, side, item, player_name)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
return tubelib.put_item(meta, "dst", item)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
-- Register a base device
|
-- Register a base device
|
||||||
function ele.register_base_device(nodename, nodedef)
|
function ele.register_base_device(nodename, nodedef)
|
||||||
|
local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"])
|
||||||
|
|
||||||
-- Override construct callback
|
-- Override construct callback
|
||||||
local original_on_construct = nodedef.on_construct
|
local original_on_construct = nodedef.on_construct
|
||||||
nodedef.on_construct = function (pos)
|
nodedef.on_construct = function (pos)
|
||||||
@ -165,6 +183,7 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
local original_after_destruct = nodedef.after_destruct
|
local original_after_destruct = nodedef.after_destruct
|
||||||
nodedef.after_destruct = function (pos)
|
nodedef.after_destruct = function (pos)
|
||||||
ele.clear_networks(pos)
|
ele.clear_networks(pos)
|
||||||
|
|
||||||
if original_after_destruct then
|
if original_after_destruct then
|
||||||
original_after_destruct(pos)
|
original_after_destruct(pos)
|
||||||
end
|
end
|
||||||
@ -183,12 +202,30 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
local original_after_place_node = nodedef.after_place_node
|
local original_after_place_node = nodedef.after_place_node
|
||||||
nodedef.after_place_node = function(pos, placer, itemstack, pointed_thing)
|
nodedef.after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local ret = retrieve_metadata(pos, placer, itemstack, pointed_thing)
|
local ret = retrieve_metadata(pos, placer, itemstack, pointed_thing)
|
||||||
|
|
||||||
|
if tlsupp then
|
||||||
|
tubelib.add_node(pos, nodename)
|
||||||
|
end
|
||||||
|
|
||||||
if original_after_place_node then
|
if original_after_place_node then
|
||||||
ret = original_after_place_node(pos, placer, itemstack, pointed_thing)
|
ret = original_after_place_node(pos, placer, itemstack, pointed_thing)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local original_after_dig_node = nodedef.after_dig_node
|
||||||
|
nodedef.after_dig_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
|
if tlsupp then
|
||||||
|
tubelib.add_node(pos, nodename)
|
||||||
|
end
|
||||||
|
|
||||||
|
if original_after_dig_node then
|
||||||
|
return original_after_dig_node(pos, placer, itemstack, pointed_thing)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Prevent digging when there's items inside
|
-- Prevent digging when there's items inside
|
||||||
if not nodedef.can_dig then
|
if not nodedef.can_dig then
|
||||||
nodedef.can_dig = can_dig
|
nodedef.can_dig = can_dig
|
||||||
@ -213,11 +250,12 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
|
|
||||||
-- Finally, register the damn thing already
|
-- Finally, register the damn thing already
|
||||||
minetest.register_node(nodename, nodedef)
|
minetest.register_node(nodename, nodedef)
|
||||||
|
local active_name = nil
|
||||||
|
|
||||||
-- Register an active variant if configured.
|
-- Register an active variant if configured.
|
||||||
if nodedef.ele_active_node then
|
if nodedef.ele_active_node then
|
||||||
local active_nodedef = ele.helpers.table_copy(nodedef)
|
local active_nodedef = ele.helpers.table_copy(nodedef)
|
||||||
local active_name = nodename.."_active"
|
active_name = nodename.."_active"
|
||||||
|
|
||||||
if nodedef.ele_active_node ~= true then
|
if nodedef.ele_active_node ~= true then
|
||||||
active_name = nodedef.ele_active_node
|
active_name = nodedef.ele_active_node
|
||||||
@ -237,6 +275,18 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
active_nodedef.drop = nodename
|
active_nodedef.drop = nodename
|
||||||
minetest.register_node(active_name, active_nodedef)
|
minetest.register_node(active_name, active_nodedef)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- tubelib support
|
||||||
|
if tlsupp then
|
||||||
|
local extras = {}
|
||||||
|
|
||||||
|
if active_name then
|
||||||
|
extras = {active_name}
|
||||||
|
end
|
||||||
|
|
||||||
|
tubelib.register_node(nodename, extras, tubelib_tube)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ele.register_machine(nodename, nodedef)
|
function ele.register_machine(nodename, nodedef)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = elepower_papi
|
name = elepower_papi
|
||||||
description = Elepower Power Network API
|
description = Elepower Power Network API
|
||||||
optional_depends = default,pipeworks
|
optional_depends = default,pipeworks,tubelib
|
||||||
|
Loading…
Reference in New Issue
Block a user