Thanks to @max99x’s advice and explanations the autoharvest is working now.
However, my further ideas would involve a lot of listening to events. As all of them require components I could do it in a more memory-wise way by implementing a function which fires a specific command on all components of an entity instead of listening to an event inside each component:
function pawel_API:component_trigger(entity, function, args)
if entity and entity:is_valid() and type(function) == 'string' then
local component_list = --[[how do I get a list of all components an entity has?]]
for i, component in ipairs(component_list) do
if type(component[function]) == 'function' then
component[function](self, args)
end
end
end
end
For example, for detecting an entity going iconic I could do:
args = {}
pawel_API:component_trigger(self._entity, _on_removed_from_world_trigger, args)
instead of creating a listener on each component interested in the event:
self._on_removed_from_world_listener = radiant.events.listen(self._entity, 'stonehearth:on_removed_from_world', self, self._on_removed_from_world_trigger)
But, as I asked: how do I get a list of all components an entity has?