Add a water accumulator node, disable fluid network caching temporarily

This commit is contained in:
Evert Prants 2018-06-19 10:16:43 +03:00
parent b11ec4a220
commit 8c1622c52a
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
6 changed files with 77 additions and 3 deletions

View File

@ -64,12 +64,12 @@ end
local function fluid_targets(p_pos, positions)
local provider = minetest.get_node(p_pos)
local pnodeid = minetest.pos_to_string(p_pos)
--[[
if elefluid.graphcache[pnodeid] then
local cached = elefluid.graphcache[pnodeid]
return cached.targets
end
]]
local targets = {}
local queue = {}
local all_nodes = {}
@ -111,7 +111,7 @@ end
minetest.register_abm({
nodenames = {"group:elefluid_transport_source"},
label = "elefluitFluidGraphSource",
label = "elefluidFluidGraphSource",
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
@ -231,6 +231,11 @@ local function check_connections(pos)
return connections
end
function elefluid.clear_networks(pos)
return
end
--[[
-- Update networks when a node has been placed or removed
function elefluid.clear_networks(pos)
local node = minetest.get_node(pos)
@ -313,3 +318,4 @@ function elefluid.clear_networks(pos)
end
end
end
]]

View File

@ -9,6 +9,7 @@ function elefluid.register_transfer_node(nodename, nodedef)
nodedef.groups["elefluid_transport_source"] = 1
nodedef.paramtype2 = "facedir"
nodedef.legacy_facedir_simple = true
local orig_construct = nodedef.on_construct
nodedef.on_construct = function (pos)

View File

@ -10,4 +10,5 @@ dofile(modpath.."/craft.lua")
dofile(modpath.."/formspec.lua")
dofile(modpath.."/bases/init.lua")
dofile(modpath.."/nodes.lua")
dofile(modpath.."/special/init.lua")
dofile(modpath.."/register.lua")

View File

@ -0,0 +1,64 @@
local CAPACITY = 8000
minetest.register_node("elepower_machines:accumulator", {
description = "Water Accumulator",
groups = {fluid_container = 1, oddly_breakable_by_hand = 1, cracky = 1},
tiles = {
"elepower_machine_top.png^elepower_power_port.png", "elepower_machine_base.png", "elepower_machine_accumulator.png",
"elepower_machine_accumulator.png", "elepower_machine_accumulator.png", "elepower_machine_accumulator.png",
},
fluid_buffers = {
water = {
capacity = CAPACITY
}
},
on_construct = function ( pos )
local meta = minetest.get_meta(pos)
meta:set_string("water_fluid", "default:water_source")
end
})
minetest.register_abm({
nodenames = {"elepower_machines:accumulator"},
label = "elefluidAccumulator",
interval = 2,
chance = 1/5,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local water_c = meta:get_int("water_fluid_storage")
if water_c == CAPACITY then return end
local positions = {
{x=pos.x+1,y=pos.y,z=pos.z},
{x=pos.x-1,y=pos.y,z=pos.z},
{x=pos.x, y=pos.y,z=pos.z+1},
{x=pos.x, y=pos.y,z=pos.z-1},
}
local fluid = 0
for _,fpos in pairs(positions) do
local node = minetest.get_node(fpos)
if node.name == "default:water_source" then
fluid = fluid + 1000
end
end
if fluid == 0 then
meta:set_string("infotext", "Submerge me in water!")
return
end
local give = 0
if water_c + fluid > CAPACITY then
give = CAPACITY - water_c
else
give = fluid
end
water_c = water_c + give
meta:set_int("water_fluid_storage", water_c)
meta:set_string("infotext", ("Water: %d/%d %s"):format(water_c, CAPACITY, elefluid.unit))
end
})

View File

@ -0,0 +1,2 @@
dofile(elepm.modpath.."/special/accumulator.lua")

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB