I'm trying to create a mod which listens to the [ICODE]OnOperatingChange[/ICODE] event triggered by [ICODE]WorldObject[/ICODE] objects.
Some background information (from my point of understanding, maybe I'm wrong on some of the following points): there are [ICODE]WorldObject[/ICODE]s (like the "Blast Furnace") which act as a crafting table (and thus have the [ICODE]CraftingComponent[/ICODE] interface attached). If the appropriate ingredients were added, a work order may be started, if the other conditions are met: the "Blast Furnace" for example needs fuel (like "Coal"), some room to be placed in which needs to be big enough, etc.
If any of these prerequisites fail (for example the fuel runs out), there's a [ICODE]OnOperatingChange[/ICODE] event triggered. I'm able to attach/listen to this event like this:
public void Initialize(TimedTask timer) {
...
// craftingComponent is the instance of the "Blast Furnace";
// craftingComponent.Parent yields an instance of WorldObject
craftingComponent.Parent.OnOperatingChange.Add(this.HandleOperatingChange);
}
private void HandleOperatingChange()
{
ChatManager.ServerMessageToAllLoc("oh hello there", false);
// how to get the WorldObject instance here?
}
Alles anzeigen
So this [ICODE]HandleOperatingChange[/ICODE] method is called, I'm seeing that message in the chat window. But how can I get the [ICODE]WorldObject[/ICODE] instance (which triggered this event) in this method? I don't want to iterate over all world objects to see which one may have triggered the [ICODE]OnOperatingChange[/ICODE] event. There has to be a simpler way.
In the Reacting to player events article in the EcoModKit wiki, we see that the event triggered by a player action has some payload, a [ICODE]CraftAction[/ICODE] which can be used to do things. Is there anything similar for my use case?