Skip to content

Commit 449c4f5

Browse files
authored
Fix incorrect cost due to index mismatch (minetest-mods#219)
1 parent 44d4810 commit 449c4f5

File tree

4 files changed

+110
-39
lines changed

4 files changed

+110
-39
lines changed

circular_saw.lua

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ circular_saw.known_nodes = {}
2929
-- This is populated by stairsplus:register_micro:
3030
circular_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-
4332
circular_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.
9990
function 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
10697
end
@@ -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

stairsplus/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
stairsplus:register_all("moreblocks", "wood", "default:wood", {
1010
description = "Wooden",
1111
tiles = {"default_wood.png"},
12-
groups = {oddly_breakabe_by_hand=1},
12+
groups = {oddly_breakable_by_hand=1},
1313
sounds = moreblocks.node_sound_wood_defaults(),
1414
})
1515
```

stairsplus/common.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ stairsplus.register_single = function(category, alternate, info, modname, subnam
157157
else
158158
def.on_place = stairsplus.rotate_node_aux
159159
end
160-
if type(info) ~= "table" then
160+
if info._circular_saw_cost then
161+
def._circular_saw_cost = info._circular_saw_cost
162+
end
163+
if info.size then
161164
def.node_box = {
162165
type = "fixed",
163-
fixed = {-0.5, -0.5, -0.5, 0.5, (info/16)-0.5, 0.5},
166+
fixed = {-0.5, -0.5, -0.5, 0.5, (info.size/16)-0.5, 0.5},
164167
}
165-
def.description = ("%s (%d/16)"):format(desc_base, info)
168+
def.description = ("%s (%d/16)"):format(desc_base, info.size)
166169
else
167-
def.node_box = {
168-
type = "fixed",
169-
fixed = info,
170-
}
170+
def.node_box = info.node_box
171171
def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
172172
end
173173
else

0 commit comments

Comments
 (0)