From ae58f848f7e7fee9a59c944b5d0c004b0615b777 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 12 Dec 2018 21:10:17 +0200 Subject: [PATCH] remove elepower_fapi --- elepower_dynamics/craftitems.lua | 3 - elepower_dynamics/nodes.lua | 3 + elepower_fapi/depends.txt | 3 - elepower_fapi/formspec.lua | 25 ---- elepower_fapi/init.lua | 11 -- elepower_fapi/mod.conf | 4 - elepower_fapi/transfer.lua | 213 ------------------------------- elepower_fapi/transfer_node.lua | 103 --------------- 8 files changed, 3 insertions(+), 362 deletions(-) delete mode 100644 elepower_fapi/depends.txt delete mode 100644 elepower_fapi/formspec.lua delete mode 100644 elepower_fapi/init.lua delete mode 100644 elepower_fapi/mod.conf delete mode 100644 elepower_fapi/transfer.lua delete mode 100644 elepower_fapi/transfer_node.lua diff --git a/elepower_dynamics/craftitems.lua b/elepower_dynamics/craftitems.lua index a607607..1abb547 100644 --- a/elepower_dynamics/craftitems.lua +++ b/elepower_dynamics/craftitems.lua @@ -253,6 +253,3 @@ minetest.register_craftitem("elepower_dynamics:pv_cell", { --------------- -- Overrides -- --------------- - -minetest.register_alias("elepower_dynamics:fluid_transfer_node", "fluid_transfer:fluid_transfer_pump") -minetest.register_alias("elepower_dynamics:fluid_duct", "fluid_transfer:fluid_duct") diff --git a/elepower_dynamics/nodes.lua b/elepower_dynamics/nodes.lua index 1eb0af4..f27ee68 100644 --- a/elepower_dynamics/nodes.lua +++ b/elepower_dynamics/nodes.lua @@ -3,6 +3,9 @@ -- Overrides -- --------------- +minetest.register_alias_force("elepower_dynamics:fluid_transfer_node", "fluid_transfer:fluid_transfer_pump") +minetest.register_alias_force("elepower_dynamics:fluid_duct", "fluid_transfer:fluid_duct") + ----------- -- Nodes -- ----------- diff --git a/elepower_fapi/depends.txt b/elepower_fapi/depends.txt deleted file mode 100644 index de13e3b..0000000 --- a/elepower_fapi/depends.txt +++ /dev/null @@ -1,3 +0,0 @@ -elepower_papi -fluid_lib -node_io? diff --git a/elepower_fapi/formspec.lua b/elepower_fapi/formspec.lua deleted file mode 100644 index 12d4b9e..0000000 --- a/elepower_fapi/formspec.lua +++ /dev/null @@ -1,25 +0,0 @@ - --- Fluid bar for formspec -function ele.formspec.fluid_bar(x, y, fluid_buffer) - local texture = "default_water.png" - local metric = 0 - local tooltip = ("tooltip[%d,%d;1,2.5;%s]"):format(x, y, "Empty Buffer") - - if fluid_buffer and fluid_buffer.fluid and fluid_buffer.fluid ~= "" and - minetest.registered_nodes[fluid_buffer.fluid] ~= nil then - texture = minetest.registered_nodes[fluid_buffer.fluid].tiles[1] - if type(texture) == "table" then - texture = texture.name - end - - local fdesc = fluid_lib.cleanse_node_description(fluid_buffer.fluid) - metric = math.floor(100 * fluid_buffer.amount / fluid_buffer.capacity) - tooltip = ("tooltip[%d,%d;1,2.5;%s\n%s / %s %s]"):format(x, y, fdesc, - ele.helpers.comma_value(fluid_buffer.amount), ele.helpers.comma_value(fluid_buffer.capacity), fluid_lib.unit) - end - - return "image["..x..","..y..";1,2.8;elepower_gui_barbg.png".. - "\\^[lowpart\\:"..metric.."\\:"..texture.."\\\\^[resize\\\\:64x128]".. - "image["..x..","..y..";1,2.8;elepower_gui_gauge.png]".. - tooltip -end diff --git a/elepower_fapi/init.lua b/elepower_fapi/init.lua deleted file mode 100644 index b9ffa2d..0000000 --- a/elepower_fapi/init.lua +++ /dev/null @@ -1,11 +0,0 @@ --- An Elepower Mod --- Copyright 2018 Evert "Diamond" Prants - -local modpath = minetest.get_modpath(minetest.get_current_modname()) - -elefluid = rawget(_G, "elefluid") or {} -elefluid.modpath = modpath - -dofile(modpath.."/transfer.lua") -dofile(modpath.."/transfer_node.lua") -dofile(modpath.."/formspec.lua") diff --git a/elepower_fapi/mod.conf b/elepower_fapi/mod.conf deleted file mode 100644 index 82d844a..0000000 --- a/elepower_fapi/mod.conf +++ /dev/null @@ -1,4 +0,0 @@ -name = elepower_fapi -description = Elepower Fluid Transfer API -depends = elepower_papi,fluid_lib -optional_depends = node_io diff --git a/elepower_fapi/transfer.lua b/elepower_fapi/transfer.lua deleted file mode 100644 index 844e49e..0000000 --- a/elepower_fapi/transfer.lua +++ /dev/null @@ -1,213 +0,0 @@ --- Network graphs are built eminating from provider nodes. --- TODO: Caching - ---------------------- --- Graph Functions -- ---------------------- - -local function clear_networks_from_node(pos) - local meta = minetest.get_meta(pos) - meta:set_string("network_id", "") -end - -local function add_node(nodes, pos, pnodeid) - local node_id = minetest.hash_node_position(pos) - if nodes[node_id] then - return false - end - nodes[node_id] = pos - return true -end - -local function add_duct_node(nodes, pos, pnodeid, queue) - if add_node(nodes, pos, pnodeid) then - queue[#queue + 1] = pos - end -end - -local function check_node(targets, all_nodes, pos, p_pos, pnodeid, queue) - ele.helpers.get_or_load_node(pos) - local node = minetest.get_node(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 - add_duct_node(all_nodes, pos, pnodeid, queue) - return - end - - if not ndef['node_io_can_put_liquid'] or not ndef['node_io_can_put_liquid'](pos, node, "") then - return - end - - add_node(targets, pos, pnodeid) -end - -local function traverse_network(targets, all_nodes, pos, p_pos, pnodeid, queue) - local positions = { - {x=pos.x+1, y=pos.y, z=pos.z}, - {x=pos.x-1, y=pos.y, z=pos.z}, - {x=pos.x, y=pos.y+1, z=pos.z}, - {x=pos.x, y=pos.y-1, z=pos.z}, - {x=pos.x, y=pos.y, z=pos.z+1}, - {x=pos.x, y=pos.y, z=pos.z-1}} - for _, cur_pos in pairs(positions) do - check_node(targets, all_nodes, cur_pos, p_pos, pnodeid, queue) - end -end - -local function fluid_targets(p_pos, pos) - local provider = minetest.get_node(p_pos) - local pnodeid = minetest.pos_to_string(p_pos) - - local targets = {} - local queue = {} - local all_nodes = {} - - 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 - add_duct_node(all_nodes, pos, pnodeid, queue) - elseif node and ndef['node_io_can_put_liquid'] and ndef['node_io_can_put_liquid'](pos, node, "") then - queue = {p_pos} - end - - while next(queue) do - local to_visit = {} - for _, posi in ipairs(queue) do - traverse_network(targets, all_nodes, posi, p_pos, pnodeid, to_visit) - end - queue = to_visit - end - - targets = ele.helpers.flatten(targets) - all_nodes = ele.helpers.flatten(all_nodes) - - return targets -end - -function elefluid.transfer_timer_tick(pos, elapsed) - local refresh = true - local node = minetest.get_node_or_nil(pos) - - if not node then - return false - end - - local meta = minetest.get_meta(pos) - local targets = {} - - -- 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 tnode = minetest.get_node(tpos) - local ndef = minetest.registered_nodes[tnode.name] - 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) - return - end - - -- Retrieve network - targets = fluid_targets(pos, tpos) - - -- No targets, don't proceed - if #targets == 0 then - return true - end - - -- Begin transfer - local srcpos = ele.helpers.face_front(pos, node.param2) - local srcnode = minetest.get_node(srcpos) - - -- Make sure source node is not air - if not srcnode or srcnode.name == "air" then - return true - end - - local srcdef = minetest.registered_nodes[srcnode.name] - - -- Make sure source node is a registered fluid container - if not srcdef['node_io_can_take_liquid'] then - return false - 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 srcdef = minetest.registered_nodes[srcnode.name] - local fl_size = srcdef.node_io_get_liquid_size(srcpos, srcnode, "") - 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 - local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity") - local pumped = 0 - - -- Transfer some fluid here - for _,pos in pairs(targets) do - if not vector.equals(pos, srcpos) then - if pumped >= pcapability then break end - 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 - - if pp ~= nil then - for bindex,bfluid in pairs(pp) do - for aindex,afluid in pairs(buffers) do - if pumped >= pcapability then break end - if (afluid == bfluid or bfluid == "") then - local idef = destdef.node_io_room_for_liquid(pos, destnode, "", afluid, pcapability) - if idef > 0 then - local fluidcount = srcdef.node_io_get_liquid_stack(srcpos, srcnode, "", aindex):get_count() - local defc = math.min(fluidcount, idef) - local defi = srcdef.node_io_take_liquid(srcpos, srcnode, "", nil, afluid, defc) - if defi.millibuckets > 0 then - local lo = destdef.node_io_put_liquid(pos, destnode, "", nil, afluid, defi.millibuckets) - pumped = pumped + (defi.millibuckets - lo) - changed = true - end - end - end - end - end - end - - if changed then - minetest.get_node_timer(srcpos):start(1.0) - minetest.get_node_timer(pos):start(1.0) - end - end - end - - return refresh -end - -function elefluid.refresh_node(pos) - minetest.get_node_timer(pos):start(1.0) - return -end - -minetest.register_lbm({ - label = "Fluid Transfer Tick", - name = "elepower_fapi:fluid_transfer_tick", - nodenames = {"group:elefluid_transport_source"}, - run_at_every_load = true, - action = elefluid.refresh_node, -}) diff --git a/elepower_fapi/transfer_node.lua b/elepower_fapi/transfer_node.lua deleted file mode 100644 index a957975..0000000 --- a/elepower_fapi/transfer_node.lua +++ /dev/null @@ -1,103 +0,0 @@ --- Nodes for transferring fluids --- All units are in millibuckets (1 bucket) - --- This is the node that takes fluid from another node. -function elefluid.register_transfer_node(nodename, nodedef) - if not nodedef.groups then - nodedef.groups = {} - end - - nodedef.groups["elefluid_transport_source"] = 1 - nodedef.paramtype2 = "facedir" - nodedef.legacy_facedir_simple = true - nodedef.on_timer = elefluid.transfer_timer_tick - - local orig_construct = nodedef.on_construct - nodedef.on_construct = function (pos) - local meta = minetest.get_meta(pos) - meta:set_int("fluid_store", 0) - meta:set_string("fluid", "") - - elefluid.refresh_node(pos) - - if orig_construct then - orig_construct(pos) - end - end - - nodedef.on_punch = function (pos, node, puncher, pointed_thing) - minetest.get_node_timer(pos):start(1.0) - minetest.node_punch(pos, node, puncher, pointed_thing) - end - - -- Default transfer capacity - if not nodedef.ele_fluid_pump_capacity then - nodedef.ele_fluid_pump_capacity = 1000 - end - - minetest.register_node(nodename, nodedef) -end - --- This is the node that allows for fluid transfer. -function elefluid.register_transfer_duct(nodename, nodedef) - if not nodedef.groups then - nodedef.groups = {} - end - - nodedef.groups["elefluid_transport"] = 1 - - -- Duct node density - local cd = 1/7 - - if nodedef.ele_duct_density then - cd = nodedef.ele_duct_density - end - - -- Default values, including the nodebox - local defaults = { - drawtype = "nodebox", - node_box = { - type = "connected", - fixed = { - {-cd, -cd, -cd, cd, cd, cd} - }, - connect_front = { - {-cd, -cd, -1/2, cd, cd, -cd} - }, - connect_back = { - {-cd, -cd, cd, cd, cd, 1/2} - }, - connect_top = { - {-cd, cd, -cd, cd, 1/2, cd} - }, - connect_bottom = { - {-cd, -1/2, -cd, cd, -cd, cd} - }, - connect_left = { - {-1/2, -cd, -cd, cd, cd, cd} - }, - connect_right = { - {cd, -cd, -cd, 1/2, cd, cd} - }, - }, - paramtype = "light", - connect_sides = { "top", "bottom", "front", "left", "back", "right" }, - is_ground_content = false, - connects_to = { - "group:elefluid_transport", - "group:elefluid_transport_source", - "group:fluid_container" - }, - } - - for k,v in pairs(defaults) do - if not nodedef[k] then - nodedef[k] = v - end - end - --- nodedef.on_construct = elefluid.refresh_node --- nodedef.after_destruct = elefluid.refresh_node - - minetest.register_node(nodename, nodedef) -end