Player-World Interaction#
Digging a node#
Preconditions are:
- a node somewhere in the map
- this node is pointable, has a selection box and can be dug by the hand or the tool the player is wielding.
- the player has
interactprivilege - the active tool has a tool range that the node can be pointed
- the node is not stuck somewhere the player can’t point it
- First look at the node, it becomes
pointed_thing. Note that on android the node is pointed without looking (referring to the cross position) at it. - Then LMB is pressed down while holding an item which does not have
on_use. If LMB wasn’t released before, a click happens, which causes a punch event.- The client sends a punch event (
client->interact(4, pointed), seegame.cpp:3657(28.02.2017)). - On server side the punch event is passed to mods, see
on_punchand the deprecatedregister_on_punchnode. - Then the client sends the digging start event to the server (
interact(0, pointed),game.cpp:3948). - The server uses this information for anticheat measurements.
- The client sends a punch event (
- Now continue looking at the node, i.e. keep pointing it, and hold down LMB.
- Periodically client-side: Crack animation is updated, digging particles are spawned (if not disabled in the settings) and the node dig sound is played.
- The dig sound is either the “dig” field in the “sounds” table in the nodedef
- If it’s not present, the client uses the sound
default_dig_${group_name}(file name extension omitted here), where$group_nameis one of the groups the node has, see (game.cpp:4001), andgainis set to0.5.
- Some time later, when the digging time elapsed, the client sends a digging completion event to the server (interact(2, pointed), game.cpp:4018), the node disappears client-side, more particles are spawned (if enabled) and the dug sound is played.
- Now the server receives the digging completion event. Anticheat probably, e.g due to lag, thinks the player dug the node too fast.
dug_too_fastcheat is passed to mods, seeregister_on_cheat, and digging aborts.- If the
nodedefhas acan_digfunction, it’s executed and probably stops the digging. - The
on_digfunction in the nodedef is called now. - The default
on_digfunction probably removes the node:- The
on_destructis executed, air is set andafter_destructis executed. - It then calls the
after_dig_nodefunction in thenodedefif present.
- The