mirror of
https://git.0x7be.net/dirk/uniham.git
synced 2024-11-28 18:23:55 +01:00
allow custom hammer textures
This commit is contained in:
parent
f74c71b448
commit
145208ade5
@ -46,7 +46,9 @@ The *Universal Hammer API* can be used by calling the `uniham.register_hammer` f
|
|||||||
```lua
|
```lua
|
||||||
uniham.register_hammer('my_cool_id', {
|
uniham.register_hammer('my_cool_id', {
|
||||||
name = 'My Cool Hammer',
|
name = 'My Cool Hammer',
|
||||||
head = 'mymod_my_cool_texture.png',
|
head = 'mymod_my_cool_head_base_texture.png',
|
||||||
|
--- Alternative to `head`, see description below
|
||||||
|
-- texture = 'mymod_my_cool_hammer_texture.png',
|
||||||
craft = 'mymod:my_cool_item',
|
craft = 'mymod:my_cool_item',
|
||||||
uses = 200
|
uses = 200
|
||||||
})
|
})
|
||||||
@ -54,6 +56,8 @@ uniham.register_hammer('my_cool_id', {
|
|||||||
|
|
||||||
This registers a hammer with the name “My Cool Hammer” that has the ID `mymod:my_cool_id`. The head base texture is `mymod_my_cool_texture.png` and the texture is automatically masked to form a hammer head.
|
This registers a hammer with the name “My Cool Hammer” that has the ID `mymod:my_cool_id`. The head base texture is `mymod_my_cool_texture.png` and the texture is automatically masked to form a hammer head.
|
||||||
|
|
||||||
|
If instead of `head` the value `texture` is provided then the automatic texture generation is disabled and the hammer will get the texture defined by the `texture` value. If both values are added then the `texture` value is given precedence.
|
||||||
|
|
||||||
The hammer is crafted like the provided hammers with two sticks and two of the items provided for `craft`.
|
The hammer is crafted like the provided hammers with two sticks and two of the items provided for `craft`.
|
||||||
|
|
||||||
`uses` defines how often the hammer can be used. The value also gets stored in the tool’s definition as `_uniham.uses` that can be used by a custom `on_use` function for example
|
`uses` defines how often the hammer can be used. The value also gets stored in the tool’s definition as `_uniham.uses` that can be used by a custom `on_use` function for example
|
||||||
|
@ -7,6 +7,7 @@ local use_hammer = uniham.use_hammer
|
|||||||
-- definition = {
|
-- definition = {
|
||||||
-- name = 'Name of the hammer',
|
-- name = 'Name of the hammer',
|
||||||
-- head = 'head_material_texture.png',
|
-- head = 'head_material_texture.png',
|
||||||
|
-- texture = 'hammer_texture.png',
|
||||||
-- craft = 'crafting:material',
|
-- craft = 'crafting:material',
|
||||||
-- on_use = on_use_function,
|
-- on_use = on_use_function,
|
||||||
-- uses = 123,
|
-- uses = 123,
|
||||||
@ -19,6 +20,10 @@ local use_hammer = uniham.use_hammer
|
|||||||
-- To change the mask textture packs need to add `uniham_head_mask.png` with
|
-- To change the mask textture packs need to add `uniham_head_mask.png` with
|
||||||
-- another file. All black pixels will become transparent.
|
-- another file. All black pixels will become transparent.
|
||||||
--
|
--
|
||||||
|
-- Instead of `head` the entry `texture` can be used. This does not auto-create
|
||||||
|
-- The hammer texture but uses the given texture file as hammer texture. If
|
||||||
|
-- both `head` and `texture` are given `texture` gets precedence.
|
||||||
|
--
|
||||||
-- With `craft` the material to craft the hammer from is defined. Hammers are
|
-- 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
|
-- crafted all the same with the provided material for x and a stick for s
|
||||||
--
|
--
|
||||||
@ -43,14 +48,22 @@ local use_hammer = uniham.use_hammer
|
|||||||
-- @see <https://dev.minetest.net/on_use#on_use>
|
-- @see <https://dev.minetest.net/on_use#on_use>
|
||||||
-- @return void
|
-- @return void
|
||||||
uniham.register_hammer = function (short_id, definition)
|
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
|
local on_use = definition.on_use or use_hammer
|
||||||
|
local autotexture = '([combine:16x16:-1,1=+s)^((+h^+m)^[makealpha:0,0,0)'
|
||||||
|
local texture = ''
|
||||||
|
|
||||||
|
if definition.head and not definition.texture then
|
||||||
|
texture = autotexture:gsub('+.', {
|
||||||
|
['+s'] = 'default_stick.png',
|
||||||
|
['+h'] = definition.head,
|
||||||
|
['+m'] = 'uniham_head_mask.png'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if definition.texture then
|
||||||
|
texture = definition.texture
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_tool('uniham:'..short_id, {
|
minetest.register_tool('uniham:'..short_id, {
|
||||||
description = definition.name,
|
description = definition.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user