2018-09-22 16:12:22 +02:00
|
|
|
|
-- Localize
|
|
|
|
|
local use_hammer = uniham.use_hammer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Register a new hammer
|
|
|
|
|
--
|
|
|
|
|
-- definition = {
|
|
|
|
|
-- name = 'Name of the hammer',
|
|
|
|
|
-- head = 'head_material_texture.png',
|
|
|
|
|
-- craft = 'crafting:material',
|
2018-09-22 16:43:38 +02:00
|
|
|
|
-- on_use = on_use_function,
|
2018-09-22 16:12:22 +02:00
|
|
|
|
-- uses = 123,
|
|
|
|
|
-- }
|
|
|
|
|
--
|
2018-09-22 16:43:38 +02:00
|
|
|
|
-- 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
|
|
|
|
|
-- hammer’s on_use action: `itemstack`, `player`, and `pointed_thing`. All of
|
|
|
|
|
-- those three parameters are defined by Minetest’s 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 hammer’s 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.
|
|
|
|
|
--
|
2018-09-22 16:12:22 +02:00
|
|
|
|
-- @param short_id Unprefixed ID for the new hammer
|
|
|
|
|
-- @param definition Definition table as described
|
2018-09-22 16:43:38 +02:00
|
|
|
|
-- @see <https://dev.minetest.net/on_use#on_use>
|
2018-09-22 16:12:22 +02:00
|
|
|
|
-- @return void
|
|
|
|
|
uniham.register_hammer = function (short_id, definition)
|
|
|
|
|
local texture = '([combine:16x16:-1,1=+s)^((+h^+m)^[makealpha:0,0,0)'
|
|
|
|
|
texture = texture:gsub('+.', {
|
|
|
|
|
['+s'] = 'default_stick.png',
|
|
|
|
|
['+h'] = definition.head,
|
|
|
|
|
['+m'] = 'uniham_head_mask.png'
|
|
|
|
|
})
|
|
|
|
|
|
2018-09-22 16:43:38 +02:00
|
|
|
|
local on_use = definition.on_use or use_hammer
|
|
|
|
|
|
2018-09-22 16:12:22 +02:00
|
|
|
|
minetest.register_tool('uniham:'..short_id, {
|
|
|
|
|
description = definition.name,
|
|
|
|
|
inventory_image = texture,
|
|
|
|
|
_uniham = { uses = definition.uses },
|
|
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
2018-09-22 16:43:38 +02:00
|
|
|
|
return on_use(itemstack, player, pointed_thing)
|
2018-09-22 16:12:22 +02:00
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2018-09-22 16:43:38 +02:00
|
|
|
|
output = minetest.get_current_modname()..':'..short_id,
|
2018-09-22 16:12:22 +02:00
|
|
|
|
recipe = {
|
|
|
|
|
{ '', definition.craft, '' },
|
|
|
|
|
{ '', 'default:stick', definition.craft },
|
|
|
|
|
{ 'default:stick', '', '' }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|