diff --git a/compat/pipeworks.lua b/compat/pipeworks.lua index cd04e3d..be0cbe2 100644 --- a/compat/pipeworks.lua +++ b/compat/pipeworks.lua @@ -14,222 +14,137 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local function getListnameBySide(sides,direction) + local listname + for _,side in ipairs(sides) do + if (not side.x or side.x==direction.x) and (not side.y or side.y==direction.y) and (not side.z or side.z==direction.z) then + listname=side.listname + break + end + end + return listname +end + +local function addPipeworksCompatibility(name,sides,inputInventory) + local groups=table.copy(minetest.registered_nodes[name].groups) + groups.tubedevice=1 + groups.tubedevice_receiver=1 + + local override={ + groups=groups, + tube={ + insert_object=function(pos,node,stack,direction) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local listname=getListnameBySide(sides,direction) + if (listname=="charged" or listname=="discharged" or listname=="powerStorage") and not industrialtest.api.hasPowerStorage(stack:get_meta()) then + return nil + end + local result=inv:add_item(listname,stack) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + return result + end, + can_insert=function(pos,node,stack,direction) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local listname=getListnameBySide(sides,direction) + if (listname=="charged" or listname=="discharged" or listname=="powerStorage") and not industrialtest.api.hasPowerStorage(stack:get_meta()) then + return false + end + return inv:room_for_item(listname,stack) + end, + input_inventory=inputInventory, + connect_sides={ + left=1, + right=1, + back=1, + front=1, + bottom=1, + top=1 + } + }, + after_place_node=pipeworks.after_place, + after_dig_node=pipeworks.after_dig, + on_rotate=pipeworks.on_rotate + } + + minetest.override_item(name,override) + local activeName=name.."_active" + if minetest.registered_nodes[activeName] then + minetest.override_item(activeName,override) + end +end + -- Iron Furnace -local def=table.copy(minetest.registered_nodes["industrialtest:iron_furnace"]) +addPipeworksCompatibility("industrialtest:iron_furnace",{ + { + y=1, + listname="fuel" + }, + {listname="src"} +},"dst") + +-- Generator +addPipeworksCompatibility("industrialtest:generator",{ + { + y=1, + listname="fuel", + }, + {listname="charged"} +},"charged") + +-- Geothermal Generator +addPipeworksCompatibility("industrialtest:geothermal_generator",{ + { + y=1, + listname="leftover", + }, + { + y=-1, + listname="fluid" + }, + {listname="charged"} +},"leftover") + +-- Water Mill +addPipeworksCompatibility("industrialtest:water_mill",{ + { + y=1, + listname="leftover", + }, + { + y=-1, + listname="fluid" + }, + {listname="charged"} +},"leftover") + +-- Wind Mill +addPipeworksCompatibility("industrialtest:wind_mill",{ + {listname="charged"} +},"charged") + +-- Solar Panel +addPipeworksCompatibility("industrialtest:solar_panel",{ + {listname="charged"} +},"charged") +addPipeworksCompatibility("industrialtest:lv_solar_array",{ + {listname="charged"} +},"charged") +addPipeworksCompatibility("industrialtest:mv_solar_array",{ + {listname="charged"} +},"charged") +addPipeworksCompatibility("industrialtest:hv_solar_array",{ + {listname="charged"} +},"charged") + +-- Nuclear Reactor +local def=table.copy(minetest.registered_nodes["industrialtest:nuclear_reactor"]) def.groups.tubedevice=1 def.groups.tubedevice_receiver=1 local override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(direction.y==1 and "fuel" or "src",stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(direction.y==1 and "fuel" or "src",stack) - end, - input_inventory="dst", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } - }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} -minetest.override_item("industrialtest:iron_furnace",override) -minetest.override_item("industrialtest:iron_furnace_active",override) - --- Generator -def=table.copy(minetest.registered_nodes["industrialtest:generator"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local listname=direction.y==1 and "fuel" or "charged" - if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(listname,stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local listname=direction.y==1 and "fuel" or "charged" - if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(listname,stack) - end, - input_inventory="charged", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } - }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} - -minetest.override_item("industrialtest:generator",override) -minetest.override_item("industrialtest:generator_active",override) - --- Geothermal Generator -def=table.copy(minetest.registered_nodes["industrialtest:geothermal_generator"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local listname - if direction.y==1 then - listname="leftover" - elseif direction.y==-1 then - listname="fluid" - else - listname="charged" - end - if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(listname,stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local listname - if direction.y==1 then - listname="leftover" - elseif direction.y==-1 then - listname="fluid" - else - listname="charged" - end - if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(listname,stack) - end, - input_inventory="leftover", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } - }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} - -minetest.override_item("industrialtest:geothermal_generator",override) -minetest.override_item("industrialtest:geothermal_generator_active",override) - --- Water Mill -override.groups=minetest.registered_nodes["industrialtest:water_mill"].groups -override.groups.tubedevice=1 -override.groups.tubedevice_receiver=1 - -minetest.override_item("industrialtest:water_mill",override) - --- Wind Mill -def=table.copy(minetest.registered_nodes["industrialtest:wind_mill"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - if not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item("charged",stack) - return result - end, - can_insert=function(pos,node,stack,direction) - if not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item("charged",stack) - end, - input_inventory="charged", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } - }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} - -minetest.override_item("industrialtest:wind_mill",override) - --- Solar Panel -override.groups=minetest.registered_nodes["industrialtest:solar_panel"].groups -override.groups.tubedevice=1 -override.groups.tubedevice_receiver=1 -override.tube.connect_sides={ - left=1, - right=1, - back=1, - front=1, - bottom=1 -} - -minetest.override_item("industrialtest:solar_panel",override) -minetest.override_item("industrialtest:lv_solar_array",override) -minetest.override_item("industrialtest:mv_solar_array",override) -minetest.override_item("industrialtest:hv_solar_array",override) - --- Nuclear Reactor -def=table.copy(minetest.registered_nodes["industrialtest:nuclear_reactor"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ groups=def.groups, tube={ insert_object=function(pos,node,stack,direction) @@ -260,6 +175,7 @@ override={ left=1, right=1, back=1, + front=1, bottom=1, top=1 } @@ -273,67 +189,40 @@ minetest.override_item("industrialtest:nuclear_reactor",override) minetest.override_item("industrialtest:nuclear_reactor_active",override) -- BatBox -def=table.copy(minetest.registered_nodes["industrialtest:batbox"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local listname=direction.y==1 and "discharged" or "charged" - if not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(listname,stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local listname=direction.y==1 and "discharged" or "charged" - if not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(listname,stack) - end, - input_inventory="charged", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } +addPipeworksCompatibility("industrialtest:batbox",{ + { + y=1, + listname="discharged" }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} - -minetest.override_item("industrialtest:batbox",override) + {listname="charged"} +},"charged") -- CESU -override.groups=minetest.registered_nodes["industrialtest:cesu"].groups -override.groups.tubedevice=1 -override.groups.tubedevice_receiver=1 -minetest.override_item("industrialtest:cesu",override) +addPipeworksCompatibility("industrialtest:cesu",{ + { + y=1, + listname="discharged" + }, + {listname="charged"} +},"charged") -- MFE -override.groups=minetest.registered_nodes["industrialtest:mfe"].groups -override.groups.tubedevice=1 -override.groups.tubedevice_receiver=1 -minetest.override_item("industrialtest:mfe",override) +addPipeworksCompatibility("industrialtest:mfe",{ + { + y=1, + listname="discharged" + }, + {listname="charged"} +},"charged") -- MFSU -override.groups=minetest.registered_nodes["industrialtest:mfsu"].groups -override.groups.tubedevice=1 -override.groups.tubedevice_receiver=1 -minetest.override_item("industrialtest:mfsu",override) +addPipeworksCompatibility("industrialtest:mfsu",{ + { + y=1, + listname="discharged" + }, + {listname="charged"} +},"charged") -- Canning Machine def=table.copy(minetest.registered_nodes["industrialtest:canning_machine"]) @@ -402,110 +291,25 @@ minetest.override_item("industrialtest:canning_machine",override) minetest.override_item("industrialtest:canning_machine_active",override) -- Rotary Macerator -def=table.copy(minetest.registered_nodes["industrialtest:rotary_macerator"]) - -def.groups.tubedevice=1 -def.groups.tubedevice_receiver=1 - -override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local listname - if direction.y==1 then - listname="powerStorage" - elseif direction.y==-1 then - listname="src" - else - listname="modifier" - end - local def=stack:get_definition() - if listname=="powerStorage" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(listname,stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local listname - if direction.y==1 then - listname="powerStorage" - elseif direction.y==-1 then - listname="src" - else - listname="modifier" - end - local def=stack:get_definition() - if listname=="powerStorage" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(listname,stack) - end, - input_inventory="dst", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } +addPipeworksCompatibility("industrialtest:rotary_macerator",{ + { + y=1, + listname="powerStorage" }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate -} - -minetest.override_item("industrialtest:rotary_macerator",override) -minetest.override_item("industrialtest:rotary_macerator_active",override) + { + y=-1, + listname="src" + }, + {listname="modifier"} +},"dst") -- Simple electric item processors for _,name in ipairs(industrialtest.internal.simpleElectricItemProcessors) do - local def=table.copy(minetest.registered_nodes[name]) - def.groups.tubedevice=1 - def.groups.tubedevice_receiver=1 - - local override={ - groups=def.groups, - tube={ - insert_object=function(pos,node,stack,direction) - local listname=direction.y==1 and "powerStorage" or "src" - if listname=="powerStorage" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return nil - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local result=inv:add_item(listname,stack) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - return result - end, - can_insert=function(pos,node,stack,direction) - local listname=direction.y==1 and "powerStorage" or "src" - if listname=="powerStorage" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return false - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - return inv:room_for_item(listname,stack) - end, - input_inventory="dst", - connect_sides={ - left=1, - right=1, - back=1, - bottom=1, - top=1 - } + addPipeworksCompatibility(name,{ + { + y=1, + listname="powerStorage" }, - after_place_node=pipeworks.after_place, - after_dig_node=pipeworks.after_dig, - on_rotate=pipeworks.on_rotate - } - - minetest.override_item(name,override) - minetest.override_item(name.."_active",override) + {listname="src"} + },"dst") end