Modding Minetest - Destroy blocks
Our previous mod has taught us something interesting about minetest events. As an example we added a custom Hello world! message to the player HUD when they join our world.
The problem is: this is everything but fun.
But I want to amend myself and now I want to teach you how to destroy blocks, oh this will be fun.
Obviously we will write a mod in lua to break things, maybe a tool that destroy more than one block.
To create a new tool we have to register it with the register_tool API.
This snippet of code will be run at startup and it will register a new tool, like a shovel or an axe, called “pewpew”.
This is still nothing but fun.
So let’s add something that we can do with this new tool.
And now when we use the tool pewpew it destroy nodes from distance, a fancy tool.
Still this is very like a normal tool, perhaps we can extend it’s range.
But increasing the tool range too much can slow down your game as the computer take advantage of untouched farther block. Now we can change blocks furter than ever and so the game have to pick our pace rendering and updating more blocks than before.
Maybe a shovel will do better.
Key points
We can create tools to fit our needs.
All tool are alike, their on_use attribute is different.
Extending tools has a tradeoff in game.
We can peek at default tools in the minetest game repository