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"}})
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]"
}
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.