[Mod] Waterworks (pipes, pumps and valves) 0.1

[Mod] Waterworks (pipes, pumps and valves) 0.1

Postby FaceDeer » Mon Mar 25, 2019 3:22 am

This mod provides a set of nodes that allow large quantities of water to be pumped from one place to another, potentially over very long distances.

Important Note: The default behaviour of water in Minetest does not actually lend itself well to this kind of activity. In particular, default:water_source has liquid_renewable = true set in its node definition, which often causes new water nodes to be created where old ones are removed.

This mod includes an optional setting that disables liquid_renewable for default water, but for best effect it is highly recommended that this mod be used in conjunction with the dynamic_liquid mod.

The airtanks mod can also be helpful for players who are interested in doing large-scale underwater construction projects.

Also note: As of right now this mod is just at the "it's alive, it's ALIVE!" stage of development. I think all the parts are working right, but I haven't stress-tested everything under a variety of different conditions (and only in Minetest 5.0) and I haven't added crafting recipes yet. Let me know if you hit weird crashes or if anything about how the mod operates is unclear.

A pipe network is only active when a player is near one of the terminal nodes attached to it. The map blocks containing all terminal nodes for the network will be forceloaded as long as the pipe network is active, allowing water to be added or removed from remote locations, but note that water will be unable to flow into or out from those remote map blocks into adjoining blocks so it may behoove a player to visit these places to ensure continued flow.

Pipes

The core node type introduced by this mod is the pipe. When pipes are laid adjacent to each other they connect up to form a pipe network, to which inlets, outlets, and pumps can be connected. All contiguously pipes are part of the same network, and all terminal nodes connected to that network will be able to interact with each other.

Pipes automatically connect to other pipes through any of their six faces.

Terminals

Terminals can only be connected to a pipe network via one face, the side that by default is facing away from the player when they place the node in world. They interact with water only on the opposite face - the one facing toward the player when they place the node in world.

A screwdriver can be used to reorient terminals if you want one facing upward or downward.

The types of terminals in this mod are:

  • Inlets let water enter the pipe but not leave
  • Outlets let water out but not in
  • Grates let water flow either way depending on pressure
  • Pumps are inlets that force water into the network at a higher pressure than their elevation would normally give it.

Valves

A valve can be used to connect or disconnect sections of a pipe network with a simple right-click. When a valve is "open" it acts like a pipe section, and when it's "closed" it does not act like a pipe.

Elevation and pressure

The flow of water through the network is determined by two main factors; the directionality of each type of terminal, and the pressure of the water at that terminal.

Water flows from high pressure terminals to low pressure terminals. The rise and fall of the pipe in between those two terminals doesn't really matter, just the pressure at the terminals themselves.

The following figure illustrates the basics of how this works with a very simple three-terminal pipe network:

Image

The two terminals on the left side are "inlets", only permitting water to enter the network, and the terminal on the right is a grate that allows water in or out.

If terminal 1 were to be immersed in water, water nodes would be transferred from terminal 1 to terminal 2 because terminal 1's higher elevation gives it higher pressure than terminal 2. Water would not be transferred to terminal 3 as terminal 3 is an inlet only.

If terminal 2 were to be immersed, likewise no water would be transferred because although terminal 2 can allow water to enter the pipe (it's a grate) there are no valid outlet terminals it could go to.

If terminal 3 were immersed in water, no water would be transferred because terminal 2 is higher elevation and therefore there isn't enough pressure at terminal 3 to reach it.

Image

In this example terminal 3 is a pump, which acts as if it were an inlet located at an elevation 100 meters higher than it actually is. There are two potential outlets for water entering the system. Water is preferentially emitted from the lowest pressure outlet, so if terminal 3 was immersed in water it would be sent to terminal 2. However, if terminal 2 was contained in an enclosed space that had run out of room for additional water, the water would then be sent to the next-lowest outlet and come out of terminal 1.

If terminal 1 was immersed, then water would transfer from it to terminal 2. Terminal 3 is an inlet, so water wouldn't come out of it.

License

This mod is under the MIT license.

Links

FaceDeer
Member
 
Posts: 297
Joined: Sat Aug 29, 2015 7:01 pm
GitHub: FaceDeer

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby Brian Gaucher » Mon Mar 25, 2019 8:11 pm

Another idea: what if a terminal were to measure how much water is above it. Since realisticly, you would place your inlet at the bottom of the pond/river/etc, not one node below the top.
Brian Gaucher
Member
 
Posts: 58
Joined: Wed Jan 10, 2018 1:56 am
GitHub: BrianGaucher
In-game: Camasia

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby FaceDeer » Mon Mar 25, 2019 8:40 pm

I do take into account the depth of the water when calculating how high an outlet can "pile" it, but it's actually a somewhat complex and imprecise process determining how deep the water is so I am reluctant to record that value and rely on it for network-wide calculations.

Let me see if I can summarize the algorithms I settled on. It's hard to put into words so anyone coding-oriented may prefer to have a look at the methods "flood_search_outlet" and "find_source" in execute.lua. Pardon the inconsistent naming convention, tidying up the variable and function names is on my "to polish" list. :)

First the waterworks.execute_pipes method collects a list of all the inlets and all the outlets connected to a particular pipe network, and sorts them in order of pressure (when pumps aren't involved the "pressure" value is equivalent to the elevation of the node immediately touching the inlet or outlet grate, pumps add +100 to this value). Then it does a loop starting with the highest-pressure inlet and the lowest-pressure outlet and attempts to move water from one to the other if the inlet's pressure is higher than the outlet's pressure. This just determines whether it will *try* to move water, mind you.

Inlets select the node of water to move by doing a depth-first "random walk" search. Each step of the search loop will randomly move to neighboring water in the +X, -X, +Z, -Z or +Y direction - always upward or to the side, never downward, and never back into a node that it's already searched. Eventually the search will reach a node where all the neighbors are either non-water (air, stone, etc) or water that it's already searched. It then removes that node. The end result of this is that the search will seek out the surface of whatever body of water it's in, and will pick randomly so that if the inlet is at the bottom of a U-bend it will take water from both columns of the U-bend approximately equally. When it selects a node it records the actual elevation of that node and records that as its "actual" pressure.

The outlet then does a breadth-first flood-fill algorithm through the water at its outlet, looking for the nearest airspace. It is limited by the "actual" pressure of the node that was taken - it never places water at an elevation higher than the elevation it was taken from. It can place water higher than the *inlet's* elevation, but only if the water above the inlet is deeper.

So basically: I already take into account the depth of the water over the inlet when calculating the actual flow of water through the pipes, but not when determining whether to trigger that flow. I know this isn't 100% realistic, but it greatly reduces the amount of map-reading and increases the predictability of the system.

I can do some experimentation to see if I can find a better balance, though, if you're finding the mod's behaviour to be counterintuitive. For example, I could have inlets attempt to trigger even if they were a short distance below the outlet they were paired with. I think that would not cost a lot of extra computation and would make for a more natural pattern of flow.
FaceDeer
Member
 
Posts: 297
Joined: Sat Aug 29, 2015 7:01 pm
GitHub: FaceDeer

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby texmex » Mon Mar 25, 2019 8:42 pm

Interesting take on water handling, will definitely check out!
texmex
Member
 
Posts: 1284
Joined: Mon Jul 11, 2016 9:08 pm
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby rubenwardy » Mon Mar 25, 2019 9:06 pm

Does this use the node_io standard?
rubenwardy
Moderator
 
Posts: 5716
Joined: Tue Jun 12, 2012 6:11 pm
GitHub: rubenwardy
In-game: rubenwardy

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby FaceDeer » Mon Mar 25, 2019 9:13 pm

rubenwardy wrote:Does this use the node_io standard?


I wasn't aware of the node_io standard, so no. :) However, this mod doesn't actually use inventories for anything, water nodes teleport directly from the source to the destination and are not actually held "in transit" anywhere. Just taking a quick read of the node_io mod's description makes me wonder if it's really applicable, but I'll take a more in-depth look when I get home.

Even if not, perhaps it might be useful to define an inlet or outlet node that's intended to couple directly to a Pipeworks or Hopper? That might be a little odd, it'd inject "naked" water nodes into those systems rather than encapsulating them in buckets, but I could see circumstances where that might be wanted.

I plan to generalize this mod to work with all kinds of liquid, not just default:water, so that might make it easier to build an oil well or magma harvester or something. :)
FaceDeer
Member
 
Posts: 297
Joined: Sat Aug 29, 2015 7:01 pm
GitHub: FaceDeer

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby rubenwardy » Mon Mar 25, 2019 9:18 pm

Node io is useful for separating machines and networks. It means that people can make machines which don't depend on a particular transport method

See http://github.com/rubenwardy/oil
rubenwardy
Moderator
 
Posts: 5716
Joined: Tue Jun 12, 2012 6:11 pm
GitHub: rubenwardy
In-game: rubenwardy

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby FaceDeer » Mon Mar 25, 2019 9:37 pm

Oh, you've got an oil mod. I whipped one up as part of the df_caverns modpack, I should ensure compatibility between them (mine was designed as more of an environmental decoration/hazard rather than a raw material so there may not actually be much overlap). I recall doing a search to see if there was an existing oil mod, but looking at the dates on your repository I guess I just missed you. Sorry about that!

I'll review node_io. I've got a few other mods it might be applicable to as well.
FaceDeer
Member
 
Posts: 297
Joined: Sat Aug 29, 2015 7:01 pm
GitHub: FaceDeer

Re: [Mod] Waterworks (pipes, pumps and valves) 0.1

Postby GamingAssociation39 » Tue Mar 26, 2019 3:29 am

Would it be possible to make a tap to pull water through a one block node like dirt to get water as long as water is underneath
GamingAssociation39
Member
 
Posts: 803
Joined: Mon Apr 25, 2016 4:09 pm
GitHub: Gerold55
In-game: Gerold55



Return to WIP Mods



Who is online

Users browsing this forum: Yandex Bot [Bot] and 0 guests