mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-12-28 22:05:34 +01:00
Fix incorrect cost due to index mismatch (#219)
This commit is contained in:
@@ -29,17 +29,6 @@ circular_saw.known_nodes = {}
|
||||
-- This is populated by stairsplus:register_micro:
|
||||
circular_saw.microblocks = {}
|
||||
|
||||
-- How many microblocks does this shape at the output inventory cost:
|
||||
-- It may cause slight loss, but no gain.
|
||||
circular_saw.cost_in_microblocks = {
|
||||
1, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 3, 2, 4, 2, 4, 5, 6,
|
||||
7, 1, 1, 2, 4, 6, 7, 8,
|
||||
1, 2, 2, 3, 1, 1, 2, 4,
|
||||
4, 2, 6, 7, 3, 7, 7, 4,
|
||||
8, 3, 2, 6, 2, 1, 3, 4
|
||||
}
|
||||
|
||||
circular_saw.names = {
|
||||
{"micro", "_1"},
|
||||
{"panel", "_1"},
|
||||
@@ -96,11 +85,13 @@ circular_saw.names = {
|
||||
{"slope", "_cut"},
|
||||
}
|
||||
|
||||
-- How many microblocks does this shape at the output inventory cost:
|
||||
-- It may cause slight loss, but no gain.
|
||||
function circular_saw:get_cost(inv, stackname)
|
||||
local name = minetest.registered_aliases[stackname] or stackname
|
||||
for i, item in pairs(inv:get_list("output")) do
|
||||
if item:get_name() == name then
|
||||
return circular_saw.cost_in_microblocks[i]
|
||||
return item:get_definition()._circular_saw_cost
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -118,10 +109,11 @@ function circular_saw:get_output_inv(modname, material, amount, max)
|
||||
|
||||
for i = 1, #circular_saw.names do
|
||||
local t = circular_saw.names[i]
|
||||
local cost = circular_saw.cost_in_microblocks[i]
|
||||
local balance = math.min(math.floor(amount/cost), max)
|
||||
local nodename = modname .. ":" .. t[1] .. "_" .. material .. t[2]
|
||||
if minetest.registered_nodes[nodename] then
|
||||
local def = minetest.registered_nodes[nodename]
|
||||
if def then
|
||||
local cost = def._circular_saw_cost
|
||||
local balance = math.min(math.floor(amount/cost), max)
|
||||
pos = pos + 1
|
||||
list[pos] = nodename .. " " .. balance
|
||||
end
|
||||
@@ -358,8 +350,9 @@ function circular_saw.on_metadata_inventory_take(
|
||||
-- If it is one of the offered stairs: find out how many
|
||||
-- microblocks have to be subtracted:
|
||||
if listname == "output" then
|
||||
local def = stack:get_definition()
|
||||
-- We do know how much each block at each position costs:
|
||||
local cost = circular_saw.cost_in_microblocks[index]
|
||||
local cost = def._circular_saw_cost
|
||||
* stack:get_count()
|
||||
circular_saw:update_inventory(pos, -cost)
|
||||
elseif listname == "micro" then
|
||||
|
||||
Reference in New Issue
Block a user