compatability and legacy mostly done. schema recipes are all messed up for some reason.

このコミットが含まれているのは:
flux
2022-06-15 16:18:11 -07:00
コミット 92ce2e1f52
47個のファイルの変更1232行の追加710行の削除

ファイルの表示

@ -15,6 +15,24 @@ function api.register_alias_all(old_node, new_node)
end
end
function api.register_alias_custom(old_node, new_node, list)
for _, shape in ipairs(list) do
api.register_alias_single(old_node, new_node, shape)
end
end
function api.register_alias_group(old_node, new_node, group)
for _, shape in ipairs(api.shapes_by_group[group] or {}) do
api.register_alias_single(old_node, new_node, shape)
end
end
function api.register_alias_groups(old_node, new_node, groups)
for _, group in ipairs(groups) do
api.register_alias_group(old_node, new_node, group)
end
end
function api.register_alias_force_single(old_node, new_node, shape)
local old_shaped_node = api.format_name(old_node, shape)
local new_shaped_node = api.format_name(new_node, shape)
@ -48,3 +66,21 @@ function api.register_alias_force_all(old_node, new_node)
api.register_alias_force_single(old_node, new_node, shape)
end
end
function api.register_alias_force_custom(old_node, new_node, list)
for _, shape in ipairs(list) do
api.register_alias_force_single(old_node, new_node, shape)
end
end
function api.register_alias_force_group(old_node, new_node, group)
for _, shape in ipairs(api.shapes_by_group[group] or {}) do
api.register_alias_force_single(old_node, new_node, shape)
end
end
function api.register_alias_force_groups(old_node, new_node, groups)
for _, group in ipairs(groups) do
api.register_alias_force_group(old_node, new_node, group)
end
end

35
stairsplus/api/groups.lua ノーマルファイル
ファイルの表示

@ -0,0 +1,35 @@
local api = stairsplus.api
api.passthrough_groups = {}
api.scale_groups = {}
api.ignore_groups = {}
function api.register_passthrough_group(group)
api.passthrough_groups[group] = true
end
function api.register_passthrough_groups(groups)
for _, group in ipairs(groups) do
api.register_passthrough_group(group)
end
end
function api.register_scale_group(group)
api.scale_groups[group] = true
end
function api.register_scale_groups(groups)
for _, group in ipairs(groups) do
api.register_scale_group(group)
end
end
function api.register_ignore_group(group)
api.ignore_groups[group] = true
end
function api.register_ignore_groups(groups)
for _, group in ipairs(groups) do
api.register_ignore_group(group)
end
end

ファイルの表示

@ -1,7 +1,8 @@
stairsplus.api = {}
stairsplus.dofile("api", "shape")
stairsplus.dofile("api", "groups")
stairsplus.dofile("api", "node")
stairsplus.dofile("api", "station")
stairsplus.dofile("api", "alias")
stairsplus.dofile("api", "recipe")
stairsplus.dofile("api", "station")

ファイルの表示

@ -10,7 +10,9 @@ local table_sort_keys = stairsplus.util.table_sort_keys
local S = stairsplus.S
local legacy_mode = stairsplus.settings.legacy_mode
local legacy_place_mechanic = stairsplus.settings.legacy_place_mechanic
local in_creative_inventory = stairsplus.settings.in_creative_inventory
local default_align_style = stairsplus.settings.default_align_style
api.nodes_by_shape = {}
api.shapes_by_node = {}
@ -25,57 +27,175 @@ 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
local function check_node_validity(node_def, meta)
local type_ = node_def.type
if not meta.ignore_type and type_ ~= "node" then
error(("cannot register non-node %q w/ stairsplus"):format(node_def.name))
end
local drawtype = node_def.drawtype
if not meta.ignore_drawtype and (
drawtype == "airlike" or
drawtype == "liquid" or
drawtype == "flowingliquid" or
drawtype == "torchlike" or
drawtype == "signlike" or
drawtype == "plantlike" or
drawtype == "firelike" or
drawtype == "fencelike" or
drawtype == "raillike" or
drawtype == "nodebox" or
drawtype == "mesh" or
drawtype == "plantlike_rooted"
) then
error(("cannot register %q w/ drawtype %q w/ stairsplus"):format(node_def.name, drawtype))
end
local paramtype2 = node_def.paramtype2
if not meta.ignore_paramtype2 and (
paramtype2 == "flowingliquid" or
paramtype2 == "wallmounted" or
paramtype2 == "leveled" or
paramtype2 == "degrotate" or
paramtype2 == "meshoptions" or
paramtype2 == "color" or
paramtype2 == "colorfacedir" or
paramtype2 == "colorwallmounted" or
paramtype2 == "glasslikeliquidlevel" or
paramtype2 == "colordegrotate"
) then
error(("cannot register %q w/ paramtype2 %q w/ stairsplus"):format(node_def.name, paramtype2))
end
end
local function build_groups(shape, node_groups)
local groups = {
[("shape_%s"):format(shape)] = 1,
not_in_creative_inventory = in_creative_inventory and 1 or 0,
}
local shape_def = api.registered_shapes[shape]
for group, value in pairs(node_groups) do
if api.passthrough_groups[group] then
groups[group] = value
elseif api.scale_groups[group] then
groups[group] = (shape_def.eighths / 8) * value
elseif not api.ignore_groups[group] then
groups[shape_def.name_format:format(group)] = value
end
end
return groups
end
local wall_right_dirmap = {9, 18, 7, 12}
local wall_left_dirmap = {11, 16, 5, 14}
local ceil_dirmap = {20, 23, 22, 21}
function api.legacy_on_place(itemstack, placer, pointed_thing)
if not minetest.is_player(placer) then
return minetest.item_place(itemstack, placer, pointed_thing)
end
local controls = placer:get_player_control()
local sneak = controls.sneak
local aux = controls.aux1
local shaped_node_name = itemstack:get_name()
local shape = api.get_shape_of_shaped_node(shaped_node_name)
local under = pointed_thing.under
local under_node = minetest.get_node(under)
local under_shape = api.get_shape_of_shaped_node(under_node.name)
local same_cat = shape == under_shape
-- standard (floor) facedir, also used for sneak placement against the lower half of the wall
local p2 = placer and minetest.dir_to_facedir(placer:get_look_dir()) or 0
-- check which face and which quadrant we are interested in
-- this is used both to check if we're handling parallel placement in the same-category case,
-- and in general for sneak placement
local face_pos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
local face_off = vector.subtract(face_pos, under)
-- we cannot trust face_off to tell us the correct directionif the
-- under node has a non-standard shape, so use the distance between under and above
local wallmounted = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.above, under))
if same_cat and not aux then
p2 = under_node.param2
-- flip if placing above or below an upright or upside-down node
-- TODO should we also flip when placing next to a side-mounted node?
if wallmounted < 2 then
if p2 < 4 then
p2 = (p2 + 2) % 4
p2 = ceil_dirmap[p2 + 1]
elseif p2 > 19 then
p2 = ceil_dirmap[p2 - 19] - 20
p2 = (p2 + 2) % 4
end
end
else
-- for same-cat placement, aux is used to disable param2 copying
if same_cat then
aux = not aux
end
local remap = nil
-- standard placement against the wall
local use_wallmap = (wallmounted > 1 and not sneak) or (wallmounted < 2 and sneak)
-- standard placement against the ceiling, or sneak placement against the upper half of the wall
local use_ceilmap = wallmounted == 1 and not sneak
use_ceilmap = use_ceilmap or (wallmounted > 1 and sneak and face_off.y > 0)
if use_wallmap then
local left = (p2 == 0 and face_off.x < 0) or
(p2 == 1 and face_off.z > 0) or
(p2 == 2 and face_off.x > 0) or
(p2 == 3 and face_off.z < 0)
if aux then
left = not left
end
remap = left and wall_left_dirmap or wall_right_dirmap
elseif use_ceilmap then
remap = ceil_dirmap
end
if aux then
p2 = (p2 + 2) % 4
end
if remap then
p2 = remap[p2 + 1]
end
end
return minetest.item_place(itemstack, placer, pointed_thing, p2)
end
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_def.name))
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_def.name, 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_def.name, node_def.paramtype2))
end
end
function api.register_single(node, shape, overrides)
function api.register_single(node, shape, overrides, meta)
stairsplus.log("info", "registering %s %s", shape, node)
meta = meta or {}
overrides = overrides or {}
local node_def = table.copy(minetest.registered_nodes[node])
check_node_validity(node_def)
check_node_validity(node_def, meta)
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)
api.register_single(node, "micro_8", overrides, meta)
end
if (api.nodes_by_shape[shape] or {})[node] then
@ -84,15 +204,7 @@ function api.register_single(node, shape, overrides)
local shape_def = api.registered_shapes[shape]
local groups = {
[shape] = 1,
not_in_creative_inventory = in_creative_inventory and 1 or 0,
}
for group, value in pairs(node_def.groups) do
groups[shape_def.name_format:format(group)] = value
end
-- shaped_node definition
local def = {
description = S(shape_def.description, node_def.description or node),
@ -105,6 +217,8 @@ function api.register_single(node, shape, overrides)
paramtype2 = shape_def.paramtype2 or "facedir",
light_source = scale_light(node_def.light_source, shape_def),
groups = build_groups(shape, node_def.groups),
tiles = node_def.tiles,
overlay_tiles = node_def.overlay_tiles,
use_texture_alpha = node_def.use_texture_alpha,
@ -117,9 +231,9 @@ function api.register_single(node, shape, overrides)
diggable = node_def.diggable,
climbable = node_def.climbable,
move_resistance = node_def.move_resistance,
groups = groups,
}
-- see-through nodes tend to look better if we just use the first tile
if (node_def.drawtype or ""):match("glass") then
if #def.tiles > 1 then
def.tiles = {def.tiles[1]}
@ -134,6 +248,7 @@ function api.register_single(node, shape, overrides)
def.short_description = S(shape_def.description, node_def.short_description)
end
-- if there's a drop defined, and we can drop a shaped version, do so
if node_def.drop then
local item = api.get_shaped_node(node_def.drop, shape)
if item then
@ -141,11 +256,48 @@ function api.register_single(node, shape, overrides)
end
end
table_set_all(def, overrides or {})
if legacy_place_mechanic then
def.on_place = api.legacy_on_place
end
table_set_all(def, overrides)
-- set backface_culling and align_style
local align_style = meta.align_style or default_align_style
for i, tile in ipairs(def.tiles) do
if type(tile) == "string" then
def.tiles[i] = {
name = tile,
backface_culling = true,
align_style = align_style,
}
elseif not (tile.animation or tile.color) then
tile.backface_culling = true
tile.align_style = align_style
end
end
if def.overlay_tiles then
for i, tile in ipairs(def.overlay_tiles) do
if type(tile) == "string" then
def.tiles[i] = {
name = tile,
backface_culling = true,
align_style = align_style,
}
elseif not (tile.animation or tile.color) then
tile.backface_culling = true
tile.align_style = align_style
end
def.overlay_tiles[i] = tile
end
end
-- register node
local shaped_name = api.format_name(node, shape)
minetest.register_node(":" .. shaped_name, def)
-- alias old name formats
if shape_def.aliases then
local mod, name = node:match("^([^:]+):(.*)$")
for _, alias in ipairs(shape_def.aliases) do
@ -163,29 +315,31 @@ function api.register_single(node, shape, overrides)
local shapes = api.shapes_by_node[node] or {}
shapes[shape] = true
api.shapes_by_node[node] = shapes
return shaped_name
end
function api.register_all(node, overrides)
function api.register_all(node, overrides, meta)
for shape in pairs(api.registered_shapes) do
api.register_single(node, shape, overrides)
api.register_single(node, shape, overrides, meta)
end
end
function api.register_custom(node, list, overrides)
function api.register_custom(node, list, overrides, meta)
for _, shape in ipairs(list) do
api.register_single(node, shape, overrides)
api.register_single(node, shape, overrides, meta)
end
end
function api.register_group(node, group, overrides)
function api.register_group(node, group, overrides, meta)
for _, shape in ipairs(api.shapes_by_group[group] or {}) do
api.register_single(node, shape, overrides)
api.register_single(node, shape, overrides, meta)
end
end
function api.register_groups(node, groups, overrides)
function api.register_groups(node, groups, overrides, meta)
for _, group in ipairs(groups) do
api.register_group(node, group, overrides)
api.register_group(node, group, overrides, meta)
end
end
@ -193,21 +347,35 @@ function api.get_shapes(node)
return table_sort_keys(api.shapes_by_node[node])
end
-- warning: don't mutate the return value
function api.get_shapes_hash(node)
return api.shapes_by_node[node]
end
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(node, t.name)
elseif t.name == "node" then
t.name = node
local name, count = shape_or_item:match("^([^ ]+) (%d+)")
if not name then
name = shape_or_item
end
return ItemStack(t):to_string()
if name == "" then
return ""
end
count = tonumber(count)
if api.registered_shapes[name] then
name = api.format_name(node, name)
elseif name == "node" then
name = node
end
if count then
return ("%s %s"):format(name, count)
else
return name
end
end
function api.get_micronode(node)

ファイルの表示

@ -33,9 +33,15 @@ api.register_crafts_for_shapes({
local api = stairsplus.api
local function is_valid_item(item, shapes)
local item_name = ItemStack(item):get_name()
local item_name = item:match("^([^ ]*)")
return shapes[item_name] or item_name == "" or item_name:match(":")
return shapes[item_name] or item_name == "" or item_name == "node" or item_name:match(":")
end
local function is_valid_output(item, shapes)
local item_name = item:match("^([^ ]+)")
return shapes[item_name] or item_name == "node" or item_name:match(":")
end
local function verify_schema(schema)
@ -45,14 +51,14 @@ local function verify_schema(schema)
table.insert(problems, ("unimplemented schema type %q"):format(schema.type))
end
if not is_valid_item(schema.output, api.registered_shapes) then
if not is_valid_output(schema.output, api.registered_shapes) then
table.insert(problems, ("don't know how to handle output %q"):format(schema.output))
end
if schema.replacements then
for _, replacement in ipairs(schema.replacements) do
for _, item in ipairs(replacement) do
if not is_valid_item(schema.output, api.registered_shapes) then
if not is_valid_item(item, api.registered_shapes) then
table.insert(problems, ("don't know how to handle replacement item %q"):format(item))
end
end
@ -61,7 +67,7 @@ local function verify_schema(schema)
if schema.type == "shapeless" then
for _, item in ipairs(schema.recipe) do
if not is_valid_item(schema.output, api.registered_shapes) then
if not is_valid_item(item, api.registered_shapes) then
table.insert(problems, ("don't know how to handle craft item %q"):format(item))
end
end
@ -69,7 +75,7 @@ local function verify_schema(schema)
else
for _, row in ipairs(schema.recipe) do
for _, item in ipairs(row) do
if not is_valid_item(schema.output, api.registered_shapes) then
if not is_valid_item(item, api.registered_shapes) then
table.insert(problems, ("don't know how to handle craft item %q"):format(item))
end
end
@ -89,11 +95,13 @@ function api.register_craft_schema(schema)
error(problems)
end
stairsplus.log("info", "registering craft schema %s", minetest.write_json(schema))
table.insert(api.registered_recipe_schemas, schema)
end
local function has_the_right_shapes(schema, shapes)
if not is_valid_item(schema.output, shapes) then
if not is_valid_output(schema.output, shapes) then
return false
end
@ -130,15 +138,19 @@ end
local function register_for_schema(node, shapes, schema)
local recipe = table.copy(schema)
if shapes[recipe.output] then
if is_valid_output(recipe.output, shapes) then
recipe.output = api.get_shaped_node(node, recipe.output)
else
return
end
if recipe.replacements then
for _, replacement in ipairs(recipe.replacements) do
for i, item in ipairs(replacement) do
if shapes[item] then
if is_valid_item(item, shapes) then
replacement[i] = api.get_shaped_node(node, item)
else
return
end
end
end
@ -146,21 +158,27 @@ local function register_for_schema(node, shapes, schema)
if recipe.type == "shapeless" then
for i, item in ipairs(recipe.recipe) do
if shapes[item] then
if is_valid_item(item, shapes) then
recipe.recipe[i] = api.get_shaped_node(node, item)
else
return
end
end
elseif recipe.type == "shaped" or recipe.type == nil then
for _, row in ipairs(schema.recipe) do
for i, item in ipairs(row) do
if shapes[item] then
if is_valid_item(item, shapes) then
row[i] = api.get_shaped_node(node, item)
else
return
end
end
end
end
stairsplus.log("info", "registering recipe %s", minetest.serialize(recipe):sub(#("return ")))
minetest.register_craft(recipe)
end

ファイルの表示

@ -18,6 +18,7 @@ api.registered_shapes = {}
api.shapes_by_group = {}
function api.register_shape(name, def)
stairsplus.log("info", "registering shape %q", name)
api.registered_shapes[name] = def
for group in pairs(def.shape_groups or {}) do

ファイルの表示

@ -9,6 +9,11 @@ local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) o
local station = {}
--[[
TODO this isn't actually modular in the right way for adding different kinds of stations
TODO e.g. some of this stuff is very particular to the saw itself
]]
local function get_cost(shaped_node)
if shaped_node == "" then
return 0