Difference between revisions of "Player-World Interaction"

From Minetest Developer Wiki
Jump to navigation Jump to search
Line 10: Line 10:
 
== Digging a node ==
 
== Digging a node ==
  
Preconditions are a [[node]] somewhere in the [[world]].<br/>
+
Preconditions are a [[node]] somewhere in the [[map]].<br/>
This node is [[pointable]], has a selection box, and [[diggable| can be dug]] by the [[hand]] or the [[tool]] the [[player]] is wearing.<br/>
+
This node is [[pointable]], has a [[selection box]] and [[diggable| can be dug]] by the [[hand]] or the [[tool]] the [[player]] is wearing.<br/>
 
The player has interact [[priv]] and the tool has a [[tool range]] that the node can be pointed.<br/>
 
The player has interact [[priv]] and the tool has a [[tool range]] that the node can be pointed.<br/>
 
The node is not stuck somewhere the player can't point it.
 
The node is not stuck somewhere the player can't point it.

Revision as of 14:43, 28 February 2017

TODO





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 wearing.
The player has interact priv and the 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.
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 send a punch event (client->interact(4, pointed), see game.cpp:3657 (28.02.2017)).
On server side the punch event is passed to mods, see on_punch and the deprecated register_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.
  • 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
or, if it's not present, the client uses the sound "default_dig_${groupname}" (file name extension omitted here), where $groupname is one of the groups the node has, see (game.cpp:4001), and gain is set to 0.5.
The default_dig_ thing should be banned from source code in my opinion.
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 recieves the digging completion event.
Anticheat probably, e.g due to lag, thinks the player dug the node too fast.
dug_too_fast cheat is passed to mods, see register_on_cheat, and digging aborts.
If the nodedef has a can_dig function, it's executed and probably stops the digging.
The on_dig function in the nodedef is called now.
The default function checks privileges (doesn't abort digging), wears out the tool and removes the node, which calls the on_destruct, sets air and calls after_destruct.
And in the end, the after_dig_node function in the nodedef is called, if present.