LuaSurface.can_place_entity{} could use more API details

Place to get help with not working mods / modding interface.
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

LuaSurface.can_place_entity{} could use more API details

Post 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).
Attachments
FFlVdn6.png
FFlVdn6.png (80.17 KiB) Viewed 840 times
I have mods! I guess!
Link
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5411
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post by Klonan »

Can you provide your code? because I have never had a problem with can_place_entity
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

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

Post 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 76 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 804 times
While it is not:
sync_area_disabled.jpg
sync_area_disabled.jpg (1.09 MiB) Viewed 804 times
I have mods! I guess!
Link
Post Reply

Return to “Modding help”