[2.0.21] on_robot_built_entity event ItemStack provides wrong grid

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
robot256
Filter Inserter
Filter Inserter
Posts: 948
Joined: Sun Mar 17, 2019 1:52 am
Contact:

[2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by robot256 »

What I did:

I tried to read the equipment grid of the customized vehicle item that a robot used to revive a differently-customized vehicle entity ghost. I tried to do this inside the on_robot_built_entity event using the LuaItemStack parameter provided by the event.

What I expected to happen:

I expected that the LuaItemStack provided by the event would contain the equipment stored in the item when the robot picked it up. After the robot places it, of course, requests are added automatically to make the equipment equal what was in the ghost rather than what was in the item.

What actually happened:

The LuaEntity provided by on_robot_built_entity correctly shows the equipment that was in the item the robot was carrying, with removal requests if they do not match the ghost. However, the LuaItemStack provided by the event returns a grid that does NOT contain the same equipment as the item that was picked up by the robot. Instead, it contains the equipment GHOSTS that the entity ghost had in it BEFORE being revived. This is not obvious nor particularly useful, since that information can already be obtained by looking at the entity itself and the ghosts/removal requests that were added to its grid.

Reproduction steps:

1. Load the attached save file.
2. Observe that the Tank ghost contains 4 equipment requests and the Tank item in the player's inventory contains 5 equipment--4 of them match the ghost and 1 is extra.
3. Observe that the Spidertron ghost contains no equipment requests and the Spidertron item in the player's inventory contains 4 equipment.
4. Run the following console command to print data when on_robot_built_entity fires.

Code: Select all

/c script.on_event(defines.events.on_robot_built_entity, function(event) game.print(event.entity.name.." has qty
 "..tostring(event.entity.grid.count()).." equipment "..serpent.block(event.entity.grid.equipment).." after being placed with item containing qty "..tostring(event.stack.grid.count()).." equipment "..serpent.block(event.stack.grid.equipment)); end, {{filter="vehicle"}})
5. Enable personal construction robots and allow the robots to build the vehicles.
6. Observe the following text is printed:

Code: Select all

spidertron has qty  4 equipment {
  "[LuaEquipment: fission-reactor-equipment (normal) at [0,0] in spidertron at [gps=21.2,30.1]]",
  "[LuaEquipment: battery-equipment (normal) at [4,0] in spidertron at [gps=21.2,30.1]]",
  "[LuaEquipment: battery-mk2-equipment (normal) at [5,0] in spidertron at [gps=21.2,30.1]]",
  "[LuaEquipment: exoskeleton-equipment (normal) at [4,2] in spidertron at [gps=21.2,30.1]]"
} after being placed with item containing qty 0 equipment {}
tank has qty  5 equipment {
  "[LuaEquipment: exoskeleton-equipment (normal) at [0,0] in tank at [gps=7.8,29.6]]",
  "[LuaEquipment: personal-roboport-equipment (normal) at [2,0] in tank at [gps=7.8,29.6]]",
  "[LuaEquipment: belt-immunity-equipment (normal) at [4,0] in tank at [gps=7.8,29.6]]",
  "[LuaEquipment: exoskeleton-equipment (normal) at [0,4] in tank at [gps=7.8,29.6]]",
  "[LuaEquipment: fission-reactor-equipment (normal) at [2,4] in tank at [gps=7.8,29.6]]"
} after being placed with item containing qty 4 equipment {
  "[LuaEquipment: ghost exoskeleton-equipment (normal) at [0,0] in tank (normal) itemNumber=11]",
  "[LuaEquipment: ghost personal-roboport-equipment (normal) at [2,0] in tank (normal) itemNumber=11]",
  "[LuaEquipment: ghost belt-immunity-equipment (normal) at [4,0] in tank (normal) itemNumber=11]",
  "[LuaEquipment: ghost fission-reactor-equipment (normal) at [2,4] in tank (normal) itemNumber=11]"
}
Conclusion: event.stack.grid points to the grid of the ghost prior to being revived, NOT the grid of the item-with-entity-data that was used to revive the ghost. If this is intentional, it would be nice to note it somewhere in the API documentation, but I suspect this is unintended weird behavior.

In fairness, with the current API, you can determine everything from the grid in the entity itself: The contents of the item that was used will exist as real equipment, with or without the "to_be_removed" flag set. The contents of the ghost will exist as the combination of ghost equipment and not-to_be_removed real equipment. But what I found was not where I expected it to be.
Attachments
equipment_event_test.zip
(1.96 MiB) Downloaded 7 times
neinstein
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Nov 10, 2024 1:18 am
Contact:

Re: [2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by neinstein »

I can't follow the technical details here. But can this also explain, why my spidertron is missing some equipment after placing it post space journey?

I did:

1. Build a spidertron on Nauvis 2. Fill its grid with equipment 3. Pick it up and place in rocket 4. Send to platform 5. Fly to Gleba 6. Drop from orbit 7. Tell robots to place blueprint spidertron

This did work before, but this time only 2 equipment items are there, the rest is missing.

PS: the items did not vanish, but were placed in logistic storage
Rseding91
Factorio Staff
Factorio Staff
Posts: 14413
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by Rseding91 »

Thanks for the report however I don't believe we will be changing this. One or the other will have one version of the grid and the other will have the other. The equipment grid is moved into the entity when it's built and so only one of the two things can have that instance of the grid.
If you want to get ahold of me I'm almost always on Discord.
robot256
Filter Inserter
Filter Inserter
Posts: 948
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by robot256 »

Rseding91 wrote: Mon Nov 25, 2024 2:00 pm Thanks for the report however I don't believe we will be changing this. One or the other will have one version of the grid and the other will have the other. The equipment grid is moved into the entity when it's built and so only one of the two things can have that instance of the grid.
Thanks for the explanation! I made a documentation request instead.
robot256
Filter Inserter
Filter Inserter
Posts: 948
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by robot256 »

neinstein wrote: Mon Nov 25, 2024 12:25 pm I can't follow the technical details here. But can this also explain, why my spidertron is missing some equipment after placing it post space journey?

I did:

1. Build a spidertron on Nauvis 2. Fill its grid with equipment 3. Pick it up and place in rocket 4. Send to platform 5. Fly to Gleba 6. Drop from orbit 7. Tell robots to place blueprint spidertron

This did work before, but this time only 2 equipment items are there, the rest is missing.

PS: the items did not vanish, but were placed in logistic storage
No, what you describe is the intentional behavior that I was attempting to alter in a mod when I encountered my issue. Please see the other threads where your situation is discussed: 118257, 122587
neinstein
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Nov 10, 2024 1:18 am
Contact:

Re: [2.0.21] on_robot_built_entity event ItemStack provides wrong grid

Post by neinstein »

robot256 wrote: Mon Nov 25, 2024 3:43 pm No, what you describe is the intentional behavior that I was attempting to alter in a mod when I encountered my issue. Please see the other threads where your situation is discussed: 118257, 122587
Yep, thanks for the links! That actually is the behavior I encountered, as I see now after playing around with it. You can place a fully equipped spidertron in a rocket. It will stay in storage as is: in the rocket, on the platforn, in the target hub. But when placing "a spidertron" on a planet in remote view, this transported entity will be placed by the bots and then "disassembled" at first, to fit the blueprint of a naked spidertron.

What confused me specifically, was that the placed spidertron had some equipment that stayed when I copy-pasted the original config, while other equipiment was already removed by the bots, or maybe did geometrically collide with the new setup. So I was left with a spidertron that had some equipment, but not all.

Perhaps take the cheap way out, and say entities with a (filled) grid cannot be transported??? I would understand that a tank or a spidertron are too big for a rocket anyway.
Post Reply

Return to “Minor issues”