elepower/elepower_farming/machines/tree_extractor.lua

76 lines
2.3 KiB
Lua
Raw Normal View History

2018-06-19 14:21:32 +00:00
-- see elepower_papi >> external_nodes_items.lua for explanation
-- shorten table ref
local epi = ele.external.ing
2018-06-19 14:21:32 +00:00
local CAPACITY = 8000
2018-06-19 18:08:28 +00:00
local fluid_table = {
[epi.tree] = { fpc = 100, fluid = "elepower_farming:tree_sap_source" },
[epi.jungle_tree] = { fpc = 50, fluid = "elepower_farming:resin_source" },
[epi.pine_tree] = { fpc = 100, fluid = "elepower_farming:resin_source" },
[epi.acacia_tree] = { fpc = 50, fluid = "elepower_farming:resin_source" },
[epi.aspen_tree] = { fpc = 50, fluid = "elepower_farming:resin_source" },
2018-06-19 18:08:28 +00:00
}
2018-06-20 14:09:28 +00:00
minetest.register_node("elepower_farming:tree_extractor", {
2018-06-19 18:08:28 +00:00
description = "Tree Fluid Extractor",
2018-06-19 14:21:32 +00:00
groups = {fluid_container = 1, oddly_breakable_by_hand = 1, cracky = 1},
tiles = {
"elefarming_machine_base.png", "elefarming_machine_base.png", "elefarming_machine_side.png",
"elefarming_machine_side.png", "elefarming_machine_side.png^elepower_power_port.png",
"elefarming_machine_tree_extractor.png",
},
fluid_buffers = {
2018-06-19 18:08:28 +00:00
tree = {
2018-06-19 14:21:32 +00:00
capacity = CAPACITY
}
},
2018-06-19 18:08:28 +00:00
paramtype2 = "facedir"
2018-06-20 14:09:28 +00:00
})
2018-06-19 14:21:32 +00:00
minetest.register_abm({
nodenames = {"elepower_farming:tree_extractor"},
2018-06-21 10:14:12 +00:00
label = "elefluidSapAccumulator",
interval = 8,
chance = 1/6,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local buffer = fluid_lib.get_buffer_data(pos, "tree")
if not buffer or buffer.amount == buffer.capacity then return end
2018-06-19 14:21:32 +00:00
2018-06-21 10:14:12 +00:00
local fpos = ele.helpers.face_front(pos, node.param2)
local amount = 0
local ftype = buffer.fluid
local fnode = minetest.get_node_or_nil(fpos)
2018-06-19 14:21:32 +00:00
if fnode and ele.helpers.get_item_group(fnode.name, "tree") then
2018-06-19 18:08:28 +00:00
local fdata = fluid_table[fnode.name]
if fdata and (ftype == "" or ftype == fdata.fluid) then
2018-06-21 10:14:12 +00:00
amount = fdata.fpc
2018-06-19 18:08:28 +00:00
ftype = fdata.fluid
end
2018-06-19 14:21:32 +00:00
end
2018-06-21 10:14:12 +00:00
if amount == 0 then
2018-06-19 14:21:32 +00:00
meta:set_string("infotext", "Place me in front of a tree!")
return
end
local give = 0
2018-06-21 10:14:12 +00:00
if buffer.amount + amount > buffer.capacity then
give = buffer.capacity - buffer.amount
2018-06-19 14:21:32 +00:00
else
2018-06-21 10:14:12 +00:00
give = amount
2018-06-19 14:21:32 +00:00
end
2018-06-21 10:14:12 +00:00
buffer.amount = buffer.amount + give
buffer.fluid = ftype
2018-06-19 14:21:32 +00:00
2018-06-21 10:14:12 +00:00
meta:set_int("tree_fluid_storage", buffer.amount)
meta:set_string("tree_fluid", buffer.fluid)
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
2018-06-19 14:21:32 +00:00
end
})
2018-08-24 19:36:15 +00:00
fluid_lib.register_node("elepower_farming:tree_extractor")