hammer registration documentation/function update

This commit is contained in:
Dirk Sohler 2018-09-22 16:43:38 +02:00
parent 290763eeeb
commit 7495124061
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A

@ -8,11 +8,39 @@ local use_hammer = uniham.use_hammer
-- name = 'Name of the hammer',
-- head = 'head_material_texture.png',
-- craft = 'crafting:material',
-- on_use = on_use_function,
-- uses = 123,
-- }
--
-- The `name` will be shown as tooltip on hovering the item in the inventory
-- and will be used as it is.
--
-- `head` is a texture that is used as base for the hammer head texture mask.
-- To change the mask textture packs need to add `uniham_head_mask.png` with
-- another file. All black pixels will become transparent.
--
-- With `craft` the material to craft the hammer from is defined. Hammers are
-- crafted all the same with the provided material for x and a stick for s
--
-- [ ][x][ ]
-- [ ][s][x]
-- [s][ ][ ]
--
-- The function provided via `on_use` gets three parameters when called by the
-- hammers on_use action: `itemstack`, `player`, and `pointed_thing`. All of
-- those three parameters are defined by Minetests API. The function has to
-- modify and return the itemstack as needed.
--
-- If no function is provided the default function (replace nodes by the table
-- provided as `uniham.use_hammer` in mod loading state).
--
-- `uses` is added as `_uniham.uses` to the hammers item definition and can
-- be used by the custom `on_use` function. The built-in function (replacing
-- nodes) calculates the `add_wear` value from this.
--
-- @param short_id Unprefixed ID for the new hammer
-- @param definition Definition table as described
-- @see <https://dev.minetest.net/on_use#on_use>
-- @return void
uniham.register_hammer = function (short_id, definition)
local texture = '([combine:16x16:-1,1=+s)^((+h^+m)^[makealpha:0,0,0)'
@ -22,17 +50,19 @@ uniham.register_hammer = function (short_id, definition)
['+m'] = 'uniham_head_mask.png'
})
local on_use = definition.on_use or use_hammer
minetest.register_tool('uniham:'..short_id, {
description = definition.name,
inventory_image = texture,
_uniham = { uses = definition.uses },
on_use = function(itemstack, player, pointed_thing)
return use_hammer(itemstack, player, pointed_thing)
return on_use(itemstack, player, pointed_thing)
end
})
minetest.register_craft({
output = 'uniham:'..short_id,
output = minetest.get_current_modname()..':'..short_id,
recipe = {
{ '', definition.craft, '' },
{ '', 'default:stick', definition.craft },