wcwyes wrote:how would I add an extra function to a special pick axe? like if I mine something from pos then do function?
Oddly, there's not a lot of customization you can do for the behavior from the tool's end. You can either completely
override what it does by adding an on_use()
callback (same for tools as for nodes), or you're pretty much stuck with what it does using the default Minetest behavior. [EDIT: I stand corrected. See Nore's post below. Excellent!] You can set parameters for the latter to customize the damage it does, how quickly it digs various types of block, what materials it can affect, etc., but you can't just do arbitrary things. If you make your own on_use() method, you'll have to figure out every detail of what happens when you left-click with it; the default behavior for digging and damage and all of that does not take effect, instead being replaced with whatever your callback does.
From the receiving end—meaning a node or entity on which a tool is being used—you have a few more options. So if there's some special entity/mob/node (but not player) you want the tool to affect in a particular way, there are a number of options to play with. For example, there are the on_punch(), on_dig(), can_dig(), after_dig_node(), and on_rightclick() callbacks on nodes
and the punch() and right_click() callbacks on entites
. From most of these you either get the wielded item as a parameter or get a reference to the player doing the digging/clicking and can use the player
API to test things like what tool they are wielding.
It may be possible to re-create enough of the default behavior of digging/hitting if you dig around in the built-in Lua code a bit to figure out what everything is doing, but you'll have to be pretty careful to do it in a way that will work nicely with other mods (because of the way they assume it is all going to work).