2018-06-19 14:21:32 +00:00
|
|
|
|
|
|
|
local CAPACITY = 8000
|
|
|
|
|
2018-06-19 18:08:28 +00:00
|
|
|
local fluid_table = {
|
|
|
|
["default:tree"] = { fpc = 100, fluid = "elepower_farming:tree_sap_source" },
|
|
|
|
["default:jungletree"] = { fpc = 50, fluid = "elepower_farming:resin_source" },
|
|
|
|
["default:pine_tree"] = { fpc = 100, fluid = "elepower_farming:resin_source" },
|
|
|
|
["default:acacia_tree"] = { fpc = 50, fluid = "elepower_farming:resin_source" },
|
|
|
|
["default:aspen_tree"] = { fpc = 50, fluid = "elepower_farming:resin_source" },
|
|
|
|
}
|
|
|
|
|
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"},
|
|
|
|
label = "elefluidSapAccumulator",
|
|
|
|
interval = 8,
|
|
|
|
chance = 1/6,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-06-19 18:08:28 +00:00
|
|
|
local fluid_c = meta:get_int("tree_fluid_storage")
|
|
|
|
if fluid_c == CAPACITY then return end
|
2018-06-19 14:21:32 +00:00
|
|
|
|
|
|
|
local fpos = ele.helpers.face_front(pos, node.param2)
|
|
|
|
local fluid = 0
|
2018-06-19 18:08:28 +00:00
|
|
|
local ftype = meta:get_string("tree_fluid")
|
|
|
|
local fname = "Tree Sap"
|
2018-06-19 14:21:32 +00:00
|
|
|
local fnode = minetest.get_node_or_nil(fpos)
|
|
|
|
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
|
|
|
|
fluid = fdata.fpc
|
|
|
|
ftype = fdata.fluid
|
|
|
|
fname = minetest.registered_nodes[ftype].description:gsub(" Source", "")
|
|
|
|
end
|
2018-06-19 14:21:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if fluid == 0 then
|
|
|
|
meta:set_string("infotext", "Place me in front of a tree!")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local give = 0
|
2018-06-19 18:08:28 +00:00
|
|
|
if fluid_c + fluid > CAPACITY then
|
|
|
|
give = CAPACITY - fluid_c
|
2018-06-19 14:21:32 +00:00
|
|
|
else
|
|
|
|
give = fluid
|
|
|
|
end
|
|
|
|
|
2018-06-19 18:08:28 +00:00
|
|
|
fluid_c = fluid_c + give
|
2018-06-19 14:21:32 +00:00
|
|
|
|
2018-06-19 18:08:28 +00:00
|
|
|
meta:set_int("tree_fluid_storage", fluid_c)
|
|
|
|
meta:set_string("tree_fluid", ftype)
|
|
|
|
meta:set_string("infotext", ("%s: %d/%d %s"):format(fname, fluid_c, CAPACITY, elefluid.unit))
|
2018-06-19 14:21:32 +00:00
|
|
|
end
|
|
|
|
})
|