create proper stairs mod replacement; create option to allow registering stairs w/out a proper recipeitem

This commit is contained in:
flux 2022-12-09 14:55:37 -08:00
parent d844a5f8b7
commit 53ac0b80b3
16 changed files with 484 additions and 155 deletions

View File

@ -29,6 +29,12 @@ repos:
entry: luacheck
pass_filenames: false
args: [--config,./moreblocks_legacy_recipes/.luacheckrc,-q,./moreblocks_legacy_recipes]
- id: luacheck_stairs
name: luacheck_stairs
language: system
entry: luacheck
pass_filenames: false
args: [--config,./stairs/.luacheckrc,-q,./stairs]
- id: luacheck_stairsplus
name: luacheck_stairsplus
language: system

View File

@ -13,6 +13,12 @@ moreblocks_legacy_recipes.enabled (Enable legacy recipes) bool false
# Add a yellow outline around trap nodes, to make them visibly distinct
moreblocks.outline_trap_nodes (Outline trap nodes) bool true
# If true, registering stairs w/out a registered recipe item will still create the stair nodes.
# This is how the stairs mod in minetest game works currently.
# Unfortunately, they will not be craftable.
# By default, trying to do this will create an error.
stairs.legacy_stairs_without_recipeitem (Allow stairs without a base node) bool false
# I guess if you want the saw to be creative-only?
stairsplus.circular_saw_crafting (Allow crafting the circular saw) bool true

31
stairs/.luacheckrc Normal file
View File

@ -0,0 +1,31 @@
std = "lua51+luajit+minetest+stairs"
unused_args = false
max_line_length = 120
stds.minetest = {
read_globals = {
"DIR_DELIM",
"minetest",
"core",
"dump",
"vector",
"nodeupdate",
"VoxelManip",
"VoxelArea",
"PseudoRandom",
"ItemStack",
"default",
"table",
"math",
"string",
}
}
stds.stairs = {
globals = {
"stairs",
},
read_globals = {
"stairsplus",
},
}

1
stairs/README.md Normal file
View File

@ -0,0 +1 @@
stairs compat: override what stairs does

View File

@ -1,29 +1,34 @@
-- stairs compat: override what stairs does
-- in stairsplus_legacy, "fix" any stairs which were already registered
if not stairsplus.has.stairs then
return
end
local f = string.format
local api = stairsplus.api
local S = stairsplus.S
local legacy = stairs.legacy
local is_legacy_drawtype = stairsplus.compat.is_legacy_drawtype
local is_legacy_paramtype2 = stairsplus.compat.is_legacy_paramtype2
local default_align_style = stairsplus.settings.default_align_style
local crafting_schemata_enabled = stairsplus.settings.crafting_schemata_enabled
local legacy_stairs_without_recipeitem = stairs.settings.legacy_stairs_without_recipeitem
function stairs.register_stair(subname, node, groups, tiles, description, sounds, worldaligntex)
if not minetest.registered_nodes[node] then
-- registering a stair for a node that doesn't exist
if legacy_stairs_without_recipeitem then
legacy.register_stair(subname, node, groups, tiles, description, sounds, worldaligntex)
return
else
error(f("attempt to register stairs for unknown node %q. " ..
"set `stairs.legacy_stairs_without_recipeitem = true` in minetest.conf to enable this behavior.", node))
end
end
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
if not minetest.registered_nodes[node] then
error(f("cannot register stairs for unknown node %q", node))
end
if is_legacy_drawtype(node) then
meta.ignore_drawtype = true
end
@ -41,7 +46,19 @@ function stairs.register_stair(subname, node, groups, tiles, description, sounds
minetest.register_alias(("stairs:stair_%s"):format(subname), api.format_name(node, "stair"))
end
function stairs.register_slab(subname, node, groups, images, description, sounds, worldaligntex)
function stairs.register_slab(subname, node, groups, tiles, description, sounds, worldaligntex)
if not minetest.registered_nodes[node] then
-- registering a stair for a node that doesn't exist
if legacy_stairs_without_recipeitem then
legacy.register_slab(subname, node, groups, tiles, description, sounds, worldaligntex)
return
else
error(f("attempt to register stairs for unknown node %q. " ..
"set `stairs.legacy_stairs_without_recipeitem = true` in minetest.conf to enable this behavior.", node))
end
end
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
@ -54,7 +71,7 @@ function stairs.register_slab(subname, node, groups, images, description, sounds
api.register_single(node, "slab_8", {
groups = groups,
tiles = images,
tiles = tiles,
description = description,
sounds = sounds,
}, meta)
@ -63,6 +80,19 @@ function stairs.register_slab(subname, node, groups, images, description, sounds
end
function stairs.register_stair_inner(subname, node, groups, tiles, description, sounds, worldaligntex, full_description)
if not minetest.registered_nodes[node] then
-- registering a stair for a node that doesn't exist
if legacy_stairs_without_recipeitem then
legacy.register_stair_inner(subname, node, groups, tiles, description, sounds, worldaligntex,
full_description)
return
else
error(f("attempt to register stairs for unknown node %q. " ..
"set `stairs.legacy_stairs_without_recipeitem = true` in minetest.conf to enable this behavior.", node))
end
end
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
@ -84,6 +114,19 @@ function stairs.register_stair_inner(subname, node, groups, tiles, description,
end
function stairs.register_stair_outer(subname, node, groups, tiles, description, sounds, worldaligntex, full_description)
if not minetest.registered_nodes[node] then
-- registering a stair for a node that doesn't exist
if legacy_stairs_without_recipeitem then
legacy.register_stair_outer(subname, node, groups, tiles, description, sounds, worldaligntex,
full_description)
return
else
error(f("attempt to register stairs for unknown node %q. " ..
"set `stairs.legacy_stairs_without_recipeitem = true` in minetest.conf to enable this behavior.", node))
end
end
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
@ -104,68 +147,12 @@ function stairs.register_stair_outer(subname, node, groups, tiles, description,
minetest.register_alias(("stairs:stair_outer_%s"):format(subname), api.format_name(node, "stair_outer"))
end
local stair_name_formats = {
stair = "stairs:stair_%s",
slab_8 = "stairs:slab_%s",
stair_inner = "stairs:stair_inner_%s",
stair_outer = "stairs:stair_outer_%s",
}
function stairsplus.compat.override_stairs(name, node, overrides, meta)
for shape, name_format in pairs(stair_name_formats) do
local stair_name = name_format:format(name)
if minetest.registered_nodes[stair_name] then
api.register_single(node, shape, overrides, meta)
local shaped_name = api.format_name(node, shape)
minetest.register_alias_force(stair_name, shaped_name)
end
end
if not crafting_schemata_enabled then
local stair_name = stair_name_formats.stair:format(name)
local slab_name = stair_name_formats.slab_8:format(name)
minetest.clear_craft({
recipe = {
{ stair_name, stair_name },
{ stair_name, stair_name },
}
})
minetest.clear_craft({
recipe = {
{ slab_name },
{ slab_name },
}
})
minetest.clear_craft({
recipe = {
{"", "", node},
{"", node, node},
{node, node, node},
}
})
minetest.clear_craft({
recipe = {
{node, node, node},
}
})
minetest.clear_craft({
recipe = {
{"", node, ""},
{node, "", node},
{node, node, node},
}
})
minetest.clear_craft({
recipe = {
{"", node, ""},
{node, node, node},
}
})
end
function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds,
worldaligntex, desc_stair_inner, desc_stair_outer)
stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds, worldaligntex)
stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds, worldaligntex)
stairs.register_stair_inner(subname, recipeitem, groups, images, desc_stair, sounds, worldaligntex,
desc_stair_inner)
stairs.register_stair_outer(subname, recipeitem, groups, images, desc_stair, sounds, worldaligntex,
desc_stair_outer)
end

4
stairs/compat.lua Normal file
View File

@ -0,0 +1,4 @@
-- for very, very old worlds...
minetest.register_alias("stairs:stair_pinewood", "stairs:stair_pine_wood")
minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")

33
stairs/init.lua Normal file
View File

@ -0,0 +1,33 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local S = minetest.get_translator(modname)
stairs = {
version = {3, 0, 0},
fork = "minetest_mods",
modname = modname,
modpath = modpath,
S = S,
has = {
default = minetest.get_modpath("default"),
i3 = minetest.get_modpath("i3"),
stairs = minetest.get_modpath("stairs"),
unified_inventory = minetest.get_modpath("unified_inventory"),
},
log = function(level, messagefmt, ...)
return minetest.log(level, ("[%s] %s"):format(modname, messagefmt:format(...)))
end,
dofile = function(...)
return dofile(table.concat({modpath, ...}, DIR_DELIM) .. ".lua")
end,
}
stairs.dofile("util")
stairs.dofile("legacy")
stairs.dofile("api")
stairs.dofile("compat")

245
stairs/legacy.lua Normal file
View File

@ -0,0 +1,245 @@
local rotate_and_place = minetest.rotate_and_place
local get_node_vars = stairs.util.get_node_vars
local get_stair_images = stairs.util.get_stair_images
local legacy = {}
local nodeboxes = {
stair = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
},
},
slab = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
stair_inner = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
{-0.5, 0.0, -0.5, 0.0, 0.5, 0.0},
},
},
stair_outer = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.0, 0.5, 0.5},
},
},
}
local function register_generic(name, recipeitem, groups, images, description, sounds, worldaligntex, nodebox)
if not nodebox then
error()
end
local light_source, texture_alpha, sunlight = get_node_vars(recipeitem)
local stair_images = get_stair_images(images, worldaligntex)
minetest.register_node(name, {
description = description,
drawtype = "nodebox",
tiles = stair_images,
use_texture_alpha = texture_alpha,
sunlight_propagates = sunlight,
light_source = light_source,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = groups,
sounds = sounds,
node_box = nodebox,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
return rotate_and_place(itemstack, placer, pointed_thing)
end,
})
end
function legacy.register_stair(subname, recipeitem, groups, images, description, sounds, worldaligntex)
local new_groups = table.copy(groups)
new_groups.stair = 1
register_generic(":stairs:stair_" .. subname, recipeitem, new_groups, images, description, sounds,
worldaligntex, nodeboxes.stair)
if recipeitem and minetest.registered_nodes[recipeitem] then
-- Recipe matches appearence in inventory
minetest.register_craft({
output = "stairs:stair_" .. subname .. " 8",
recipe = {
{"", "", recipeitem},
{"", recipeitem, recipeitem},
{recipeitem, recipeitem, recipeitem},
},
})
-- Use stairs to craft full blocks again (1:1)
minetest.register_craft({
output = recipeitem .. " 3",
recipe = {
{"stairs:stair_" .. subname, "stairs:stair_" .. subname},
{"stairs:stair_" .. subname, "stairs:stair_" .. subname},
},
})
-- Fuel
local baseburntime = minetest.get_craft_result({
method = "fuel",
width = 1,
items = {recipeitem}
}).time
if baseburntime > 0 then
minetest.register_craft({
type = "fuel",
recipe = "stairs:stair_" .. subname,
burntime = math.floor(baseburntime * 0.75),
})
end
end
end
-- Register slab
-- Node will be called stairs:slab_<subname>
function legacy.register_slab(subname, recipeitem, groups, images, description, sounds, worldaligntex)
local new_groups = table.copy(groups)
new_groups.slab = 1
register_generic(":stairs:slab_" .. subname, recipeitem, new_groups, images, description, sounds,
worldaligntex, nodeboxes.slab)
if recipeitem and minetest.registered_nodes[recipeitem] then
minetest.register_craft({
output = "stairs:slab_" .. subname .. " 6",
recipe = {
{recipeitem, recipeitem, recipeitem},
},
})
-- Use 2 slabs to craft a full block again (1:1)
minetest.register_craft({
output = recipeitem,
recipe = {
{"stairs:slab_" .. subname},
{"stairs:slab_" .. subname},
},
})
-- Fuel
local baseburntime = minetest.get_craft_result({
method = "fuel",
width = 1,
items = {recipeitem}
}).time
if baseburntime > 0 then
minetest.register_craft({
type = "fuel",
recipe = "stairs:slab_" .. subname,
burntime = math.floor(baseburntime * 0.5),
})
end
end
end
-- Register inner stair
-- Node will be called stairs:stair_inner_<subname>
function legacy.register_stair_inner(subname, recipeitem, groups, images, description, sounds, worldaligntex,
full_description)
local new_groups = table.copy(groups)
new_groups.stair = 1
if full_description then
description = full_description
else
description = "Inner " .. description
end
register_generic(":stairs:stair_inner_" .. subname, recipeitem, new_groups, images, description, sounds,
worldaligntex, nodeboxes.stair_inner)
if recipeitem and minetest.registered_nodes[recipeitem] then
minetest.register_craft({
output = "stairs:stair_inner_" .. subname .. " 7",
recipe = {
{"", recipeitem, ""},
{recipeitem, "", recipeitem},
{recipeitem, recipeitem, recipeitem},
},
})
-- Fuel
local baseburntime = minetest.get_craft_result({
method = "fuel",
width = 1,
items = {recipeitem}
}).time
if baseburntime > 0 then
minetest.register_craft({
type = "fuel",
recipe = "stairs:stair_inner_" .. subname,
burntime = math.floor(baseburntime * 0.875),
})
end
end
end
-- Register outer stair
-- Node will be called stairs:stair_outer_<subname>
function legacy.register_stair_outer(subname, recipeitem, groups, images, description, sounds, worldaligntex,
full_description)
local new_groups = table.copy(groups)
new_groups.stair = 1
if full_description then
description = full_description
else
description = "Outer " .. description
end
register_generic(":stairs:stair_outer_" .. subname, recipeitem, new_groups, images, description, sounds,
worldaligntex, nodeboxes.stair_outer)
if recipeitem and minetest.registered_nodes[recipeitem] then
minetest.register_craft({
output = "stairs:stair_outer_" .. subname .. " 6",
recipe = {
{"", recipeitem, ""},
{recipeitem, recipeitem, recipeitem},
},
})
-- Fuel
local baseburntime = minetest.get_craft_result({
method = "fuel",
width = 1,
items = {recipeitem}
}).time
if baseburntime > 0 then
minetest.register_craft({
type = "fuel",
recipe = "stairs:stair_outer_" .. subname,
burntime = math.floor(baseburntime * 0.625),
})
end
end
end
stairs.legacy = legacy

5
stairs/mod.conf Normal file
View File

@ -0,0 +1,5 @@
name = stairs
version = 3.0.0
title = Stairs+'s Stairs Compat layer
description = stair API
depends = stairsplus

5
stairs/settings.lua Normal file
View File

@ -0,0 +1,5 @@
local s = minetest.settings
stairs.settings = {
legacy_stairs_without_recipeitem = s:get_bool("stairs.legacy_stairs_without_recipeitem", false),
}

47
stairs/util.lua Normal file
View File

@ -0,0 +1,47 @@
local default_align_style = stairsplus.settings.default_align_style
local util = {}
-- get node settings to use for stairs
function util.get_node_vars(nodename)
local def = minetest.registered_nodes[nodename]
if def then
return def.light_source, def.use_texture_alpha, def.sunlight_propagates
end
end
function util.get_stair_images(images, worldaligntex)
local stair_images = {}
for i, image in ipairs(images) do
local stair_image
if type(image) == "string" then
stair_image = {
name = image,
backface_culling = true,
}
else
stair_image = table.copy(image)
if stair_image.backface_culling == nil then
stair_image.backface_culling = true
end
end
if stair_image.align_style == nil then
if worldaligntex then
stair_image.align_style = "world"
else
stair_image.align_style = default_align_style
end
end
stair_images[i] = stair_image
end
return stair_images
end
stairs.util = util

View File

@ -24,7 +24,6 @@ stds.minetest = {
stds.stairsplus = {
globals = {
"stairsplus",
"stairs", -- we take over control of stairs
},
read_globals = {
"default",

View File

@ -20,5 +20,4 @@ stairsplus.compat = {
stairsplus.dofile("compat", "i3")
stairsplus.dofile("compat", "unified_inventory")
stairsplus.dofile("compat", "stairs")
stairsplus.dofile("compat", "old_moreblocks")

View File

@ -2,4 +2,4 @@ name = stairsplus
version = 3.0.0
title = Stairs+
description = Microblock API
optional_depends = default, i3, stairs, unified_inventory
optional_depends = i3, unified_inventory

View File

@ -1,85 +1,47 @@
if stairsplus_legacy.has.stairs then
stairsplus.compat.override_stairs("wood", "default:wood")
stairsplus.compat.override_stairs("junglewood", "default:junglewood")
stairsplus.compat.override_stairs("pine_wood", "default:pine_wood")
stairsplus.compat.override_stairs("acacia_wood", "default:acacia_wood")
stairsplus.compat.override_stairs("aspen_wood", "default:aspen_wood")
stairsplus.compat.override_stairs("cobble", "default:cobble")
stairsplus.compat.override_stairs("stone", "default:stone")
stairsplus.compat.override_stairs("mossycobble", "default:mossycobble")
stairsplus.compat.override_stairs("stonebrick", "default:stonebrick")
stairsplus.compat.override_stairs("stone_block", "default:stone_block")
stairsplus.compat.override_stairs("desert_stone", "default:desert_stone")
stairsplus.compat.override_stairs("desert_cobble", "default:desert_cobble")
stairsplus.compat.override_stairs("desert_stonebrick", "default:desert_stonebrick")
stairsplus.compat.override_stairs("desert_stone_block", "default:desert_stone_block")
stairsplus.compat.override_stairs("sandstone", "default:sandstone")
stairsplus.compat.override_stairs("sandstonebrick", "default:sandstonebrick")
stairsplus.compat.override_stairs("sandstone_block", "default:sandstone_block")
stairsplus.compat.override_stairs("desert_sandstone", "default:desert_sandstone")
stairsplus.compat.override_stairs("desert_sandstone_brick", "default:desert_sandstone_brick")
stairsplus.compat.override_stairs("desert_sandstone_block", "default:desert_sandstone_block")
stairsplus.compat.override_stairs("silver_sandstone", "default:silver_sandstone")
stairsplus.compat.override_stairs("silver_sandstone_brick", "default:silver_sandstone_brick")
stairsplus.compat.override_stairs("silver_sandstone_block", "default:silver_sandstone_block")
stairsplus.compat.override_stairs("obsidian", "default:obsidian")
stairsplus.compat.override_stairs("obsidianbrick", "default:obsidianbrick")
stairsplus.compat.override_stairs("obsidian_block", "default:obsidian_block")
stairsplus.compat.override_stairs("brick", "default:brick")
stairsplus.compat.override_stairs("steelblock", "default:steelblock")
stairsplus.compat.override_stairs("tinblock", "default:tinblock")
stairsplus.compat.override_stairs("copperblock", "default:copperblock")
stairsplus.compat.override_stairs("bronzeblock", "default:bronzeblock")
stairsplus.compat.override_stairs("goldblock", "default:goldblock")
stairsplus.compat.override_stairs("ice", "default:ice")
stairsplus.compat.override_stairs("snowblock", "default:snowblock")
stairsplus.compat.override_stairs("glass", "default:glass", nil, {ignore_paramtype2 = true})
stairsplus.compat.override_stairs("obsidian_glass", "default:obsidian_glass", nil, {ignore_paramtype2 = true})
end
local default_nodes = { -- Default stairs/slabs/panels/microblocks:
"stone",
"stone_block",
"cobble",
"mossycobble",
"brick",
"sandstone",
"steelblock",
"goldblock",
"copperblock",
"bronzeblock",
"diamondblock",
"tinblock",
"desert_stone",
"desert_stone_block",
"desert_cobble",
"meselamp",
"tree",
"wood",
"jungletree",
"junglewood",
"pine_tree",
"pine_wood",
"acacia_tree",
"acacia_wood",
"aspen_tree",
"aspen_wood",
"brick",
"bronzeblock",
"cobble",
"copperblock",
"coral_skeleton",
"default:ice",
"desert_cobble",
"desert_sandstone",
"desert_sandstone_block",
"desert_sandstone_brick",
"desert_stone",
"desert_stone_block",
"desert_stonebrick",
"diamondblock",
"goldblock",
"ice",
"jungletree",
"junglewood",
"meselamp",
"mossycobble",
"obsidian",
"obsidian_block",
"obsidianbrick",
"stonebrick",
"desert_stonebrick",
"pine_tree",
"pine_wood",
"sandstone",
"sandstone_block",
"sandstonebrick",
"silver_sandstone",
"silver_sandstone_brick",
"silver_sandstone_block",
"desert_sandstone",
"desert_sandstone_brick",
"desert_sandstone_block",
"sandstone_block",
"coral_skeleton",
"ice",
"sand", -- TODO tmp remove
"silver_sandstone_brick",
"snowblock",
"steelblock",
"stone",
"stone_block",
"stonebrick",
"tinblock",
"tree",
"wood",
}
for _, name in ipairs(default_nodes) do
@ -87,6 +49,7 @@ for _, name in ipairs(default_nodes) do
if minetest.registered_nodes[node] then
stairsplus_legacy.register_legacy(node)
stairsplus.api.register_alias_all(("moreblocks:%s"):format(name), node)
stairsplus.api.register_alias_all(("stairs:%s"):format(name), node)
end
end
@ -101,6 +64,7 @@ for _, name in ipairs(glass) do
if minetest.registered_nodes[node] then
stairsplus_legacy.register_legacy(node, nil, {ignore_paramtype2 = true})
stairsplus.api.register_alias_all(("moreblocks:%s"):format(name), node)
stairsplus.api.register_alias_all(("stairs:%s"):format(name), node)
end
end

View File

@ -1,12 +1,9 @@
if stairsplus_legacy.has.stairs then
stairsplus.compat.override_stairs("straw", "farming:straw")
end
local farming_nodes = {"straw"}
for _, name in pairs(farming_nodes) do
local node = ("farming:%s"):format(name)
if minetest.registered_nodes[node] then
stairsplus_legacy.register_legacy(node)
stairsplus.api.register_alias_all(("moreblocks:%s"):format(name), node)
stairsplus.api.register_alias_all(("stairs:%s"):format(name), node)
end
end