[Tutorial 1.16.5] Fluid Pipes quick overview

Started by Shadetree on Wed, 10/27/2021 - 08:00

Topic category: User side tutorials

Last seen on 14:31, 5. Dec 2021
Joined Oct 2020

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[Tutorial 1.16.5] Fluid Pipes quick overview
Wed, 10/27/2021 - 08:55 (edited)

A little background

As I was updating my mod Microcosm I wanted farmhouses to be supplied with water from the closest well connected to my path blocks.

I looked around all over for tutorials and either missed them or no ones covered them yet.

The path blocks are modified from NorthWestTree's fence tutorial to make them connect together.  Thanks so much for that tutorial!  This should work without that though.

These pipes only work horizontally for my purposes., I'm sure they can be modified to go up and down as well but as my Great Grandpa Mobius use to say, "Not my Dimension, Not my Problem!"  Conversations with him tended to be one-sided.

I can include procedure snippets but I wanted to get this down before I forget what I did. 

Relevant Blocks:
Producer: fills >1 fluid NSWE direction on update tick
Consumer: A block with a fluid tank, however large you want.
Pipe(s): The meat.  has a tank that is at least slightly greater than 3 times the output you would like. OnTick Procedure detailed below


Pipe OnTick Procedure: AKA a very short description of a fairly long procedure.

If next to a producer, set a nbt number tag to 1. 
Else get the lowest nbt number tag of your neighbors that is also greater than 0. and set the nbt tag to that lowest number +1*

I'd suggest binding a gui to the pipe block(s) that has a text label that will display this nbt number for debugging purposes.  I'd also throw a <fluidLevel> on it as well.
What this ends up doing is creating "shortest paths" along your pipes and basically designating which side is the input.  This will change as you place more pipes.

If you have 3x your max output or more in your tank then:

If the nbt number tag of your neighbor is higher than your own, AND it has less fluid in it's tank than yours, OR Just if its a Consumer:
Test sending your max output, get result, Send that much to that guy and drain that much from your own tank.

Repeat the above for all your neighbors.


That's it.

If the pipe has no branches on its way to your consumer it will fill up the first pipe and start pushing max output to the next every tick, three ticks later that pipe will start pushing.  etc.  If it reaches a 2 or 3 way split, it will take that many ticks to push max output to the pipes.  It will travel down the line like this and start filling consumers even before the internal tanks in your pipes fill up, if you have larger tanks than needed that is.  So the more Consumers and branches on a specific pipeline the slower things will be to get to the end of the line but for my purposes that is what I wanted.

Since it basically follows the shortest path to each consumer only the closest producer will supply a consumer, unless carefully arranged or separate pipelines to different sides.

If you break the Producer.  sometimes the pipes nbt number will start to go up every tick (mine do it if a path travels for any distance east of the well.)  this could be due to my poor implementation of NorthWestTree's fence code.  I cover this up by setting a max pipe length.  if the nbt number goes above 100 I just reset it to 0. It leaves me with some pipes at 0 and some at 100.  I make em spew water particles as they slowly drain if they still have water in their tanks. So... uhm... working as intended. 

Making the producer have a slower tick speed but fill adjacent pipes with more is the route I went. Every little bit helps.
I haven't tested with working the number system backwards from the Consumers instead of from the Producer. Or starting at the producer with max pipe length and working down to the consumer. except in my head. and thats not a place I like to dwell. I really like the aesthetic of "flowing down" the pipes from higher to lower numbers but my intuition tells me it'll break somehow.

*The logic I had to use to find the lowest number of four neighbors that also was greater than 0 broke me but I'm not a coder.  It can probably be improved.

If you have questions, criticism, suggestions, want to see the code for specific bits, or whatever.  I welcome it all.

I'm planning to release the version of Microcosm that has this implemented this Friday.



Edited by Shadetree on Wed, 10/27/2021 - 08:55