mirror of
https://git.0x7be.net/dirk/uniham.git
synced 2024-11-19 22:03:46 +01:00
73 lines
2.5 KiB
Lua
73 lines
2.5 KiB
Lua
-- 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',
|
||
-- 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
|
||
-- 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.
|
||
--
|
||
-- @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)'
|
||
texture = texture:gsub('+.', {
|
||
['+s'] = 'default_stick.png',
|
||
['+h'] = definition.head,
|
||
['+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 on_use(itemstack, player, pointed_thing)
|
||
end
|
||
})
|
||
|
||
minetest.register_craft({
|
||
output = minetest.get_current_modname()..':'..short_id,
|
||
recipe = {
|
||
{ '', definition.craft, '' },
|
||
{ '', 'default:stick', definition.craft },
|
||
{ 'default:stick', '', '' }
|
||
}
|
||
})
|
||
end
|