Some API changes, add buckets to liquids..

This commit is contained in:
Evert Prants 2018-06-20 14:53:07 +03:00
parent 0e9ad60635
commit 4012bf27a8
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
12 changed files with 269 additions and 50 deletions

View File

@ -0,0 +1,19 @@
-- Fluid bar for formspec
function ele.formspec.fluid_bar(x, y, fluid_buffer)
local texture = "default_water.png"
local metric = 0
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
metric = math.floor(100 * fluid_buffer.amount / fluid_buffer.capacity)
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]"
end

View File

@ -11,4 +11,5 @@ elefluid.unit_description = "milli-bucket"
dofile(modpath.."/transfer.lua") dofile(modpath.."/transfer.lua")
dofile(modpath.."/transfer_node.lua") dofile(modpath.."/transfer_node.lua")
dofile(modpath.."/formspec.lua")
dofile(modpath.."/buffer.lua") dofile(modpath.."/buffer.lua")

View File

@ -61,7 +61,7 @@ local function traverse_network(targets, all_nodes, pos, p_pos, pnodeid, queue)
end end
end end
local function fluid_targets(p_pos, positions) local function fluid_targets(p_pos, pos)
local provider = minetest.get_node(p_pos) local provider = minetest.get_node(p_pos)
local pnodeid = minetest.pos_to_string(p_pos) local pnodeid = minetest.pos_to_string(p_pos)
--[[ --[[
@ -74,9 +74,6 @@ local function fluid_targets(p_pos, positions)
local queue = {} local queue = {}
local all_nodes = {} local all_nodes = {}
for pos in pairs(positions) do
queue = {}
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
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)
@ -92,7 +89,6 @@ local function fluid_targets(p_pos, positions)
end end
queue = to_visit queue = to_visit
end end
end
local prov_id = minetest.hash_node_position(p_pos) local prov_id = minetest.hash_node_position(p_pos)
elefluid.graphcache.nodes[prov_id] = pnodeid elefluid.graphcache.nodes[prov_id] = pnodeid
@ -119,35 +115,25 @@ minetest.register_abm({
local meta1 = nil local meta1 = nil
local targets = {} local targets = {}
local source = minetest.registered_nodes[node.name]
local positions = {vector.add(minetest.facedir_to_dir(node.param2), pos)} -- 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 ntwks = {} local tname = minetest.get_node(tpos).name
local errored = false if not ele.helpers.get_item_group(tname, "elefluid_transport") and
local nw_branches = 0 not ele.helpers.get_item_group(tname, "fluidity_tank") and
for _,pos1 in pairs(positions) do not ele.helpers.get_item_group(tname, "fluid_container") then
local name = node.name
local networked = ele.helpers.get_item_group(name, "elefluid_transport_source") or
ele.helpers.get_item_group(name, "elefluid_transport")
if networked then
ntwks[pos1] = true
nw_branches = nw_branches + 1
end
end
if errored then
return
end
if nw_branches == 0 then
minetest.forceload_free_block(pos) minetest.forceload_free_block(pos)
return return
else
minetest.forceload_block(pos)
end end
targets = fluid_targets(pos, ntwks) -- Retrieve network
minetest.forceload_block(pos)
targets = fluid_targets(pos, tpos)
-- No targets, don't proceed
if #targets == 0 then
return
end
-- Begin transfer -- Begin transfer
local srcpos = ele.helpers.face_front(pos, node.param2) local srcpos = ele.helpers.face_front(pos, node.param2)
@ -169,11 +155,14 @@ minetest.register_abm({
local buffers = elefluid.get_node_buffers(srcpos) local buffers = elefluid.get_node_buffers(srcpos)
if not buffers then return nil end if not buffers then return nil end
-- 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")
local pumped = 0
-- Transfer some fluid here -- Transfer some fluid here
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
local pp = elefluid.get_node_buffers(pos) local pp = elefluid.get_node_buffers(pos)
local changed = false local changed = false
@ -181,17 +170,20 @@ minetest.register_abm({
if pp ~= nil then if pp ~= nil then
for name in pairs(pp) do for name in pairs(pp) do
for bname in pairs(buffers) do for bname in pairs(buffers) do
if pumped >= pcapability then break end
local buffer_data = elefluid.get_buffer_data(srcpos, bname) local buffer_data = elefluid.get_buffer_data(srcpos, bname)
local target_data = elefluid.get_buffer_data(pos, name) local target_data = elefluid.get_buffer_data(pos, name)
if (target_data.fluid == buffer_data.fluid or target_data.fluid == "") and if (target_data.fluid == buffer_data.fluid or target_data.fluid == "") and
buffer_data.fluid ~= "" and buffer_data.amount > 0 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 elefluid.buffer_accepts_fluid(pos, name, buffer_data.fluid) then
if elefluid.can_insert_into_buffer(pos, name, buffer_data.fluid, pcapability) > 0 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) local res_f, count = elefluid.take_from_buffer(srcpos, bname, pcapability)
if count > 0 then if count > 0 then
elefluid.insert_into_buffer(pos, name, res_f, count) elefluid.insert_into_buffer(pos, name, res_f, count)
pumped = pumped + count
changed = true changed = true
end end
end end

View File

@ -37,3 +37,21 @@ function elefarm.formspec.harvester_formspec(timer, power)
"listring[current_player;main]".. "listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25) default.get_hotbar_bg(0, 4.25)
end end
function elefarm.formspec.tree_processor(timer, power, fluid_buffer, water_buffer, output_buffer)
return "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
ele.formspec.power_meter(power)..
bar(1, 0, 100-timer)..
ele.formspec.fluid_bar(2, 0, fluid_buffer)..
ele.formspec.fluid_bar(3, 0, water_buffer)..
ele.formspec.fluid_bar(7, 0, output_buffer)..
"list[context;dst;5,1;1,1;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[context;dst]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end

View File

@ -1,3 +1,4 @@
name = elepower_farming name = elepower_farming
description = Electric Farming Automation! description = Electric Farming Automation!
depends = elepower_papi, elepower_tools, farming depends = elepower_papi, elepower_tools, farming
optional_depends = bucket

View File

@ -19,7 +19,7 @@ minetest.register_node("elepower_farming:tree_sap_source", {
liquid_alternative_flowing = "elepower_farming:tree_sap_flowing", liquid_alternative_flowing = "elepower_farming:tree_sap_flowing",
liquid_viscosity = 7, liquid_viscosity = 7,
post_effect_color = {a = 103, r = 84, g = 34, b = 0}, post_effect_color = {a = 103, r = 84, g = 34, b = 0},
groups = {tree_sap = 3, liquid = 3}, groups = {tree_sap = 3, liquid = 3, raw_bio = 1, tree_fluid = 1},
sounds = default.node_sound_water_defaults(), sounds = default.node_sound_water_defaults(),
}) })
@ -67,7 +67,7 @@ minetest.register_node("elepower_farming:resin_source", {
liquid_alternative_flowing = "elepower_farming:resin_flowing", liquid_alternative_flowing = "elepower_farming:resin_flowing",
liquid_viscosity = 8, liquid_viscosity = 8,
post_effect_color = {a = 103, r = 84, g = 34, b = 0}, post_effect_color = {a = 103, r = 84, g = 34, b = 0},
groups = {resin = 3, liquid = 3}, groups = {resin = 3, liquid = 3, raw_bio = 1, tree_fluid = 1},
sounds = default.node_sound_water_defaults(), sounds = default.node_sound_water_defaults(),
}) })
@ -236,3 +236,25 @@ minetest.register_node("elepower_farming:sludge_flowing", {
groups = {sludge = 3, liquid = 3, not_in_creative_inventory = 1}, groups = {sludge = 3, liquid = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_water_defaults(), 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")
bucket.register_liquid("elepower_farming:resin_source", "elepower_farming:resin_flowing",
"elepower_farming:bucket_resin", bucket_construct("#411401"), "Resin Bucket")
bucket.register_liquid("elepower_farming:biomass_source", "elepower_farming:biomass_flowing",
"elepower_farming:bucket_biomass", bucket_construct("#002c01"), "Biomass Bucket")
bucket.register_liquid("elepower_farming:biofuel_source", "elepower_farming:biofuel_flowing",
"elepower_farming:bucket_biofuel", bucket_construct("#762700"), "Biofuel Bucket")
bucket.register_liquid("elepower_farming:sludge_source", "elepower_farming:sludge_flowing",
"elepower_farming:bucket_sludge", bucket_construct("#121212"), "Sludge Bucket")
end

View File

@ -1,6 +1,10 @@
-- How many seconds there are between runs
local HARVESTER_TICK = 10 local HARVESTER_TICK = 10
-- How many plants we can collect in one run
local HARVESTER_SWEEP = 9
local function can_dig(pos, player) local function can_dig(pos, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -36,7 +40,7 @@ local function harvest(pos, harvested, fdir)
local range_st = vector.add(front, ranges[1]) local range_st = vector.add(front, ranges[1])
local range_end = vector.add(front, ranges[2]) local range_end = vector.add(front, ranges[2])
local shots = 9 local shots = HARVESTER_SWEEP
for x = range_st.x, range_end.x do for x = range_st.x, range_end.x do
for z = range_st.z, range_end.z do for z = range_st.z, range_end.z do

View File

@ -3,3 +3,4 @@ dofile(elefarm.modpath.."/nodes/planter.lua")
dofile(elefarm.modpath.."/nodes/harvester.lua") dofile(elefarm.modpath.."/nodes/harvester.lua")
dofile(elefarm.modpath.."/nodes/fluids.lua") dofile(elefarm.modpath.."/nodes/fluids.lua")
dofile(elefarm.modpath.."/nodes/tree_extractor.lua") dofile(elefarm.modpath.."/nodes/tree_extractor.lua")
dofile(elefarm.modpath.."/nodes/tree_processor.lua")

View File

@ -1,6 +1,8 @@
local PLANTER_TICK = 5 -- How many seconds there are between runs
local PLANTER_TICK = 10
-- Growth regions for configured crops
local ranges = { local ranges = {
-- Slot 1 (starts from upper left corner) -- Slot 1 (starts from upper left corner)
{ {
@ -170,9 +172,9 @@ local function plant(pos, range, stack, inv)
minetest.set_node(place_pos, {name = to_place}) minetest.set_node(place_pos, {name = to_place})
else else
local seeddef = minetest.registered_items[to_plant] local seeddef = minetest.registered_items[to_plant]
local nodename = seeddef.next_plant or (to_plant .. "_1"):gsub("seed_", "")
farming.place_seed(to_plant, nil, {type = "node", under = base_pos, above = place_pos}, seeddef.on_place(ItemStack(to_plant), nil,
nodename) {type = "node", under = base_pos, above = place_pos})
take = to_plant take = to_plant
end end

View File

@ -0,0 +1,159 @@
local tree_fluid_recipes = {
["elepower_farming:tree_sap_source"] = {
water = 100,
amount = 100,
time = 5,
output = {
fluid = "elepower_farming:biofuel_source",
amount = 80,
},
},
["elepower_farming:resin_source"] = {
water = 100,
amount = 100,
time = 5,
output = {
fluid = "elepower_farming:biomass_source",
amount = 80,
item = "elepower_farming:resin"
},
},
}
local function on_timer(pos, elapsed)
local refresh = false
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local tree_buffer = elefluid.get_buffer_data(pos, "tree")
local water_buffer = elefluid.get_buffer_data(pos, "water")
local out_buffer = elefluid.get_buffer_data(pos, "output")
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local storage = ele.helpers.get_node_property(meta, pos, "storage")
local usage = ele.helpers.get_node_property(meta, pos, "usage")
local time = meta:get_int("src_time")
local time_max = meta:get_int("src_time_max")
local recipe = tree_fluid_recipes[tree_buffer.fluid]
while true do
if not recipe then
break
end
local conditions = water_buffer.amount >= recipe.water and
tree_buffer.amount >= recipe.amount and
out_buffer.amount + recipe.output.amount < out_buffer.capacity and
storage > usage and
(out_buffer.fluid == "" or out_buffer.fluid == recipe.output.fluid)
if not conditions then
break
end
if time_max == 0 then
time_max = recipe.time
meta:set_int("src_time_max", time_max)
refresh = true
break
end
storage = storage - usage
meta:set_int("storage", storage)
if time < time_max then
time = time + 1
meta:set_int("src_time", time)
refresh = true
end
if time ~= time_max then
break
end
if recipe.output.item then
local room_for_output = true
local stack = ItemStack(recipe.output.item)
inv:set_size("dst_tmp", inv:get_size("dst"))
inv:set_list("dst_tmp", inv:get_list("dst"))
if not inv:room_for_item("dst_tmp", stack) then
room_for_output = false
else
inv:add_item("dst_tmp", stack)
end
if not room_for_output then
break
end
inv:set_list("dst", inv:get_list("dst_tmp"))
end
local new_tree_amount = tree_buffer.amount - recipe.amount
meta:set_int("tree_fluid_storage", new_tree_amount)
meta:set_int("output_fluid_storage", out_buffer.amount + recipe.output.amount)
meta:set_int("water_fluid_storage", water_buffer.amount - recipe.water)
if new_tree_amount == 0 then
tree_buffer.fluid = ""
end
meta:set_string("tree_fluid", tree_buffer.fluid)
meta:set_string("output_fluid", recipe.output.fluid)
meta:set_int("src_time", 0)
meta:set_int("src_time_max", 0)
refresh = true
break
end
local timer = 0
local power = math.floor(100 * storage / capacity)
if time_max > 0 then
timer = math.floor(100 * time / time_max)
end
meta:set_string("formspec", elefarm.formspec.tree_processor(timer, power, tree_buffer, water_buffer, out_buffer))
return refresh
end
ele.register_machine("elepower_farming:tree_processor", {
description = "Tree Fluid Processor",
ele_usage = 8,
ele_no_automatic_ports = true,
groups = {ele_user = 1, oddly_breakable_by_hand = 1, cracky = 1, fluid_container = 1},
fluid_buffers = {
tree = {
capacity = 8000,
accepts = {"group:tree_fluid"}
},
water = {
capacity = 8000,
accepts = {"default:water_source"}
},
output = {
capacity = 8000
}
},
on_timer = on_timer,
on_construct = function (pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("dst", 1)
meta:set_string("formspec", elefarm.formspec.tree_processor(0, 0))
meta:set_string("tree_fluid", "elepower_farming:resin_source")
meta:set_int("tree_fluid_storage", 2000)
end,
tiles = {
"elefarming_machine_tree_processor.png", "elefarming_machine_base.png", "elefarming_machine_side.png",
"elefarming_machine_side.png", "elefarming_machine_side.png", "elefarming_machine_side.png",
},
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB