[Solved]Intercepting creation of an entity from on_put_item?
Posted: Sat May 06, 2017 5:36 pm
Hi!
I've been creating a mod to show direction indicators on belt placement since I was constantly screwing up the placement. For this, I created a "belt placer" item that is in the transport_belt fast_replaceable_group. On being built, it is replaced with a belt of the appropriate type and direction and added back to the player's inventory again. However, I have two problems:
a) The item can be built even with no belts in inventory. I could stop the process in on_built_entity and delete the entity instead of replacing it with a belt. But that's ugly and the sound for "thing built" still plays.
b) I get into an infinite build loop - the entity is created, replaced, and replaced with the placeholder entity again since it's in the fast_replaceable_group. This causes build sounds to play rapidly like when placing a lot of robots manually.
There are two direct ways around this I can think of: Intercepting the build and disabling the sound temporarily and play it back just once manually. Is either of those possible? For the former, I'd also need a way to get the direction the entity would be placed in, in order to emulate default belt placement behavior where nothing happens if you're building a belt in the same direction again. Is that possible, if this is a feasible idea? The latter would probably be quite performance-hungry, would it not?
If you have any other ideas or would suggest changing the concept, go ahead, this is my first mod and I'm having a hard time understanding how everything ties together.
Thanks!
I've been creating a mod to show direction indicators on belt placement since I was constantly screwing up the placement. For this, I created a "belt placer" item that is in the transport_belt fast_replaceable_group. On being built, it is replaced with a belt of the appropriate type and direction and added back to the player's inventory again. However, I have two problems:
a) The item can be built even with no belts in inventory. I could stop the process in on_built_entity and delete the entity instead of replacing it with a belt. But that's ugly and the sound for "thing built" still plays.
b) I get into an infinite build loop - the entity is created, replaced, and replaced with the placeholder entity again since it's in the fast_replaceable_group. This causes build sounds to play rapidly like when placing a lot of robots manually.
There are two direct ways around this I can think of: Intercepting the build and disabling the sound temporarily and play it back just once manually. Is either of those possible? For the former, I'd also need a way to get the direction the entity would be placed in, in order to emulate default belt placement behavior where nothing happens if you're building a belt in the same direction again. Is that possible, if this is a feasible idea? The latter would probably be quite performance-hungry, would it not?
If you have any other ideas or would suggest changing the concept, go ahead, this is my first mod and I'm having a hard time understanding how everything ties together.
Thanks!