Page 1 of 1

Handling item/ghost-in-cursor placement

Posted: Sun Oct 29, 2023 1:59 pm
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 1235 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.

Re: Handling item/ghost-in-cursor placement

Posted: Sun Oct 29, 2023 2:13 pm
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.

Re: Handling item/ghost-in-cursor placement

Posted: Sun Oct 29, 2023 2:16 pm
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.