convert index to custom subset#219
Conversation
a-tour-ist
left a comment
There was a problem hiding this comment.
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.
How would you "extract type with a pattern"? I can do and then change ordered names to 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? |
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 |
|
I see what you mean about the pattern now! Updated the PR. |
f268834 to
11ac4dc
Compare
|
Wouldn't it be more straight-forward to have the cost included As a Node Definition field, such as |
11ac4dc to
dee7aca
Compare
|
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.
|
SmallJoker
left a comment
There was a problem hiding this comment.
stair_right_halfis 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.
SmallJoker
left a comment
There was a problem hiding this comment.
Looks good. Thank you. Will merge in a few days unless there are objections.
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
namesarray.