add more ladder types

addresses #2
This commit is contained in:
𝘋𝘪𝘳𝘬 2023-08-16 23:10:16 +02:00
parent 0de557c588
commit e299cc79b3
Signed by: dirk
GPG Key ID: F44E7467B12D6707
4 changed files with 94 additions and 37 deletions

View File

@ -39,4 +39,4 @@ ladders_3d_exact_selection_box = false
ladders_3d_walkable_by_default = false
```
The listing above shows the default values. Please also refer to `settingtypes.txt` for a more in-detail description of the parameters.
The listing above shows the default values. Please also refer to `settingtypes.txt` for a more in-detail description of the parameters. Individual registration files can introduce own configuration options. If the files are built-in the options should be noted in `settingtypes.txt`.

View File

@ -1,3 +1,8 @@
-- vim:nowrap
--
-- This file contains wide tables to wrapping is disabled.
-- Ladders created with the default wood variants from “Minetest Game”, the
-- steel ladder and the generic wood ladder are left out. Those ladders are
-- handled in a separate registration file.
@ -10,44 +15,92 @@
if ladders_3d.game.id ~= 'minetest' then return end
-- Get the translator
local S = ladders_3d.translator
local texture = '(+base^(+mask^[opacity:+opacity))'
local image = '((+texture)^[mask:+mask)'
local ladders = {
aspen_wood = { S('Aspen Wood Ladder'), 'default:aspen_wood', 32 },
pine_wood = { S('Pine Wood Ladder'), 'default:pine_wood', 32 },
jungle_wood = { S('Jungle Wood Ladder'), 'default:junglewood', 32 },
acacia_wood = { S('Acacia Wood Ladder'), 'default:acacia_wood', 32 },
}
-- Mass register ladders from a table
--
-- ladders = {
-- short_short_id = { 'My Cool Ladder', material_definition, 'mymod_my_cool_texture.png', overlay_opacity },
-- another_id = { 'My Other Ladder', material_definition, 'mymod_my_other_texture.png', overlay_opacity },
-- -- etc.
-- }
--
-- `material_definition` can either be a single node ID or a table. If it is a
-- single node ID this ID is used as source for the sounds and as crafting
-- material. If its a table, the first table entry is used a crafting material
-- and the second entry is used as source for the sounds, etc.
--
-- `overlay_opacity` is number between 0 and 255 to define the opacity of the
-- visual “3D effect mask”.
--
-- @see ladders_3d.register
--
-- @param ladders The table as desicbed
local mass_register = function (ladders)
local texture_template = '(+base^(+mask^[opacity:+opacity))'
local image_template = '((+texture)^[mask:+mask)'
for short_short_id,definition in pairs(ladders) do
local ladder_name = definition[1]
local material = definition[2]
local node_def = minetest.registered_nodes[definition[2]] or {}
-- Get node definition
if type(definition[2]) == 'table' then
material = definition[2][1]
node_def = definition[2][2]
end
-- Build texture
local texture = (texture_template:gsub('%+%w+', {
['+base'] = '('..definition[3]..')',
['+mask'] = 'ladders_3d_default_shape_shading_mask.png',
['+opacity'] = definition[4]
}))
-- Build image
local image = (image_template:gsub('%+%w+', {
['+texture'] = texture,
['+mask'] = 'ladders_3d_default_shape_inventory_mask.png'
}))
-- Register ladders
ladders_3d.register(short_short_id, {
description = definition[1],
recipe = {
{ material, '', material },
{ material, material, material },
{ material, '', material }
},
yield = 7,
uncraft = material..' 1',
tiles = { texture },
sounds = node_def.sounds,
image = image
})
end
end
for short_short_id,definition in pairs(ladders) do
local node_def = minetest.registered_nodes[definition[2]]
local texture = (texture:gsub('%+%w+', {
['+base'] = '(('..node_def.tiles[1]..')^[transformR180)',
['+mask'] = 'ladders_3d_default_shape_shading_mask.png',
['+opacity'] = definition[3]
}))
local image = (image:gsub('%+%w+', {
['+texture'] = texture,
['+mask'] = 'ladders_3d_default_shape_inventory_mask.png'
}))
ladders_3d.register('default_'..short_short_id, {
description = definition[1],
recipe = {
{ definition[2], '', definition[2], },
{ definition[2], definition[2], definition[2], },
{ definition[2], '', definition[2], }
},
yield = 7,
uncraft = definition[2]..' 1',
tiles = { texture },
sounds = node_def.sounds,
image = image
-- Wooden ladders from default wood nodes
if ladders_3d.option('default_wooden_ladders', true) == true then
mass_register({
default_aspen_wood = { S('Aspen Wood Ladder'), 'default:aspen_wood', 'default_aspen_wood.png^[transformR180', 32 },
default_pine_wood = { S('Pine Wood Ladder'), 'default:pine_wood', 'default_pine_wood.png^[transformR180', 32 },
default_jungle_wood = { S('Jungle Wood Ladder'), 'default:junglewood', 'default_junglewood.png^[transformR180', 32 },
default_acacia_wood = { S('Acacia Wood Ladder'), 'default:acacia_wood', 'default_acacia_wood.png^[transformR180', 32 },
})
end
-- Metal ladders from default metal nodes
if ladders_3d.option('default_metal_ladders', true) == true then
mass_register({
default_gold = { S('Golden Ladder'), { 'default:gold_ingot', 'default:gold_block' }, 'default_gold_block.png', 32 },
default_tin = { S('Tin Ladder'), { 'default:tin_ingot', 'default:tin_block' }, 'default_tin_block.png', 32 },
default_bronze = { S('Bronze Ladder'), { 'default:bronze_ingot', 'default:bronze_block' }, 'default_bronze_block.png', 64 },
default_copper = { S('Copper Ladder'), { 'default:copper_ingot', 'default:copper_block' }, 'default_copper_block.png', 32 },
})
end

View File

@ -23,3 +23,9 @@ ladders_3d_load_default (Enable built-in support for “default”) bool true
# This only looks good when the default ladder texture was not changed or when the changed texture has the same shape as the default ladder texture. This is considered a “hack” to prevent having to create aliases or messing with the node registration.
ladders_3d_override_default_ladders (Override default ladders to look 3D) bool true
# Ladders made from the default wood types except the generic “wood” ladder
ladders_3d_default_wooden_ladders (Register wooden ladders) bool true
# Ladders made from the default metal types except the steel ladder
ladders_3d_default_metal_ladders (Register metal ladders) bool true

View File

@ -86,6 +86,4 @@ ladders_3d.register = function (short_id, definition)
recipe = { ladder_id }
})
end
end