@@ -29,17 +29,6 @@ circular_saw.known_nodes = {}
2929-- This is populated by stairsplus:register_micro:
3030circular_saw .microblocks = {}
3131
32- -- How many microblocks does this shape at the output inventory cost:
33- -- It may cause slight loss, but no gain.
34- circular_saw .cost_in_microblocks = {
35- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 ,
36- 2 , 3 , 2 , 4 , 2 , 4 , 5 , 6 ,
37- 7 , 1 , 1 , 2 , 4 , 6 , 7 , 8 ,
38- 1 , 2 , 2 , 3 , 1 , 1 , 2 , 4 ,
39- 4 , 2 , 6 , 7 , 3 , 7 , 7 , 4 ,
40- 8 , 3 , 2 , 6 , 2 , 1 , 3 , 4
41- }
42-
4332circular_saw .names = {
4433 {" micro" , " _1" },
4534 {" panel" , " _1" },
@@ -96,11 +85,13 @@ circular_saw.names = {
9685 {" slope" , " _cut" },
9786}
9887
88+ -- How many microblocks does this shape at the output inventory cost:
89+ -- It may cause slight loss, but no gain.
9990function circular_saw :get_cost (inv , stackname )
10091 local name = minetest .registered_aliases [stackname ] or stackname
10192 for i , item in pairs (inv :get_list (" output" )) do
10293 if item :get_name () == name then
103- return circular_saw . cost_in_microblocks [ i ]
94+ return item : get_definition (). _circular_saw_cost
10495 end
10596 end
10697end
@@ -118,10 +109,11 @@ function circular_saw:get_output_inv(modname, material, amount, max)
118109
119110 for i = 1 , # circular_saw .names do
120111 local t = circular_saw .names [i ]
121- local cost = circular_saw .cost_in_microblocks [i ]
122- local balance = math.min (math.floor (amount / cost ), max )
123112 local nodename = modname .. " :" .. t [1 ] .. " _" .. material .. t [2 ]
124- if minetest .registered_nodes [nodename ] then
113+ local def = minetest .registered_nodes [nodename ]
114+ if def then
115+ local cost = def ._circular_saw_cost
116+ local balance = math.min (math.floor (amount / cost ), max )
125117 pos = pos + 1
126118 list [pos ] = nodename .. " " .. balance
127119 end
@@ -358,8 +350,9 @@ function circular_saw.on_metadata_inventory_take(
358350 -- If it is one of the offered stairs: find out how many
359351 -- microblocks have to be subtracted:
360352 if listname == " output" then
353+ local def = stack :get_definition ()
361354 -- We do know how much each block at each position costs:
362- local cost = circular_saw . cost_in_microblocks [ index ]
355+ local cost = def . _circular_saw_cost
363356 * stack :get_count ()
364357 circular_saw :update_inventory (pos , - cost )
365358 elseif listname == " micro" then
0 commit comments