Pipe connections problems

Place to get help with not working mods / modding interface.
User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Pipe connections problems

Post by Linver »

Hi again to all,
I'm one of authors of this mod:
https://mods.factorio.com/mod/FluidMustFlow
I have problems with define the pipe connections position, sometimes I receive a report that the fluid boxes of the entities added by this mod will not connect to other entities, I don't understand how is the correct way to define the pipe connections position, for example:

This entity is 2x2 and have 8 pipe connections, I have try define position 0.4 0.5 0.6... always bugs:

Code: Select all

	collision_box = {{-0.75, -0.75}, {0.75, 0.75}}
	...
	selection_box = {{-1, -1}, {1, 1}}
	...
	pipe_connections =	
	{
		{ position = {0.5, -1.5}, type="input" },
		{ position = {-0.5, -1.5}, type="input" },
		{ position = {0.6, 1.6}, type="output" },
		{ position = {-0.6, 1.6}, type="output" },
		{ position = {1.5, -0.5}, type="input" },
		{ position = {1.5, 0.5}, type="input" },
		{ position = {-1.5, -0.5}, type="input" },
		{ position = {-1.5, 0.5}, type="input" }
	},
	...
Most of vanilla fluid boxes jump from 0.5 in 0.5, but trying that don't work too.

Thanks to all in advance for the answer.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Pipe connections problems

Post by darkfrei »

For entities 2x2 must be

Code: Select all

pipe_connections =
  {
    { position = { 0.5, -1.5} },
    { position = { 0.5,  1.5} },
    { position = {-0.5, -1.5} },
    { position = {-0.5,  1.5} },
    { position = { 1.5, -0.5} },
    { position = { 1.5,  0.5} },
    { position = {-1.5, -0.5} },
    { position = {-1.5,  0.5} }
  }

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

And will not work how I said, look this code (a piece):

Code: Select all

	...
	pipe_connections =	
	{
		{ position = {0.5, -1.5}, type="input" },
		{ position = {-0.5, -1.5}, type="input" },
		{ position = {0.5, 1.5}, type="output" },
		{ position = {-0.5, 1.5}, type="output" },
		{ position = {1.5, -0.5}, type="input" },
		{ position = {1.5, 0.5}, type="input" },
		{ position = {-1.5, -0.5}, type="input" },
		{ position = {-1.5, 0.5}, type="input" }
	},
	...
This is the result:
Image

But if i change all x.5 to x.6 will work for SOME entities.
If you don't believe me the file is in .../FluidMustFlow/prototypes/entity/ducts_end_points.lua, you could test this too your self

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Pipe connections problems

Post by PyroFire »

Can you please post any errors you're receiving, and/or describe the bugs that you're encountering - as in, what is and is not working?
"Always bugs" doesn't really tell us anything.

This will help us help you better.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Hi PyroFire,
the problem is that I don't know how describe more in detail this problem. I have this two pump added by the mod, that entities is a pump and use the pump prototype, with some entities is supposed that the fluid boxes of modded entities (this pumps) and other entities placed near to the sides will connect together, this with not always happen and I haven't any tool to understand or documentation to find this problem. I suppose that is a problem about the pipe connections, because changing the number will connect to some entities, but if I set all pipe connections like the vanilla standard, from 0.5 to 0.5, they will connect to some entities but not with all.

PS: Look my answer to darkfrei too for got a picture of the problem.

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Pipe connections problems

Post by Bilka »

To illustrate: The pump accepts/doesn't accept fluid depending on build order:

I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Ok how to reproduce the bug:
Download the mod version 1.0.3 (so FluidMustFlow_1.0.3), place some vanilla pipes like this:
Image
Now, with a creative mode get a duct end point intake pump entity (internal name "duct-end-point-intake-south") and place it near the pipes like this:
Image
The expected result is that they will connect, this doesn't happen.
Now do the this step reversed, and tadan! Will now connect together.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Thank you Bilka for post a example

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Pipe connections problems

Post by PyroFire »

I've had a brief go-over through the code, and discovered that this may not actually be a prototype related issue, but rather with how you're handling rotated entities.

Image


Looking at your code..

Code: Select all

control.lua:384: 		rotated_entity.fluidbox[1] = entity_fluidbox 
So each time an entity is placed or rotated, what you're doing is (FIRST) creating a new entity on top of the old one, (SECOND) copying the fluidbox over (why?), and (THIRD) destroying the original entity.

I am not surprised it is breaking.


And as proof of this being a problem with your control code and not the prototype:


User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Pipe connections problems

Post by boskid »

This issue is because of fancy control.lua that during building and rotation swaps entities.

If pipe is built last, it will simply connect.
If "Duct end point Intake" is built last, player created entity will connect to pipe then script will kick in, will spawn overlapping entity that will not connect since pipe is already connected to underlying entity, and then underlying entity is removed disconnecting pipes. Removing entities should never (not counting Dominik's favourite entity: undergrounds) require reconnecting pipes so they are left disconnected.

If you run following command:

Code: Select all

/c
    local s = game.surfaces["nauvis"]
    s.create_entity{name="pipe", position={0.5,0.5}}
    s.create_entity{name="pipe", position={2.5,0.5}}
    local p = s.create_entity{name="pipe", position={1.5,0.5}}

    s.create_entity{name="pipe", position={1.5,0.5}}
    p.destroy()
you will get same result. Third create_entity spawns pipe that connects, but last creat_entity spawn overlapping pipe that will not connect since connections around are already connected, then underlying pipe is removed leaving pipes in disconnected state.

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Pipe connections problems

Post by PyroFire »

As further further proof of faulty control.lua shenanigans, i've altered your code so that it functions correctly.

See attached.

Please note however, by destroying the original entity in the manner that you are (to apply rotations), you are also destroying any fluids that exist in the pump.
You may want to add some code to carry over those fluids.
Same goes for power but that's probably not a big enough deal to worry about.

Attachments
control.lua
(13.59 KiB) Downloaded 50 times
Last edited by PyroFire on Thu Nov 14, 2019 8:22 am, edited 1 time in total.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Pipe connections problems

Post by boskid »

btw what is reason for this entity swap when building and rotating? square entities will rotate in all 4 directions just fine.

Removed rotating entity swap (so below there is duct-endpoint-intake-south even after rotation):
mustflow-no-rotate-swap.gif
mustflow-no-rotate-swap.gif (452.04 KiB) Viewed 2870 times

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Pipe connections problems

Post by darkfrei »

Where are the input connection triangles?

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Pipe connections problems

Post by Bilka »

darkfrei wrote:
Thu Nov 14, 2019 10:04 am
Where are the input connection triangles?
They don't get drawn for pumps.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Pipe connections problems

Post by darkfrei »

Bilka wrote:
Thu Nov 14, 2019 10:06 am
darkfrei wrote:
Thu Nov 14, 2019 10:04 am
Where are the input connection triangles?
They don't get drawn for pumps.
I see it, but why they don't get drawn for pumps? All entities have both, input and output connection triangles.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Thank you PyroFire for your testing,
I tried now your control.lua and seems to solve the problem, about:

rotated_entity.fluidbox[1] = entity_fluidbox

This was suggested to me from staplergun from keep the fluid inside, but seems that not work much well, we follow the info of this documentation: https://lua-api.factorio.com/latest/LuaFluidBox.html (see the first example) but maybe I could inserted the fluid manually with another function and way. I will try. Thank you again.

Hi boskid,
The reason why I do all this entities messy substitutions, is for obtain this graphical effect:

Image

By default the pipe connection covers will not rotate with the entity, because in that mod "virtually" (with an option that I have to improve) the big pipes added by the mod should be connected only to the big one, I hide the pipe covers on that side for give a better graphical feedback and look, after some try the only solution I found was make four entities with the correct pipe covers in that rotation and rotate the entity changing the entity.
Last edited by Linver on Thu Nov 14, 2019 12:19 pm, edited 3 times in total.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Anyway PyroFire (but all are welcome), I was wondering about what is the best way to:

1. Save what kind of fluid and the quantity inside the old entities
2. Destroy the entity
3. Place the new entities in the right pipe covers
4. Insert the old fluid with the old quantities

Do u have a suggestion, or there's an easy old.fluid... blabla, new.fluid blabla .. = old.fluid... blabla that I can find on prototype documentation?

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

I tried this solution and seems work enough for keep the fluid:

Code: Select all

...
local contained_fluid = entity.fluidbox[1] or false
...
-- substitution
...
-- Reinsert in the new entity the fluid of the destroyed entity
if contained_fluid then
	rotated_entity.insert_fluid(contained_fluid)
end
...
Is correct?

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Pipe connections problems

Post by PyroFire »

Linver wrote:
Thu Nov 14, 2019 1:46 pm
I tried this solution and seems work enough for keep the fluid:
Yeah that seems fine.

Other stuff missed by manually cloning an entity and needs to be copied over:
- .energy - this one is easy
- circuit connections https://github.com/PyroFire232/warptori ... l.lua#L190
- circuit conditions that are set on the pump (enabled/disabled condition) - https://lua-api.factorio.com/latest/Lua ... l_behavior

There could be more, but i'm not too sure.

If you're able to setup your prototypes so that they can be rotated and still have the graphical fixes applied to them, it would be much more ideal than this janky entity cloning/swapping business.

Also another bug unrelated to cloning issues: shift+r doesn't rotate in the opposite direction as expected - check the function(event table)

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Pipe connections problems

Post by Linver »

Sorry PyroFire, you talk about setup well the prototype, do u know a way to implement the pipes covers (on pump) with the same result without using control scripts?

Post Reply

Return to “Modding help”