mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-07-16 06:40:34 +02:00
create proper stairs mod replacement; create option to allow registering stairs w/out a proper recipeitem
This commit is contained in:
31
stairs/.luacheckrc
Normal file
31
stairs/.luacheckrc
Normal 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
1
stairs/README.md
Normal file
@ -0,0 +1 @@
|
||||
stairs compat: override what stairs does
|
158
stairs/api.lua
Normal file
158
stairs/api.lua
Normal file
@ -0,0 +1,158 @@
|
||||
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 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 is_legacy_drawtype(node) then
|
||||
meta.ignore_drawtype = true
|
||||
end
|
||||
if is_legacy_paramtype2(node) then
|
||||
meta.ignore_paramtype2 = true
|
||||
end
|
||||
|
||||
api.register_single(node, "stair", {
|
||||
groups = groups,
|
||||
tiles = tiles,
|
||||
description = description,
|
||||
sounds = sounds,
|
||||
}, meta)
|
||||
|
||||
minetest.register_alias(("stairs:stair_%s"):format(subname), api.format_name(node, "stair"))
|
||||
end
|
||||
|
||||
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
|
||||
}
|
||||
if is_legacy_drawtype(node) then
|
||||
meta.ignore_drawtype = true
|
||||
end
|
||||
if is_legacy_paramtype2(node) then
|
||||
meta.ignore_paramtype2 = true
|
||||
end
|
||||
|
||||
api.register_single(node, "slab_8", {
|
||||
groups = groups,
|
||||
tiles = tiles,
|
||||
description = description,
|
||||
sounds = sounds,
|
||||
}, meta)
|
||||
|
||||
minetest.register_alias(("stairs:slab_%s"):format(subname), api.format_name(node, "slab_8"))
|
||||
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
|
||||
}
|
||||
if is_legacy_drawtype(node) then
|
||||
meta.ignore_drawtype = true
|
||||
end
|
||||
if is_legacy_paramtype2(node) then
|
||||
meta.ignore_paramtype2 = true
|
||||
end
|
||||
|
||||
api.register_single(node, "stair_inner", {
|
||||
groups = groups,
|
||||
tiles = tiles,
|
||||
description = full_description or S("Inner @1", description),
|
||||
sounds = sounds,
|
||||
}, meta)
|
||||
|
||||
minetest.register_alias(("stairs:stair_inner_%s"):format(subname), api.format_name(node, "stair_inner"))
|
||||
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
|
||||
}
|
||||
if is_legacy_drawtype(node) then
|
||||
meta.ignore_drawtype = true
|
||||
end
|
||||
if is_legacy_paramtype2(node) then
|
||||
meta.ignore_paramtype2 = true
|
||||
end
|
||||
|
||||
api.register_single(node, "stair_outer", {
|
||||
groups = groups,
|
||||
tiles = tiles,
|
||||
description = full_description or S("Outer @1", description),
|
||||
sounds = sounds,
|
||||
}, meta)
|
||||
|
||||
minetest.register_alias(("stairs:stair_outer_%s"):format(subname), api.format_name(node, "stair_outer"))
|
||||
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
4
stairs/compat.lua
Normal 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
33
stairs/init.lua
Normal 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
245
stairs/legacy.lua
Normal 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
5
stairs/mod.conf
Normal 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
5
stairs/settings.lua
Normal 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
47
stairs/util.lua
Normal 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
|
Reference in New Issue
Block a user