Days 2 - 5: more playing around

Learned a couple more things over the past couple days. I wanted to find a nice way to interact with the thing so looked at some different methods. Ran into some pretty funny interactions.


One great tool for learning stuff, and for debugging, is the logging facility. This allows you to print useful information that you can look at to trace what has happened. In my case, I’m trying to learn what callbacks there are, when they are called, and what sorts of things I can do.

Minetest has a logging facility built in. When you use it your messages show up in the stdout when you run minetest without arguments. They also show up in the top left of the game window in debug mode.


You’ll find the callbacks you can hook into at the bottom of the documentation for the node definition record.

Having been looking at some module code I know the syntax to use in order to override these callbacks. It’s weird, but pretty straight forward:

minetest.register_node("name", {
    description = "something something",
    on_punch = function(pos, node, puncher, pointed_thing)

As you can see, it is simply another field in the node description record. You assign a function (lua obviously treats them as values) to the on_punch field and make sure it matches the same call syntax as the documentation. In fact, you can simply copy/paste the top line from the documentation directly.

Then you indent some lines of code that make up the body of the function and then de-indent and end your function with an end.

Things will get tougher later but for now they’re pretty easy.


I wanted the interaction with the strangegate to be more than just clicking on it. I wanted to require them to hold the button down for a while at least.

If you play with the above definition you’ll notice that you only get the “PUNCH” output on the first down of the punch button. When you hold it, no message except the first. So the next step was dig, and my initial thougt of just overriding on_dig is not sufficient:

on_dig = function(pos, node, digger)

If you play with this you will never see the “DIG” output. So this means something more is necessary.

If you scroll up a bit you might find a field diggable where it’s claimed that this is a necessary component. Setting this to true though is also not quite sufficient.


It turns out that what is needed is groups. In the documentation is a list of several special groups and some brief information about what they do. So then add this:

groups = { crumbly = 3 }

This then lets you get the dig callback. You will get this after you hold punch for a bit. What this does is put the node in a group that the engine knows should be broken up when held. You will note that for now it doesn’t, you get the animation and the block just stays.

The really bothersome thing here that leads one to think there’s an element of the documentation that is out of date, is that you can delete the “diggable = true” in your node description record and it has no effect. If it is in the group it can be dug, if not then it cannot. There are several groups it can join to describe different kinds of toughness and such, but the node must be a member of one of them to get the dig callback.

Bouncy, slippery, and other fun groups

While I’m here…:

bouncy: value is bounce speed in percent

What does 1000 do?


I think it’s death on contact? Definitely before slammed into ceiling.

Player velocity

There’s an explody group. Playing with that value yielded no immediate changes so I looked into the code for tnt.

I can do that!:

on_punch = function(pos, node, puncher, pointed_thing)

    local direction = vector.normalize(vector.subtract(pos, puncher:get_pos()))
    local pow = vector.multiply(direction, 100)