mirror of
https://github.com/sirrobzeroone/elepower.git
synced 2024-08-20 21:04:06 +02:00
Alpha 5
This commit is contained in:
commit
db44499501
@ -1,2 +1,3 @@
|
|||||||
elepower_papi
|
elepower_papi
|
||||||
fluid_lib
|
fluid_lib
|
||||||
|
node_io?
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
name = elepower_fapi
|
name = elepower_fapi
|
||||||
description = Elepower Fluid Transfer API
|
description = Elepower Fluid Transfer API
|
||||||
depends = elepower_papi,fluid_lib
|
depends = elepower_papi,fluid_lib
|
||||||
|
optional_depends = node_io
|
||||||
|
@ -29,13 +29,14 @@ local function check_node(targets, all_nodes, pos, p_pos, pnodeid, queue)
|
|||||||
ele.helpers.get_or_load_node(pos)
|
ele.helpers.get_or_load_node(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
|
||||||
if ele.helpers.get_item_group(node.name, "elefluid_transport") then
|
if ele.helpers.get_item_group(node.name, "elefluid_transport") then
|
||||||
add_duct_node(all_nodes, pos, pnodeid, queue)
|
add_duct_node(all_nodes, pos, pnodeid, queue)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ele.helpers.get_item_group(node.name, "fluid_container") then
|
if not ndef['node_io_can_put_liquid'] or not ndef['node_io_can_put_liquid'](pos, node, "") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -64,9 +65,10 @@ local function fluid_targets(p_pos, pos)
|
|||||||
local all_nodes = {}
|
local all_nodes = {}
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
if node and ele.helpers.get_item_group(node.name, "elefluid_transport") then
|
if node and ele.helpers.get_item_group(node.name, "elefluid_transport") then
|
||||||
add_duct_node(all_nodes, pos, pnodeid, queue)
|
add_duct_node(all_nodes, pos, pnodeid, queue)
|
||||||
elseif node and ele.helpers.get_item_group(node.name, "fluid_container") then
|
elseif node and ndef['node_io_can_put_liquid'] and ndef['node_io_can_put_liquid'](pos, node, "") then
|
||||||
queue = {p_pos}
|
queue = {p_pos}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,9 +99,10 @@ function elefluid.transfer_timer_tick(pos, elapsed)
|
|||||||
|
|
||||||
-- Only allow the node directly behind to be a start of a network
|
-- Only allow the node directly behind to be a start of a network
|
||||||
local tpos = vector.add(minetest.facedir_to_dir(node.param2), pos)
|
local tpos = vector.add(minetest.facedir_to_dir(node.param2), pos)
|
||||||
local tname = minetest.get_node(tpos).name
|
local tnode = minetest.get_node(tpos)
|
||||||
if not ele.helpers.get_item_group(tname, "elefluid_transport") and
|
local ndef = minetest.registered_nodes[tnode.name]
|
||||||
not ele.helpers.get_item_group(tname, "fluid_container") then
|
if not ele.helpers.get_item_group(tnode.name, "elefluid_transport") and
|
||||||
|
(not ndef['node_io_can_put_liquid'] or not ndef['node_io_can_put_liquid'](tpos, tnode, "")) then
|
||||||
minetest.forceload_free_block(pos)
|
minetest.forceload_free_block(pos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -121,15 +124,24 @@ function elefluid.transfer_timer_tick(pos, elapsed)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local srcdef = minetest.registered_nodes[srcnode.name]
|
||||||
|
|
||||||
-- Make sure source node is a registered fluid container
|
-- Make sure source node is a registered fluid container
|
||||||
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") then
|
if not srcdef['node_io_can_take_liquid'] then
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local c = srcdef.node_io_can_take_liquid(srcpos, srcnode, "")
|
||||||
|
if not c then return false end
|
||||||
|
|
||||||
local srcmeta = minetest.get_meta(srcpos)
|
local srcmeta = minetest.get_meta(srcpos)
|
||||||
local srcdef = minetest.registered_nodes[srcnode.name]
|
local srcdef = minetest.registered_nodes[srcnode.name]
|
||||||
local buffers = fluid_lib.get_node_buffers(srcpos)
|
local fl_size = srcdef.node_io_get_liquid_size(srcpos, srcnode, "")
|
||||||
if not buffers then return true end
|
local buffers = {}
|
||||||
|
for i = 1, fl_size do
|
||||||
|
buffers[i] = srcdef.node_io_get_liquid_name(srcpos, srcnode, "", i)
|
||||||
|
end
|
||||||
|
if not #buffers then return true end
|
||||||
|
|
||||||
-- Limit the amount of fluid pumped per cycle
|
-- Limit the amount of fluid pumped per cycle
|
||||||
local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity")
|
local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity")
|
||||||
@ -139,27 +151,36 @@ function elefluid.transfer_timer_tick(pos, elapsed)
|
|||||||
for _,pos in pairs(targets) do
|
for _,pos in pairs(targets) do
|
||||||
if not vector.equals(pos, srcpos) then
|
if not vector.equals(pos, srcpos) then
|
||||||
if pumped >= pcapability then break end
|
if pumped >= pcapability then break end
|
||||||
local pp = fluid_lib.get_node_buffers(pos)
|
local destnode = minetest.get_node(pos)
|
||||||
|
local destdef = minetest.registered_nodes[destnode.name]
|
||||||
|
local pp = nil
|
||||||
|
|
||||||
|
if destdef['node_io_can_put_liquid'] then
|
||||||
|
if destdef.node_io_can_put_liquid(pos, destnode, "") then
|
||||||
|
pp = {}
|
||||||
|
local fl_size = destdef.node_io_get_liquid_size(pos, destnode, "")
|
||||||
|
for i = 1, fl_size do
|
||||||
|
pp[i] = destdef.node_io_get_liquid_name(pos, destnode, "", i)
|
||||||
|
end
|
||||||
|
if not #pp then pp = nil end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local changed = false
|
local changed = false
|
||||||
|
|
||||||
if pp ~= nil then
|
if pp ~= nil then
|
||||||
for name in pairs(pp) do
|
for bindex,bfluid in pairs(pp) do
|
||||||
for bname in pairs(buffers) do
|
for aindex,afluid in pairs(buffers) do
|
||||||
if pumped >= pcapability then break end
|
if pumped >= pcapability then break end
|
||||||
local buffer_data = fluid_lib.get_buffer_data(srcpos, bname)
|
if (afluid == bfluid or bfluid == "") then
|
||||||
local target_data = fluid_lib.get_buffer_data(pos, name)
|
local idef = destdef.node_io_room_for_liquid(pos, destnode, "", afluid, pcapability)
|
||||||
|
if idef > 0 then
|
||||||
if (target_data.fluid == buffer_data.fluid or target_data.fluid == "") and
|
local fluidcount = srcdef.node_io_get_liquid_stack(srcpos, srcnode, "", aindex):get_count()
|
||||||
buffer_data.fluid ~= "" and buffer_data.amount > 0 and
|
local defc = math.min(fluidcount, idef)
|
||||||
(buffer_data.drainable == nil or buffer_data.drainable == true) and
|
local defi = srcdef.node_io_take_liquid(srcpos, srcnode, "", nil, afluid, defc)
|
||||||
fluid_lib.buffer_accepts_fluid(pos, name, buffer_data.fluid) then
|
if defi.millibuckets > 0 then
|
||||||
|
local lo = destdef.node_io_put_liquid(pos, destnode, "", nil, afluid, defi.millibuckets)
|
||||||
if fluid_lib.can_insert_into_buffer(pos, name, buffer_data.fluid, pcapability) > 0 then
|
pumped = pumped + (defi.millibuckets - lo)
|
||||||
local res_f, count = fluid_lib.take_from_buffer(srcpos, bname, pcapability)
|
|
||||||
if count > 0 then
|
|
||||||
fluid_lib.insert_into_buffer(pos, name, res_f, count)
|
|
||||||
pumped = pumped + count
|
|
||||||
changed = true
|
changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,3 +67,5 @@ minetest.register_abm({
|
|||||||
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
|
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fluid_lib.register_node("elepower_farming:tree_extractor")
|
||||||
|
@ -59,6 +59,9 @@ minetest.register_abm({
|
|||||||
buffer.amount = buffer.amount + give
|
buffer.amount = buffer.amount + give
|
||||||
|
|
||||||
meta:set_int("water_fluid_storage", buffer.amount)
|
meta:set_int("water_fluid_storage", buffer.amount)
|
||||||
|
meta:set_string("water_fluid", "default:water_source")
|
||||||
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
|
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fluid_lib.register_node("elepower_machines:accumulator")
|
||||||
|
@ -117,7 +117,6 @@ ele.register_base_device("elepower_machines:bucketer", {
|
|||||||
fluid_buffers = {
|
fluid_buffers = {
|
||||||
input = {
|
input = {
|
||||||
capacity = 8000,
|
capacity = 8000,
|
||||||
drainable = false,
|
|
||||||
accepts = true,
|
accepts = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
default
|
default
|
||||||
pipeworks?
|
pipeworks?
|
||||||
tubelib?
|
tubelib?
|
||||||
|
mesecons?
|
||||||
|
node_io?
|
||||||
|
@ -311,6 +311,54 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Node IO Support
|
||||||
|
if nodedef.groups["tubedevice"] or nodedef.groups["tube"] then
|
||||||
|
nodedef.node_io_can_put_item = function(pos, node, side) return true end
|
||||||
|
nodedef.node_io_room_for_item = function(pos, node, side, itemstack, count)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
local istack_real = ItemStack(itemstack)
|
||||||
|
istack_real:set_count(count)
|
||||||
|
return inv:room_for_item("src", istack_real)
|
||||||
|
end
|
||||||
|
nodedef.node_io_put_item = function(pos, node, side, putter, itemstack)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
local t = minetest.get_node_timer(pos)
|
||||||
|
if not t:is_started() then
|
||||||
|
t:start(1.0)
|
||||||
|
end
|
||||||
|
return inv:add_item("src", itemstack)
|
||||||
|
end
|
||||||
|
nodedef.node_io_can_take_item = function(pos, node, side) return true end
|
||||||
|
nodedef.node_io_get_item_size = function(pos, node, side)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:get_size("dst")
|
||||||
|
end
|
||||||
|
nodedef.node_io_get_item_name = function(pos, node, side, index)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:get_stack("dst", index):get_name()
|
||||||
|
end
|
||||||
|
nodedef.node_io_get_item_stack = function(pos, node, side, index)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:get_stack("dst", index)
|
||||||
|
end
|
||||||
|
nodedef.node_io_take_item = function(pos, node, side, taker, want_item, want_count)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
local stack = ItemStack(want_item)
|
||||||
|
stack:set_count(want_count)
|
||||||
|
local t = minetest.get_node_timer(pos)
|
||||||
|
if not t:is_started() then
|
||||||
|
t:start(1.0)
|
||||||
|
end
|
||||||
|
return inv:take_item("dst", stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Mesecons support
|
-- Mesecons support
|
||||||
if mc then
|
if mc then
|
||||||
nodedef["mesecons"] = mesecons_def
|
nodedef["mesecons"] = mesecons_def
|
||||||
@ -376,6 +424,14 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
|
|
||||||
tubelib.register_node(nodename, extras, tubelib_tube)
|
tubelib.register_node(nodename, extras, tubelib_tube)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- nodeio fluids
|
||||||
|
if nodedef.groups and nodedef.groups['fluid_container'] then
|
||||||
|
fluid_lib.register_node(nodename)
|
||||||
|
if active_name then
|
||||||
|
fluid_lib.register_node(active_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ele.register_machine(nodename, nodedef)
|
function ele.register_machine(nodename, nodedef)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
name = elepower_papi
|
name = elepower_papi
|
||||||
description = Elepower Power Network API
|
description = Elepower Power Network API
|
||||||
optional_depends = default,pipeworks,tubelib,mesecons
|
depends = default
|
||||||
|
optional_depends = pipeworks,tubelib,mesecons,node_io
|
||||||
|
Loading…
Reference in New Issue
Block a user