nicolas-lang / Factorio.LongWarehouses

A mod for the game Factorio
Other
3 stars 3 forks source link

blueprinted warehouses loose rotation capabilities when overwriting blueprint #9

Open Tetlanesh opened 10 months ago

Tetlanesh commented 10 months ago

when overwriting existing blueprint containing long warehouse with new content ("select new content for this blueprint" option) the resulting blueprint no longer can be rotated and instead is only mirrored when pressing rotation button. I have to recreate blueprint from scratch when making changes to it instead of only updating the content

nicolas-lang commented 9 months ago

I would expect that the new feature comes with a build event that I am not catching yet. It might be a simple fix to just add a secondary event hook at this place ... maxbe on_player_configured_blueprint As I am not playing the game right now, It wont happen for now from my side... but I would appreciate a Pull request.

joncol commented 8 months ago

@nicolas-lang, I tried looking into this, but I didn't get very far.

It seems the same problem occurs when using the pipette tool (Q) to select a long warehouse that is placed in the world. When doing that, you also cannot rotate the warehouse (ghost). Do you think this is related to the problem with not being able to rotate when updating blueprints?

I saw that you're currently not playing the game (how were you able to quit?? :smile:), but any pointers would be much appreciated. I'm a total neophyte when it comes to Factorio mod development, but it would be nice to try and fix this issue, which has been bothering me a bit as well.

nicolas-lang commented 8 months ago

The warehouse is in fact not a warehouse when you place it, as warehouses are impossible to rotate. The mod uses a warehouse-skinned pump entity to simulate a rotating warehouse. When the mod registers the "the pump has been placed"-event a script checks the orientation of the pump-house and replaces it with one of two hidden warehouse entites depending on the orientation. When the mod registers that a warehouse is blueprinted, the wharehouse in the BP is replaced by a pump-house again.

If now a event that the mod is not aware of, interacts with the warehouse the described errors will occur, as the blueprint (or whatever) contains one of the hidden H/V-warehouses instead of the pump-house.

(additional logic is present for circuit connections but that is a different mess)

joncol commented 7 months ago

@nicolas-lang, thanks for the explanation. It seems the same trick that you use for the blueprints (changing the name of the entity directly) is not supported for events like on_player_pipette. Setting the name field of the entity yields some error message about that not being allowed...

nicolas-lang commented 7 months ago

Not sure if the following would work, but what you described cant't work for sure:

Blueprints are a bit special, as they are just a "list" on items to be placed, like a construction drawing can represent a house but is just made from ink and paper not bricks. Based on a 30 sec check of the documentation i would expect the pipette to be different. It does not use a reference (name) but rather "picks up" the "real" item-template (Item Prototype). A Prototype can't be changed during runtime (and it would do the wrong things if you could), and you have to replace the prototype by the correct one instead of renaming it.

check: https://lua-api.factorio.com/latest/events.html#on_player_pipette and https://lua-api.factorio.com/latest/classes/LuaItemPrototype.html

It might have to be implemented like this, assuming that the pipette "just leaves an item in the player's hand": hook: on_player_pipette --> handle: if player "item in hand" = my warehouse then replace item in hand by proxy-item see: https://forums.factorio.com/viewtopic.php?t=56423

but to find out how pipette really works would require me to install factorio, which i haven't done yet.