[Solved] create_entity behavior - preserving inventory and filters
Posted: Mon Oct 12, 2020 5:52 pm
Does anyone have any ideas why the surface.create_entity function would preserve inventory and filters on one deep copy, and not on the other? In a script, I am using surface.create_entity to replace an entity with an 'upgraded' version. The upgrade just has double inventory.
I'm doing this same process for two different entity upgrade sets. The entities I'm beginning and replacing with are deep copies of logistic requester chests as follows:
My create_entity logic looks like this and is used for both.
The issue I'm having is that in the case of one building upgrade (resort to resort mk2), the replace preserves inventory and the logistic filters are carried over correctly using the logic above - which is what I want to happen. In the case of the 2nd building (city to city mk2), the replace destroys the inventory and does not carry over the logistic filters even though it's using the same logic.
I tried to use this in the create_entity function to carry over the filters, which worked slick as u please, but then it seems to invalidate the entity itself which causes issues downstream?
Any ideas? If I need to paste the full entity definitions or other code, please let me know. Thanks.
I'm doing this same process for two different entity upgrade sets. The entities I'm beginning and replacing with are deep copies of logistic requester chests as follows:
Code: Select all
ent = util.table.deepcopy(data.raw["logistic-container"]["logistic-chest-requester"])
ent.name = "k2cp-resort"
...
ent = util.table.deepcopy(data.raw["logistic-container"]["k2cp-resort"])
ent.name = "k2cp-resort-mk2"
...
ent = util.table.deepcopy(data.raw["logistic-container"]["logistic-chest-requester"])
ent.name = "k2cp-city"
...
ent = util.table.deepcopy(data.raw["logistic-container"]["k2cp-city"])
ent.name = "k2cp-city-mk2"
...
Code: Select all
local new_entity = old_object.state.entity.surface.create_entity
{ name=new_object
, target=old_object.state.entity
, position=old_object.state.entity.position
, direction=old_object.state.entity.direction
, force=game.forces.player
, fast_replace=true
, player=player
, raise_built=false
, create_build_effect_smoke=false
, spawn_decorations=false
}
I tried to use this in the create_entity function to carry over the filters, which worked slick as u please, but then it seems to invalidate the entity itself which causes issues downstream?
Code: Select all
request_filters = old_object.state.entity.get_logistic_point(defines.logistic_member_index.logistic_container).filters