Page 1 of 1

LuaSurface.can_place_entity{} could use more API details

Posted: Wed May 06, 2020 11:16 am
by Honktown
I was provided a screenshot of an error, and it said I didn't have property "stack" in a line which only had can_place_entity. See attachment.

Some testing revealed ghosts would produce a similar error, that the property "inner_name" was missing.

can_place_entity lists a limited number of key-value pairs for the table to pass, but it appears at least some of the entity-specific information that create_entity lists is required.

I'll be adding exceptions for anything that probably needs it. A ghost's inner-name makes sense for can_place_entity to check, but the property "stack" looks to be from an item-entity, which are all the same size (1/4 tile by 1/4 on ground, unless I am mistaken).

Re: LuaSurface.can_place_entity{} could use more API details

Posted: Wed May 06, 2020 12:12 pm
by Klonan
Can you provide your code? because I have never had a problem with can_place_entity

Re: LuaSurface.can_place_entity{} could use more API details

Posted: Wed May 06, 2020 7:52 pm
by Honktown
This is a line that will trigger an error for ghosts and entity-with-item's:

Code: Select all

		if outside.can_place_entity{name = ent.name, position = {posX, posY}, direction = ent.direction, force = ent.force, build_check_type = defines.build_check_type.ghost_place, forced = true} == false then
The function is as attached. Clipped from a larger file, in a mod, etc etc so some details are omitted. Whole file is mod/scripts/objects/mobile-factory.lua . From Mobile Factory 0.0.143 . Version 0.0.144 is patched.
clip.txt
(3.69 KiB) Downloaded 75 times

The full effect (which you and I had discussed lightly in the Factorio Discord) is that I clone useful entities from one surface to another in an area, and mirror their "contents". One surface (the normal game map) mirroring ores and tiles to an "inside" surface. Both surface mirror chests, accumulators, and storage tanks. See attached images which explain better.

The "catch" is that when cloning tiles, water tiles will destroy land-bound entities (and vice-versa). After a few attempts at getting that to *not* happen but still feeling good from a gameplay standpoint, I found can_place_entity to be very effective for the behavior I wanted... until I ran into errors with ghosts and "entity-with-item"s. Ghosts trigger an error that they're missing inner_name. That makes sense because a ghost's size, collision, etc is based on the prototype it represents. Entity-with-item's (lootable items) don't make sense, since as far as I can think they're all the same size, but since that's the behavior of can_place_entity, I have to go with it.

The effect is seen in the following images.
While effect is active:
stopped.jpg
stopped.jpg (1.11 MiB) Viewed 803 times
While it is not:
sync_area_disabled.jpg
sync_area_disabled.jpg (1.09 MiB) Viewed 803 times