make the embossing effect configurable

This commit is contained in:
Dirk Sohler 2019-06-13 17:55:49 +02:00
parent a0b5fdd473
commit 430c5b1a84
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
4 changed files with 56 additions and 18 deletions

@ -46,7 +46,10 @@ The *Unified Hammers API* can be used by calling the `uniham.register_hammer` fu
```lua
uniham.register_hammer('my_cool_id', {
name = 'My Cool Hammer',
head = 'mymod_my_cool_head_base_texture.png',
head = {
texture = 'mymod_my_cool_head_base_texture.png',
opacity = 51.2
}
--- Alternative to `head`, see description below
-- texture = 'mymod_my_cool_hammer_texture.png',
craft = 'mymod:my_cool_item',
@ -54,7 +57,7 @@ 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` with the embossing effect being 20% visible (51.2) 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.

@ -5,56 +5,74 @@ local S = uniham.translator
register_hammer('hammer_bronze', {
name = S('Bronze Hammer'),
head = 'default_bronze_block.png',
head = {
texture = 'default_bronze_block.png',
},
craft = 'default:bronze_ingot',
uses = 150
})
register_hammer('hammer_diamond', {
name = S('Diamond Hammer'),
head = 'default_diamond_block.png',
head = {
texture = 'default_diamond_block.png',
opacity = 120
},
craft = 'default:diamond',
uses = 300
})
register_hammer('hammer_gold', {
name = S('Golden Hammer'),
head = 'default_gold_block.png',
head = {
texture = 'default_gold_block.png',
},
craft = 'default:gold_ingot',
uses = 100
})
register_hammer('hammer_mese', {
name = S('Mese Hammer'),
head = 'default_mese_block.png',
head = {
texture = 'default_mese_block.png',
},
craft = 'default:mese_crystal',
uses = 350
})
register_hammer('hammer_obsidian', {
name = S('Obsidian Hammer'),
head = 'default_obsidian_block.png',
head = {
texture = 'default_obsidian_block.png',
opacity = 25
},
craft = 'default:obsidian_shard',
uses = 400
})
register_hammer('hammer_steel', {
name = S('Steel Hammer'),
head = 'default_steel_block.png',
head = {
texture = 'default_steel_block.png',
},
craft = 'default:steel_ingot',
uses = 200
})
register_hammer('hammer_stone', {
name = S('Stone Hammer'),
head = 'default_stone.png',
head = {
texture = 'default_stone.png',
},
craft = 'default:cobble',
uses = 70
})
register_hammer('hammer_wood', {
name = S('Wooden Hammer'),
head = 'default_wood.png',
head = {
texture = 'default_wood.png',
},
craft = 'default:wood',
uses = 30
})

@ -5,14 +5,18 @@ local S = uniham.translator
register_hammer('hammer_mithril', {
name = S('Mithril Hammer'),
head = 'moreores_mithril_block.png',
head = {
texture = 'moreores_mithril_block.png',
},
craft = 'moreores:mithril_ingot',
uses = 450
})
register_hammer('hammer_silver', {
name = S('Silver Hammer'),
head = 'moreores_silver_block.png',
head = {
texture = 'moreores_silver_block.png',
},
craft = 'moreores:silver_ingot',
uses = 250
})

@ -6,7 +6,10 @@ local crush_nodes = uniham.crush_nodes
--
-- definition = {
-- name = 'Name of the hammer',
-- head = 'head_material_texture.png',
-- head = {
-- texture = 'head_material_texture.png',
-- opacity = 20
-- },
-- texture = 'hammer_texture.png',
-- craft = 'crafting:material',
-- on_use = on_use_function,
@ -16,9 +19,16 @@ local crush_nodes = uniham.crush_nodes
-- 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.
-- `head` is a texture table containing two entries. The `texture` entry
-- defines the texture that is used as base for the hammer head texture mask.
-- The `opacity` entry is the opacity value between 0 (fully transparent) and
-- 255 (fully visible) of the embossing effect. When omitting the opacity
-- value, 51.2 will be used.
--
-- 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. To change the
-- embossing effect add `uniham_emboss.png` with transparent backgground. The
-- embossing texture is simply overlayed over the generated head texture.
--
-- 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
@ -54,17 +64,20 @@ local crush_nodes = uniham.crush_nodes
-- @return void
uniham.register_hammer = function (short_id, definition)
local on_use = definition.on_use or crush_nodes
local autotexture = '([combine:16x16:-1,1=+s)^((+h^+m)^[makealpha:0,0,0)'
local autotexture = '(([combine:16x16:-1,1=+s)^((+h^+m)^[makealpha:0,0,0))'
local hammer_id = minetest.get_current_modname()..':'..short_id
local texture = ''
local opacity = ''
if definition.head and not definition.texture then
texture = autotexture:gsub('+.', {
['+s'] = 'default_stick.png',
['+h'] = definition.head,
['+h'] = definition.head.texture,
['+m'] = 'uniham_head_mask.png'
})
texture = '(('..texture..')^(uniham_emboss.png^[opacity:51.2))'
opacity = definition.head.opacity or 51.2
texture = '('..texture..'^(uniham_emboss.png^[opacity:'..opacity..'))'
end
if definition.texture then