Depend on fluid_lib.
This commit is contained in:
parent
8cdd2ec47f
commit
4f184e2325
@ -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
|
@ -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
|
@ -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")
|
||||
|
@ -1,4 +1,3 @@
|
||||
name = elepower_fapi
|
||||
description = Elepower Fluid Transfer API
|
||||
depends = elepower_papi
|
||||
optional_depends = fluidity,bucket
|
||||
depends = elepower_papi,fluid_lib
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"},
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.0 KiB |
Loading…
Reference in New Issue
Block a user