circular saw works now; still need to do compatabilit and testing

This commit is contained in:
flux
2022-06-14 16:30:41 -07:00
parent b9eed16713
commit a2c8e2db8e
12 changed files with 410 additions and 259 deletions

View File

@ -25,14 +25,63 @@ local function scale_light(light_source, shape_def)
return math.max(1, math.min(math.round(light_source * shape_def.eighths / 4), light_source))
end
function api.format_name(shape, node)
function api.format_name(node, shape)
local mod, name = node:match("^([^:]+):(.*)$")
local shape_def = api.registered_shapes[shape]
return ("%s:%s"):format(mod, shape_def.name_format:format(name))
end
local function check_node_validity(node_def)
if node_def.type ~= "node" then
error(("cannot register non-node %q w/ stairsplus"):format(node))
end
if (
node_def.drawtype == "airlike" or
node_def.drawtype == "liquid" or
node_def.drawtype == "flowingliquid" or
node_def.drawtype == "torchlike" or
node_def.drawtype == "signlike" or
node_def.drawtype == "plantlike" or
node_def.drawtype == "firelike" or
node_def.drawtype == "fencelike" or
node_def.drawtype == "raillike" or
node_def.drawtype == "nodebox" or
node_def.drawtype == "mesh" or
node_def.drawtype == "plantlike_rooted"
) then
error(("cannot register %q w/ drawtype %q w/ stairsplus"):format(node, node_def.drawtype))
end
if (
node_def.paramtype2 == "flowingliquid" or
node_def.paramtype2 == "wallmounted" or
node_def.paramtype2 == "leveled" or
node_def.paramtype2 == "degrotate" or
node_def.paramtype2 == "meshoptions" or
node_def.paramtype2 == "color" or
node_def.paramtype2 == "colorfacedir" or
node_def.paramtype2 == "colorwallmounted" or
node_def.paramtype2 == "glasslikeliquidlevel" or
node_def.paramtype2 == "colordegrotate"
) then
error(("cannot register %q w/ paramtype2 %q w/ stairsplus"):format(node, node_def.paramtype2))
end
end
function api.register_single(node, shape, overrides)
local node_def = table.copy(minetest.registered_nodes[node])
check_node_validity(node_def)
if shape ~= "micro_8" and not (api.nodes_by_shape.micro_8 or {})[node] then
-- always make sure a microblock exists
api.register_single(node, "micro_8", overrides)
end
if (api.nodes_by_shape[shape] or {})[node] then
return -- already registered
end
local shape_def = api.registered_shapes[shape]
local groups = {
@ -46,35 +95,47 @@ function api.register_single(node, shape, overrides)
local def = {
description = S(shape_def.description, node_def.description or node),
drawtype = shape_def.drawtype,
mesh = shape_def.mesh,
node_box = shape_def.node_box,
collision_box = shape_def.collision_box,
selection_box = shape_def.selection_box,
groups = groups,
use_texture_alpha = node_def.use_texture_alpha,
paramtype = shape_def.paramtype or "light",
paramtype2 = shape_def.paramtype2 or "facedir",
light_source = scale_light(node_def.light_source, shape_def),
tiles = node_def.tiles,
overlay_tiles = node_def.overlay_tiles,
use_texture_alpha = node_def.use_texture_alpha,
color = node_def.color,
stack_max = node_def.stack_max,
sound = node_def.sound,
is_ground_content = node_def.is_ground_content,
walkable = node_def.walkable,
pointable = node_def.pointable,
diggable = node_def.diggable,
climbable = node_def.climbable,
move_resistance = node_def.move_resistance,
groups = groups,
}
local tiles = node_def.tiles
if #tiles > 1 and (node_def.drawtype or ""):match("glass") then
def.tiles = {tiles[1]}
else
def.tiles = tiles
if (node_def.drawtype or ""):match("glass") then
if #def.tiles > 1 then
def.tiles = {def.tiles[1]}
end
if def.overlay_tiles and #def.overlay_tiles > 1 then
def.overlay_tiles = {def.overlay_tiles[1]}
end
end
if node_def.short_description then
def.short_description = S(shape_def.description, node_def.short_description)
end
if def.use_texture_alpha == nil then
def.use_texture_alpha = node_def.use_texture_alpha
end
if node_def.drop then
local item = api.get_shaped_name(node_def.drop, shape)
local item = api.get_shaped_node(node_def.drop, shape)
if item then
def.drop = item
end
@ -82,7 +143,7 @@ function api.register_single(node, shape, overrides)
table_set_all(def, overrides or {})
local shaped_name = api.format_name(shape, node)
local shaped_name = api.format_name(node, shape)
minetest.register_node(":" .. shaped_name, def)
if shape_def.aliases then
@ -122,6 +183,12 @@ function api.register_group(node, group, overrides)
end
end
function api.register_groups(node, groups, overrides)
for _, group in ipairs(groups) do
api.register_group(node, group, overrides)
end
end
function api.get_shapes(node)
return table_sort_keys(api.shapes_by_node[node])
end
@ -130,11 +197,11 @@ function api.get_shapes_hash(node)
return api.shapes_by_node[node]
end
function api.get_shaped_name(node, shape_or_item)
function api.get_shaped_node(node, shape_or_item)
local t = ItemStack(shape_or_item):to_table()
if api.registered_shapes[t.name] then
t.name = api.format_name(t.name, node)
t.name = api.format_name(node, t.name)
elseif t.name == "node" then
t.name = node
@ -143,9 +210,33 @@ function api.get_shaped_name(node, shape_or_item)
return ItemStack(t):to_string()
end
function api.get_micronode(node)
return api.format_name(node, "micro_8")
end
api.node_by_shaped_node = {}
api.shape_by_shaped_node = {}
function api.get_node_of_shaped_node(shaped_node)
return api.node_by_shaped_node[shaped_node]
end
function api.get_shape_of_shaped_node(shaped_node)
return api.shape_by_shaped_node[shaped_node]
end
minetest.register_on_mods_loaded(function()
stairsplus.log("info", "registering schema crafts")
for node in pairs(api.shapes_by_node) do
for node, shapes in pairs(api.shapes_by_node) do
api.register_schema_crafts_for_node(node)
for shape in pairs(shapes) do
local shaped_node = api.format_name(node, shape)
api.node_by_shaped_node[shaped_node] = node
api.shape_by_shaped_node[shaped_node] = shape
end
api.node_by_shaped_node[node] = node
api.shape_by_shaped_node[node] = "node"
end
end)