Page 1 of 1

[Lou][2.0.55] Modding - Non-Square Machines, Fluidbox, Rotation event

Posted: Fri Jun 06, 2025 12:12 am
by Honktown
What you expect:
The machine - non-square (rectangular) crafting machine with fluid_boxes and fluid_boxes_off_when_no_fluid_recipe = true
The machine can be placed, and if you try to rotate it, it doesn't rotate (conventional behavior for assemblers), and does not raise on_player_rotated_entity , or, it does rotate, and changes direction in the event and LuaEntity (which also draws different direction graphics)

What happens:
The machine can be placed, and if you try to rotate it, it doesn't rotate, and does raise on_player_rotated_entity, but the direction does not change.

Why is this a problem?
For mods that are reacting to the entity rotating and changing e.g. "attached" loaders, or other combined entities, this causes unexpected behavior, including that from a design standpoint, the entity doesn't look like it rotated, leading to a rabbit hole of "why are my graphics wrong, it did rotate?".

Example mod:

Code: Select all

local chem = data.raw["assembling-machine"]["chemical-plant"]
chem.collision_box = {
    {
      -2.2,
      -1.2
    },
    {
      2.2,
      1.2
    }
  }
chem.fluid_boxes_off_when_no_fluid_recipe = true

Code: Select all

script.on_event(defines.events.on_player_rotated_entity, function(event)
    game.print("rotated, direction: "..event.entity.direction)
end)
unexpected_rotation_0.0.1.zip
(1.18 KiB) Downloaded 21 times

Save file:
unexpected_rotation.zip
(288.42 KiB) Downloaded 19 times

For comparison, an assembling-machine-2 is beside, which elicits "This cannot be rotated." (the first example of potentially "proper" behavior). More organically, the second option of successfully rotating and altering the LuaEntity makes "sense", whether it's for direction-able assemblers, square or otherwise.

Re: [2.0.55] Modding - Non-Square Machines, Fluidbox, Rotation event

Posted: Fri Jun 06, 2025 5:42 am
by StephenB
I ran into this issue with my mod. Non-square assemblers can be rotated, but if the machine has no fluidboxes or fluid_boxes_off_when_no_fluid_recipe == true, then pressing the rotate key on it will raise the rotation event but the entity's .direction doesn't update. Basically it looks like there's an engine optimization / bug that doesn't allow entity.direction to be changed for assemblers with no fluidboxes. Assigning `entity.direction = 12` and then reading `entity.direction` will still give you the original direction, not the new one.

Not sure what the solution to this is, assuming it's not a bug. Maybe treat assemblers with 4-directional sprites as rotatable even without fluidboxes?

If you git clone my WIP mod https://github.com/StephenBarnes/Legend ... 14e51389cc you can place down the "classifier" building which is a 2x1 assembler, and it can be rotated 180 degrees. If you remove the code here https://github.com/StephenBarnes/Legend ... r.lua#L210 that adds the fluidbox, and replace it with `miniAssembler.fluid_boxes = nil`, then it stops working - rotating the assembler doesn't change the entity's .direction, so it keeps the wrong directional sprites. (Loaders will still rotate 180 degrees but that's done with separate control scripting.)