Skip to content

convert index to custom subset#219

Merged
SmallJoker merged 2 commits intominetest-mods:masterfrom
fetsorn:fetsorn_custom_subset
Dec 25, 2025
Merged

convert index to custom subset#219
SmallJoker merged 2 commits intominetest-mods:masterfrom
fetsorn:fetsorn_custom_subset

Conversation

@fetsorn
Copy link
Contributor

@fetsorn fetsorn commented Dec 13, 2025

attempts to resolve #190

the bug was in on_metadata_inventory_take, it assumed that index parameter always matched default subset and fetched hardcoded costs for it.

instead, I find the proper index by searching for the given stack name in the names array.

Copy link

@a-tour-ist a-tour-ist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wounder whether it's worth keeping the cost_in_microblocks[custom_index] table.

Extracting the microblock type with a pattern and looking into a {type=cost} table might be more robust...

That would fix recycling custom_subset blocks too.

@fetsorn
Copy link
Contributor Author

fetsorn commented Dec 16, 2025

Extracting the microblock type with a pattern and looking into a {type=cost} table

How would you "extract type with a pattern"? I can do

circular_saw.blocks = {
	micro = { cost = 1, prefix = "micro", suffix = "" },
	micro_1 = { cost = 1, prefix = "micro", suffix = "_1" },

and then change ordered names to

circular_saw.names = {
    "micro_1",
    "panel_1",

and then figure out the type of the stack by matching it against all possible names. But I don't know if that would be more readable, and it'd still have the same efficiency as the current solution.

Do you think of something better?

@Calinou Calinou added the Bug label Dec 17, 2025
@a-tour-ist
Copy link

How would you "extract type with a pattern"?

My idea was to do something like that:

function circular_saw:get_cost(inv, stackname)
	local input_stack = inv:get_stack("input",  1)
	local input_name = input_stack:get_name()
	local name_parts = circular_saw.known_nodes[input_name]
	local modname  = name_parts[1]
	local material = name_parts[2]
	local stackname = stack:get_name()
	stackname = minetest.registered_aliases[stackname] or stackname

	local pattern = "^" .. modname .. ":(.*)_" .. material .. "(.*)$"
	local prefix, suffix = string.match(stackname, pattern)

	-- TODO: populate this table somewhere and give it a better name
	return costs[prefix..suffix]
end

@fetsorn
Copy link
Contributor Author

fetsorn commented Dec 17, 2025

I see what you mean about the pattern now! Updated the PR.

@fetsorn fetsorn force-pushed the fetsorn_custom_subset branch from f268834 to 11ac4dc Compare December 18, 2025 01:22
@SmallJoker
Copy link
Member

SmallJoker commented Dec 20, 2025

Wouldn't it be more straight-forward to have the cost included As a Node Definition field, such as _circular_saw_cost = n? That would avoid possibly error-prone pattern matching (e.g. where the material might contain _).

@fetsorn fetsorn force-pushed the fetsorn_custom_subset branch from 11ac4dc to dee7aca Compare December 21, 2025 21:50
@fetsorn
Copy link
Contributor Author

fetsorn commented Dec 21, 2025

cost is now in the microblock node definition. I changed the slab data structure in defs.lua a bit to make it more like the rest of the definition tables.

stair_right_half is the only def without a cost and not mentioned in circular saw. Is that a bug or on purpose?

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stair_right_half is the only def without a cost and not mentioned in circular saw. Is that a bug or on purpose?

For the scope of this PR I would suggest to add a TODO FIXME-alike comment in the code to highlight this inconsistency.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you. Will merge in a few days unless there are objections.

@SmallJoker SmallJoker merged commit 449c4f5 into minetest-mods:master Dec 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stairsplus:register_custom_subset computes the wrong "cost" for elements

4 participants