From 4f184e2325ccef7bc7cf1e635dd43916cbc11625 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 20 Jun 2018 17:09:28 +0300 Subject: [PATCH] Depend on fluid_lib. --- elepower_fapi/bucket.lua | 59 ------- elepower_fapi/buffer.lua | 163 ------------------ elepower_fapi/init.lua | 5 - elepower_fapi/mod.conf | 3 +- elepower_fapi/transfer.lua | 16 +- elepower_farming/nodes/fluids.lua | 15 +- elepower_farming/nodes/tree_extractor.lua | 4 +- .../textures/elefarming_bucket_mask.png | Bin 5155 -> 0 bytes 8 files changed, 16 insertions(+), 249 deletions(-) delete mode 100644 elepower_fapi/bucket.lua delete mode 100644 elepower_fapi/buffer.lua delete mode 100644 elepower_farming/textures/elefarming_bucket_mask.png diff --git a/elepower_fapi/bucket.lua b/elepower_fapi/bucket.lua deleted file mode 100644 index 0d93328..0000000 --- a/elepower_fapi/bucket.lua +++ /dev/null @@ -1,59 +0,0 @@ - -local b_enabled = minetest.get_modpath("bucket") ~= nil - -local function find_fluid(itemname) - for _,data in ipairs(bucket.liquids) do - if data.itemname and data.itemname == itemname then - return data.source - end - end - return nil -end - -function elefluid.add_bucket_handler(nodedef) - if not b_enabled then return nodedef end - - local orig = nodedef.on_rightclick - nodedef.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing) - local bucket_name = itemstack:get_name() - local action = false - - if bucket_name == "bucket:bucket_empty" then - local buffers = elefluid.get_node_buffers(pos) - for buffer in pairs(buffers) do - if elefluid.can_take_from_buffer(pos, buffer, 1000) == 1000 then - local fluid = elefluid.take_from_buffer(pos, buffer, 1000) - if bucket.liquids[fluid] then - itemstack = ItemStack(bucket.liquids[fluid].itemname) - action = true - end - break - end - end - elseif find_fluid(bucket_name) then - local fluid = find_fluid(bucket) - local buffers = elefluid.get_node_buffers(pos) - for buffer in pairs(buffers) do - if elefluid.can_insert_into_buffer(pos, buffer, fluid, 1000) == 1000 then - elefluid.insert_into_buffer(pos, buffer, fluid, 1000) - itemstack = ItemStack("bucket:bucket_empty") - action = true - break - end - end - end - - -- Really stupid workaround so that the formspec closes after a bucket action was committed - if action and not orig and clicker then - minetest.close_formspec(clicker:get_player_name(), "") - end - - if orig then - return orig(pos, node, clicker, itemstack, pointed_thing) - end - - return itemstack - end - - return nodedef -end diff --git a/elepower_fapi/buffer.lua b/elepower_fapi/buffer.lua deleted file mode 100644 index 60a28ed..0000000 --- a/elepower_fapi/buffer.lua +++ /dev/null @@ -1,163 +0,0 @@ --- This API is compatible with fluidity. -local fluidmod = minetest.get_modpath("fluidity") ~= nil - -local function node_data(pos) - local node = minetest.get_node(pos) - local nodedef = minetest.registered_nodes[node.name] - return node, nodedef -end - -function elefluid.get_node_buffers(pos) - local node, nodedef = node_data(pos) - if not nodedef['fluid_buffers'] and not ele.helpers.get_item_group(node.name, "fluidity_tank") then - return nil - end - - if fluidmod and ele.helpers.get_item_group(node.name, "fluidity_tank") then - return {fluidity = {}} - end - - return nodedef['fluid_buffers'] -end - -function elefluid.get_buffer_data(pos, buffer) - local node, nodedef = node_data(pos) - local buffers = elefluid.get_node_buffers(pos) - - if not buffers[buffer] then - return nil - end - - local meta = minetest.get_meta(pos) - local fluid = meta:get_string(buffer .. "_fluid") - local amount = meta:get_int(buffer .. "_fluid_storage") - local capacity = buffers[buffer].capacity - local accepts = buffers[buffer].accepts - local drainable = buffers[buffer].drainable or true - - -- Fluidity tanks compatibility - if buffer == "fluidity" then - local ffluid, fluidcount, fcapacity, fbasetank, fmod = fluidity.tanks.get_tank_at(pos) - - fluid = ffluid - amount = fluidcount - capacity = fcapacity - accepts = true - drainable = true - end - - return { - fluid = fluid, - amount = amount, - accepts = accepts, - capacity = capacity, - drainable = drainable, - } -end - -function elefluid.buffer_accepts_fluid(pos, buffer, fluid) - local bfdata = elefluid.get_buffer_data(pos, buffer) - if not bfdata then return false end - - if bfdata.accepts == true or bfdata.accepts == fluid then - return true - end - - if bfdata.fluid ~= "" and bfdata.fluid ~= fluid then - return false - end - - if type(bfdata.accepts) ~= "table" then - bfdata.accepts = { bfdata.accepts } - end - - for _,pf in pairs(bfdata.accepts) do - if pf == fluid then - return true - elseif pf:match("^group") and ele.helpers.get_item_group(fluid, pf:gsub("group:", "")) then - return true - end - end - - return false -end - -function elefluid.can_insert_into_buffer(pos, buffer, fluid, count) - local bfdata = elefluid.get_buffer_data(pos, buffer) - if not bfdata then return 0 end - if bfdata.fluid ~= fluid and bfdata.fluid ~= "" then return 0 end - - local can_put = 0 - if bfdata.amount + count > bfdata.capacity then - can_put = bfdata.capacity - bfdata.amount - else - can_put = count - end - - return can_put -end - -function elefluid.insert_into_buffer(pos, buffer, fluid, count) - local bfdata = elefluid.get_buffer_data(pos, buffer) - if not bfdata then return nil end - if bfdata.fluid ~= fluid and bfdata.fluid ~= "" then return nil end - - local can_put = elefluid.can_insert_into_buffer(pos, buffer, fluid, count) - - if can_put == 0 then return count end - - if buffer == "fluidity" then - return fluidity.tanks.fill_tank_at(pos, fluid, count, true) - end - - local meta = minetest.get_meta(pos) - meta:set_int(buffer .. "_fluid_storage", bfdata.amount + can_put) - meta:set_string(buffer .. "_fluid", fluid) - - return 0 -end - -function elefluid.can_take_from_buffer(pos, buffer, count) - local bfdata = elefluid.get_buffer_data(pos, buffer) - if not bfdata or not bfdata.drainable then return 0 end - - local amount = bfdata.amount - local take_count = 0 - - if amount < count then - take_count = amount - else - take_count = count - end - - return take_count -end - -function elefluid.take_from_buffer(pos, buffer, count) - local bfdata = elefluid.get_buffer_data(pos, buffer) - if not bfdata then return nil end - - local fluid = bfdata.fluid - local amount = bfdata.amount - - local take_count = elefluid.can_take_from_buffer(pos, buffer, count) - - if buffer == "fluidity" then - local fname, cf = fluidity.tanks.take_from_tank_at(pos, count, true) - if cf then - count = count - cf - end - return fname, count - end - - local new_storage = amount - take_count - if new_storage == 0 then - fluid = "" - end - - local meta = minetest.get_meta(pos) - meta:set_int(buffer .. "_fluid_storage", new_storage) - meta:set_string(buffer .. "_fluid", fluid) - - return bfdata.fluid, take_count -end diff --git a/elepower_fapi/init.lua b/elepower_fapi/init.lua index d5213d3..e2fc706 100644 --- a/elepower_fapi/init.lua +++ b/elepower_fapi/init.lua @@ -6,11 +6,6 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) elefluid = rawget(_G, "elefluid") or {} elefluid.modpath = modpath -elefluid.unit = "mB" -elefluid.unit_description = "milli-bucket" - dofile(modpath.."/transfer.lua") dofile(modpath.."/transfer_node.lua") dofile(modpath.."/formspec.lua") -dofile(modpath.."/buffer.lua") -dofile(modpath.."/bucket.lua") diff --git a/elepower_fapi/mod.conf b/elepower_fapi/mod.conf index ab91a86..ee810ae 100644 --- a/elepower_fapi/mod.conf +++ b/elepower_fapi/mod.conf @@ -1,4 +1,3 @@ name = elepower_fapi description = Elepower Fluid Transfer API -depends = elepower_papi -optional_depends = fluidity,bucket +depends = elepower_papi,fluid_lib diff --git a/elepower_fapi/transfer.lua b/elepower_fapi/transfer.lua index 218f376..ee6f8bf 100644 --- a/elepower_fapi/transfer.lua +++ b/elepower_fapi/transfer.lua @@ -152,7 +152,7 @@ minetest.register_abm({ local srcmeta = minetest.get_meta(srcpos) local srcdef = minetest.registered_nodes[srcnode.name] - local buffers = elefluid.get_node_buffers(srcpos) + local buffers = fluid_lib.get_node_buffers(srcpos) if not buffers then return nil end -- Limit the amount of fluid pumped per cycle @@ -163,7 +163,7 @@ minetest.register_abm({ for _,pos in pairs(targets) do if not vector.equals(pos, srcpos) then if pumped >= pcapability then break end - local pp = elefluid.get_node_buffers(pos) + local pp = fluid_lib.get_node_buffers(pos) local changed = false @@ -171,18 +171,18 @@ minetest.register_abm({ for name in pairs(pp) do for bname in pairs(buffers) do if pumped >= pcapability then break end - local buffer_data = elefluid.get_buffer_data(srcpos, bname) - local target_data = elefluid.get_buffer_data(pos, name) + local buffer_data = fluid_lib.get_buffer_data(srcpos, bname) + local target_data = fluid_lib.get_buffer_data(pos, name) if (target_data.fluid == buffer_data.fluid or target_data.fluid == "") and buffer_data.fluid ~= "" and buffer_data.amount > 0 and (buffer_data.drainable == nil or buffer_data.drainable == true) and - elefluid.buffer_accepts_fluid(pos, name, buffer_data.fluid) then + fluid_lib.buffer_accepts_fluid(pos, name, buffer_data.fluid) then - if elefluid.can_insert_into_buffer(pos, name, buffer_data.fluid, pcapability) > 0 then - local res_f, count = elefluid.take_from_buffer(srcpos, bname, pcapability) + if fluid_lib.can_insert_into_buffer(pos, name, buffer_data.fluid, pcapability) > 0 then + local res_f, count = fluid_lib.take_from_buffer(srcpos, bname, pcapability) if count > 0 then - elefluid.insert_into_buffer(pos, name, res_f, count) + fluid_lib.insert_into_buffer(pos, name, res_f, count) pumped = pumped + count changed = true end diff --git a/elepower_farming/nodes/fluids.lua b/elepower_farming/nodes/fluids.lua index 39a3325..8465d13 100644 --- a/elepower_farming/nodes/fluids.lua +++ b/elepower_farming/nodes/fluids.lua @@ -237,24 +237,19 @@ minetest.register_node("elepower_farming:sludge_flowing", { sounds = default.node_sound_water_defaults(), }) --- Register buckets -local function bucket_construct(color) - return "bucket.png^(elefarming_bucket_mask.png^[multiply:"..color..")" -end - if minetest.get_modpath("bucket") ~= nil then bucket.register_liquid("elepower_farming:tree_sap_source", "elepower_farming:tree_sap_flowing", - "elepower_farming:bucket_tree_sap", bucket_construct("#411400"), "Tree Sap Bucket") + "elepower_farming:bucket_tree_sap", "#411400", "Tree Sap Bucket") bucket.register_liquid("elepower_farming:resin_source", "elepower_farming:resin_flowing", - "elepower_farming:bucket_resin", bucket_construct("#411401"), "Resin Bucket") + "elepower_farming:bucket_resin", "#411401", "Resin Bucket") bucket.register_liquid("elepower_farming:biomass_source", "elepower_farming:biomass_flowing", - "elepower_farming:bucket_biomass", bucket_construct("#002c01"), "Biomass Bucket") + "elepower_farming:bucket_biomass", "#002c01", "Biomass Bucket") bucket.register_liquid("elepower_farming:biofuel_source", "elepower_farming:biofuel_flowing", - "elepower_farming:bucket_biofuel", bucket_construct("#762700"), "Biofuel Bucket") + "elepower_farming:bucket_biofuel", "#762700", "Biofuel Bucket") bucket.register_liquid("elepower_farming:sludge_source", "elepower_farming:sludge_flowing", - "elepower_farming:bucket_sludge", bucket_construct("#121212"), "Sludge Bucket") + "elepower_farming:bucket_sludge", "#121212", "Sludge Bucket") end diff --git a/elepower_farming/nodes/tree_extractor.lua b/elepower_farming/nodes/tree_extractor.lua index 6982272..5fc628f 100644 --- a/elepower_farming/nodes/tree_extractor.lua +++ b/elepower_farming/nodes/tree_extractor.lua @@ -9,7 +9,7 @@ local fluid_table = { ["default:aspen_tree"] = { fpc = 50, fluid = "elepower_farming:resin_source" }, } -minetest.register_node("elepower_farming:tree_extractor", elefluid.add_bucket_handler({ +minetest.register_node("elepower_farming:tree_extractor", { description = "Tree Fluid Extractor", groups = {fluid_container = 1, oddly_breakable_by_hand = 1, cracky = 1}, tiles = { @@ -23,7 +23,7 @@ minetest.register_node("elepower_farming:tree_extractor", elefluid.add_bucket_ha } }, paramtype2 = "facedir" -})) +}) minetest.register_abm({ nodenames = {"elepower_farming:tree_extractor"}, diff --git a/elepower_farming/textures/elefarming_bucket_mask.png b/elepower_farming/textures/elefarming_bucket_mask.png deleted file mode 100644 index d913b214c39e12d5c645d3f38dd06f8654f480e2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5155 zcmeHLdsGu=77rB=sdPcyYVj2VR#7LJOhS^0L_oqLLVyxb&|Qy{$s|Pba%Lb2qODYE zX?=iLd?UVCeBrZt6kYIDQCLNE>!bMADr*te=elrYzX=F&m$mCT+y6*TlKJlUyT5zq z_uc!=O!5-qqP#r)JXtK3mm*r82!6epkB2+>9`UptW3l?^vyxKiM9j*zkY=skK(J}M zgjblANOdTM- z6<}&@zIprgu~QRmgM_KI{H#BW{HoTi&(qV%FN$Z1TQlySKQ`oO#ixVE&R>4_$2;}r zI>9gY#-E<3N-j@`vQPJY-Xu?5a%IXFf;*l8v};Svo^dq=E#C}X(wa5C=Cq-4UO(g2 zr9qV|TtvFV$D_-ar>?3HJYU%6Ri7?j|FAi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