Compare commits

...

5 Commits

Author SHA1 Message Date
Sirrobzeroone
5b7d61d7d9 Improved/more accurate Fluid_Pump Status's
had my afluid/bfluid understanding around the wrong way
2021-09-28 22:01:44 +10:00
Sirrobzeroone
2aabe9240d remove old line of code
too late at night.....
2021-09-27 22:55:54 +10:00
Sirrobzeroone
a703b07871 puncher not player 2021-09-27 22:53:28 +10:00
Sirrobzeroone
dfa0dc4a7b Adding Fluid_Pump Infotext 2021-09-27 20:55:14 +10:00
Sirrobzeroone
7286b55804 use_texture_alpha update from boolean to value 2021-06-10 20:34:38 +10:00
3 changed files with 49 additions and 10 deletions

View File

@ -34,6 +34,7 @@ function fluid_lib.register_extractor_node(nodename, nodedef)
nodedef.on_punch = function (pos, node, puncher, pointed_thing)
minetest.get_node_timer(pos):start(1.0)
minetest.chat_send_player(puncher:get_player_name(),"Pump Started")
minetest.node_punch(pos, node, puncher, pointed_thing)
end

View File

@ -124,12 +124,13 @@ end
function fluid_lib.transfer_timer_tick(pos, elapsed)
local refresh = true
local node = minetest.get_node_or_nil(pos)
local status = "Fluid Pump"
if not node then
return false
end
local meta = minetest.get_meta(pos)
local targets = {}
-- Only allow the node directly behind to be a start of a network
@ -144,9 +145,9 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
-- Retrieve network
targets = fluid_targets(pos, tpos)
-- No targets, don't proceed
if #targets == 0 then
meta:set_string("infotext", status.."\nNo Recieving Tank")
return true
end
@ -156,6 +157,7 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
-- Make sure source node is not air
if not srcnode or srcnode.name == "air" then
meta:set_string("infotext", status.."\nNo Source Tank")
return true
end
@ -163,11 +165,15 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
-- Make sure source node is a registered fluid container
if not srcdef or not srcdef['node_io_can_take_liquid'] then
meta:set_string("infotext", status.." Off")
return false
end
local c = srcdef.node_io_can_take_liquid(srcpos, srcnode, "")
if not c then return false end
if not c then
meta:set_string("infotext", status.." Off")
return false
end
local srcmeta = minetest.get_meta(srcpos)
local fl_size = srcdef.node_io_get_liquid_size(srcpos, srcnode, "")
@ -175,7 +181,10 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
for i = 1, fl_size do
buffers[i] = srcdef.node_io_get_liquid_name(srcpos, srcnode, "", i)
end
if not #buffers then return true end
if not #buffers then
meta:set_string("infotext", status.."\nNo Source Tank")
return true
end
-- Limit the amount of fluid pumped per cycle
local pcapability = get_node_property(meta, pos, "fluid_pump_capacity")
@ -184,7 +193,9 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
-- Transfer some fluid here
for _,pos in pairs(targets) do
if not vector.equals(pos, srcpos) then
if pumped >= pcapability then break end
local destnode = minetest.get_node(pos)
local destdef = minetest.registered_nodes[destnode.name]
local pp = nil
@ -203,24 +214,48 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
local changed = false
if pp ~= nil then
for bindex,bfluid in pairs(pp) do
for aindex,afluid in pairs(buffers) do
if pumped >= pcapability then break end
if (afluid == bfluid or bfluid == "") then
local idef = destdef.node_io_room_for_liquid(pos, destnode, "", afluid, pcapability)
for bindex,bfluid in pairs(pp) do -- bfluid = destination fluid name
for aindex,afluid in pairs(buffers) do -- afluid = source fluid name
-- get fluid names for pump status
local bfluid_des = ""
local afluid_des = ""
if bfluid ~= "" then
bfluid_des = minetest.registered_nodes[bfluid].description
end
if afluid ~= "" then
afluid_des = minetest.registered_nodes[afluid].description
end
if pumped >= pcapability then
meta:set_string("infotext", status.."\nPumped Max Volume".." "..bfluid_des)
break
end
if (afluid == bfluid or bfluid == "") then -- bfluid = "", empty destiniation
local idef = destdef.node_io_room_for_liquid(pos, destnode, "", afluid, pcapability)
if idef > 0 then
local fluidcount = srcdef.node_io_get_liquid_stack(srcpos, srcnode, "", aindex):get_count()
local defc = math.min(fluidcount, idef)
local defi = srcdef.node_io_take_liquid(srcpos, srcnode, "", nil, afluid, defc)
if defi and defi.millibuckets > 0 then
local lo = destdef.node_io_put_liquid(pos, destnode, "", nil, afluid, defi.millibuckets)
pumped = pumped + (defi.millibuckets - lo)
meta:set_string("infotext", status.."\nPumping "..afluid_des)
changed = true
end
else
meta:set_string("infotext", status.."\nStandby")
end
end
end
end
else
meta:set_string("infotext", status.."\nStandby")
end
if changed then
@ -229,7 +264,7 @@ function fluid_lib.transfer_timer_tick(pos, elapsed)
end
end
end
return refresh
end

View File

@ -2,6 +2,7 @@
fluid_lib.register_extractor_node("fluid_transfer:fluid_transfer_pump", {
description = "Fluid Transfer Pump\nPunch to start pumping",
tiles = {"fluid_transfer_pump.png"},
use_texture_alpha = "clip",
drawtype = "mesh",
mesh = "fluid_transfer_pump.obj",
groups = {oddly_breakable_by_hand = 1, cracky = 1},
@ -18,6 +19,7 @@ fluid_lib.register_extractor_node("fluid_transfer:fluid_transfer_pump", {
fluid_lib.register_transfer_node("fluid_transfer:fluid_duct", {
description = "Fluid Duct",
tiles = {"fluid_transfer_duct.png"},
use_texture_alpha = "clip",
groups = {oddly_breakable_by_hand = 1, cracky = 1}
})
@ -26,6 +28,7 @@ minetest.register_node("fluid_transfer:fluid_trash", {
drawtype = "mesh",
mesh = "fluid_transfer_trash.obj",
tiles = {"fluid_transfer_trash.png"},
use_texture_alpha = "clip",
groups = {oddly_breakable_by_hand = 1, cracky = 1, fluid_container = 1},
node_io_can_put_liquid = function (pos, node, side)
return true