documentation, bugfixes

This commit is contained in:
flux
2022-06-20 14:29:13 -07:00
parent b6d2bc09e2
commit 143778621e
19 changed files with 444 additions and 158 deletions

View File

@ -4,7 +4,7 @@ local in_creative_inventory = stairsplus.settings.in_creative_inventory
local in_craft_guide = stairsplus.settings.in_craft_guide
api.passthrough_groups = {}
api.scale_groups = {}
api.scaling_groups = {}
api.ignore_groups = {}
function api.register_passthrough_group(group)
@ -17,13 +17,13 @@ function api.register_passthrough_groups(groups)
end
end
function api.register_scale_group(group)
api.scale_groups[group] = true
function api.register_scaling_group(group)
api.scaling_groups[group] = true
end
function api.register_scale_groups(groups)
function api.register_scaling_groups(groups)
for _, group in ipairs(groups) do
api.register_scale_group(group)
api.register_scaling_group(group)
end
end
@ -52,7 +52,7 @@ function api.build_groups(node, shape)
if api.passthrough_groups[group] then
groups[group] = value
elseif api.scale_groups[group] then
elseif api.scaling_groups[group] then
groups[group] = (shape_def.eighths / 8) * value
elseif not api.ignore_groups[group] then

View File

@ -231,20 +231,20 @@ function api.register_all(node, overrides, meta)
end
end
function api.register_custom(node, list, overrides, meta)
for _, shape in ipairs(list) do
function api.register_custom(node, shapes, overrides, meta)
for _, shape in ipairs(shapes) do
api.register_single(node, shape, overrides, meta)
end
end
function api.register_group(node, group, overrides, meta)
for _, shape in ipairs(api.shapes_by_group[group] or {}) do
function api.register_group(node, shape_group, overrides, meta)
for _, shape in ipairs(api.shapes_by_group[shape_group] or {}) do
api.register_single(node, shape, overrides, meta)
end
end
function api.register_groups(node, groups, overrides, meta)
for _, group in ipairs(groups) do
function api.register_groups(node, shape_groups, overrides, meta)
for _, group in ipairs(shape_groups) do
api.register_group(node, group, overrides, meta)
end
end

View File

@ -185,7 +185,7 @@ function api.register_crafts_for_shapes(recipe)
type = "cooking",
output = api.get_schema_recipe_item(recipe.output, shape),
recipe = api.get_schema_recipe_item(recipe.recipe, shape),
cooktime = recipe.cooktime(api.registered_shapes[shape].eighths),
cooktime = recipe.cooktime * (api.registered_shapes[shape].eighths / 8),
})
end
@ -196,7 +196,7 @@ function api.register_crafts_for_shapes(recipe)
minetest.register_craft({
type = "fuel",
recipe = api.get_schema_recipe_item(recipe.recipe, shape),
burntime = recipe.burntime(api.registered_shapes[shape].eighths),
burntime = recipe.burntime * (api.registered_shapes[shape].eighths / 8),
})
end

View File

@ -19,11 +19,19 @@ api.shapes_by_group = {}
function api.register_shape(name, def)
stairsplus.log("info", "registering shape %q", name)
def.shape_groups = def.shape_groups or {}
api.registered_shapes[name] = def
for group in pairs(def.shape_groups or {}) do
for group in pairs(def.shape_groups) do
local shapes = api.shapes_by_group[group] or {}
table.insert(shapes, name)
api.shapes_by_group[group] = shapes
end
end
function api.register_shape_group(shape_group, shapes)
for _, shape in ipairs(shapes) do
api.registered_shapes[shape].shape_groups[shape_group] = 1
end
api.shapes_by_group[shape_group] = shapes
end

View File

@ -41,14 +41,14 @@ function station.can_dig(meta, inv)
return inv:is_empty("stairsplus:input") and inv:is_empty("stairsplus:micro")
end
function station.on_receive_fields(meta, inv, formname, fields, sender, build_formspec, update_infotext)
function station.on_receive_fields(meta, inv, formname, fields, sender, build_formspec, update_metadata)
local max = tonumber(fields.max_offered)
if max and max > 0 then
meta:set_int("stairsplus:max_offered", max)
-- Update to show the correct number of items:
station.update_inventory(meta, inv)
if update_infotext then
update_infotext(meta, inv)
if update_metadata then
update_metadata(meta, inv)
end
if build_formspec then
@ -121,22 +121,22 @@ function station.update_inventory(meta, inv, taken_stack)
end
end
function station.on_inventory_put(meta, inv, listname, index, stack, player, update_infotext)
function station.on_inventory_put(meta, inv, listname, index, stack, player, update_metadata)
station.update_inventory(meta, inv)
if update_infotext then
update_infotext(meta, inv)
if update_metadata then
update_metadata(meta, inv)
end
end
function station.on_inventory_take(meta, inv, listname, index, stack, player, update_infotext)
function station.on_inventory_take(meta, inv, listname, index, stack, player, update_metadata)
if listname == "stairsplus:output" then
station.update_inventory(meta, inv, stack)
else
station.update_inventory(meta, inv)
end
if update_infotext then
update_infotext(meta, inv)
if update_metadata then
update_metadata(meta, inv)
end
end
@ -181,9 +181,13 @@ function station.allow_inventory_put(meta, inv, listname, index, stack, player)
return math.min(count, available_count)
end
function station.initialize_metadata(meta, inv, shape_groups, build_formspec, update_infotext)
function station.initialize_metadata(meta, inv, shape_groups, build_formspec, update_metadata)
meta:set_string("stairsplus:shape_groups", minetest.write_json(shape_groups))
if meta:get_int("stairsplus:max_offered") == 0 then
if meta:get_int("max_offered") ~= 0 then
meta:set_int("stairsplus:max_offered", meta:get_int("max_offered"))
elseif meta:get_int("stairsplus:max_offered") == 0 then
meta:set_int("stairsplus:max_offered", default_stack_max)
end
@ -191,16 +195,21 @@ function station.initialize_metadata(meta, inv, shape_groups, build_formspec, up
meta:set_string("formspec", build_formspec(meta, inv))
end
if update_infotext then
update_infotext(meta, inv)
if update_metadata then
update_metadata(meta, inv)
end
end
function station.initialize_inventory(inv)
function station.initialize_inventory(inv, shape_groups)
local output_size = 0
for _, group in ipairs(shape_groups) do
output_size = output_size + #api.shapes_by_group[group]
end
inv:set_size("stairsplus:input", 1)
inv:set_size("stairsplus:micro", 1)
inv:set_size("stairsplus:recycle", 1)
inv:set_size("stairsplus:output", 7 * 7)
inv:set_size("stairsplus:output", output_size)
-- get rid of old lists
for _, listname in ipairs({"input", "micro", "recycle", "output"}) do
@ -211,12 +220,13 @@ function station.initialize_inventory(inv)
end
end
function station.on_construct(pos, shape_groups, build_formspec, update_infotext)
function station.on_construct(pos, shape_groups, build_formspec, update_metadata)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
station.initialize_inventory(inv)
station.initialize_metadata(meta, inv, shape_groups, build_formspec, update_infotext)
station.initialize_inventory(inv, shape_groups)
station.initialize_metadata(meta, inv, shape_groups, build_formspec, update_metadata)
station.update_inventory(meta, inv)
end
function station.after_place_node(pos, placer)
@ -226,11 +236,23 @@ function station.after_place_node(pos, placer)
end
end
function api.register_station(name, shape_groups, def)
function api.register_station(name, def)
local shape_groups = def.shape_groups
local build_formspec = def.build_formspec
local update_metadata = def.update_metadata
if not shape_groups then
error("station requires shape_groups defined")
end
def.shape_groups = nil
def.build_formspec = nil
def.update_metadata = nil
def.after_place_node = def.after_place_node or station.after_place_node
def.on_construct = def.on_construct or
function(pos)
return station.on_construct(pos, shape_groups, def.build_formspec, def.update_infotext)
return station.on_construct(pos, shape_groups, build_formspec, update_metadata)
end
def.can_dig = def.can_dig or
@ -245,7 +267,7 @@ function api.register_station(name, shape_groups, def)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return station.on_receive_fields(
meta, inv, formname, fields, sender, def.build_formspec, def.update_infotext
meta, inv, formname, fields, sender, build_formspec, update_metadata
)
end
@ -267,14 +289,14 @@ function api.register_station(name, shape_groups, def)
function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return station.on_inventory_put(meta, inv, listname, index, stack, player, def.update_infotext)
return station.on_inventory_put(meta, inv, listname, index, stack, player, update_metadata)
end
def.on_metadata_inventory_take = def.on_metadata_inventory_take or
function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return station.on_inventory_take(meta, inv, listname, index, stack, player, def.update_infotext)
return station.on_inventory_take(meta, inv, listname, index, stack, player, update_metadata)
end
def._stairsplus_shape_groups = shape_groups