I'm working on a forge mod in which it is possible to compile and run (Java) scripts at runtime. It is possible to manipulate a robot, for example by making it walk to a set of coordinates or mine in a direction.
The script runs on a separate thread from the game, but this causes some occasional crashes since the script may indirectly modify collections while they are being iterated.
The solution to this, I think, would be that every command executed by the script would have to wait for the next game tick to execute. I know whenever the game ticks, because the robot's onEntityUpdate() is called. I'm new to Java and I've looked into synchronization, but I'm not sure what an actual implementation would look like, so I would greatly appreciate some help!