One of the most important blocks in every automation machine built inside minetest is the node breaker. It is a very expensive block to craft but it can harvest resources from the environment as if you were there.
It’s most basic use is to harvest wheat or stone in an endless cycle of repetitive work that no one is interested doing.
So how do we replicate some of it’s features?
This is how we register a node called nodebreaker in the mod named awittymodname.
I added only two fields to the node properties and the interesting one is on_punch.
Obvioulsy when we will punch the node nothing will happen because there is no meaningful code inside the function, that’s just a seed to get going.
So now every time we punch the node breaker the node facing the face 0 will be destroyed.
But that wont drop resources, dammit!
By using the get node drops API we can obtain the list of item names that the node will drop if digged and by using the add item API we add the items to the world.
So now our node breaker can dig blocks as if a player would, by dropping the resources in the world.
This is very good but still requires to punch the node to dig it, maybe it’s time to think about timers…
Key points
We can create nodes to fit our needs.
It is very simple to emulate the work of a player.