Handling item/ghost-in-cursor placement

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Handling item/ghost-in-cursor placement

Post by Deadlock989 »

I'm trying to recreate something similar to the "underground visualisation" you get with underground pipes:

Untitled.jpg
Untitled.jpg (20.3 KiB) Viewed 317 times

The entity ghost concerned, though, can't be an underground pipe (for reasons). It is either a crafting machine or a SimpleEntity. So I would have to be able to know when a player is holding a buildable item and then use the rendering API to temporarily draw whatever if the item is in the right place and has the right orientation.

I figured out the first part - using events to track when a buildable item or ghost is in the cursor, and starting a conditional on-tick if any player is in that state, clearing it when none are. But I don't think there is a way of telling what tile the entity is going to be built in, i.e. the tile you're currently pointing at. Am I wrong?

Also, I can't find out any way of telling what orientation the to-be-built entity has - is that even possible? cursor_stack and cursor_ghost return various kinds of item specification which doesn't have any concept of direction.
Last edited by Deadlock989 on Sun Oct 29, 2023 2:14 pm, edited 1 time in total.
Image

Bilka
Factorio Staff
Factorio Staff
Posts: 3140
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Handling item/ghost-in-cursor placement

Post by Bilka »

If the visualisation is independent of existing entities in the world, you could use the radius visualisation specification, for example to draw the max range.

If not, you're out of luck. The cursor direction is not readable because it's not in game state. That's why events like on_pre_build come with that data as extra information. You can theoretically get the cursor position if you make the player use a custom input, but that (like the direction in the on_pre_build event) likely doesnt help.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Handling item/ghost-in-cursor placement

Post by Deadlock989 »

Bilka wrote:
Sun Oct 29, 2023 2:13 pm
If the visualisation is independent of existing entities in the world, you could use the radius visualisation specification.
It's not - like a ug pipe, the drawing needs to happen when two entities are facing each other.

What about can_build_from_cursor - if I can't get the cursor ghost direction then I could test all directions? Edited to add, never mind, still can't tell where it's going to be built - there is no player input that a custom input could catch, because you're just moving the mouse around.
Image

Post Reply

Return to “Modding help”