mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-12-27 05:25:37 +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
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
stairsplus:register_all("moreblocks", "wood", "default:wood", {
|
||||
description = "Wooden",
|
||||
tiles = {"default_wood.png"},
|
||||
groups = {oddly_breakabe_by_hand=1},
|
||||
groups = {oddly_breakable_by_hand=1},
|
||||
sounds = moreblocks.node_sound_wood_defaults(),
|
||||
})
|
||||
```
|
||||
|
||||
@@ -157,17 +157,17 @@ stairsplus.register_single = function(category, alternate, info, modname, subnam
|
||||
else
|
||||
def.on_place = stairsplus.rotate_node_aux
|
||||
end
|
||||
if type(info) ~= "table" then
|
||||
if info._circular_saw_cost then
|
||||
def._circular_saw_cost = info._circular_saw_cost
|
||||
end
|
||||
if info.size then
|
||||
def.node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, (info/16)-0.5, 0.5},
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, (info.size/16)-0.5, 0.5},
|
||||
}
|
||||
def.description = ("%s (%d/16)"):format(desc_base, info)
|
||||
def.description = ("%s (%d/16)"):format(desc_base, info.size)
|
||||
else
|
||||
def.node_box = {
|
||||
type = "fixed",
|
||||
fixed = info,
|
||||
}
|
||||
def.node_box = info.node_box
|
||||
def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
|
||||
end
|
||||
else
|
||||
|
||||
@@ -112,42 +112,49 @@ local box_slope_outer_half_raised = {
|
||||
stairsplus.defs = {
|
||||
["micro"] = {
|
||||
[""] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, 0, 0.5},
|
||||
},
|
||||
},
|
||||
["_1"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, -0.4375, 0.5},
|
||||
},
|
||||
},
|
||||
["_2"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, -0.375, 0.5},
|
||||
},
|
||||
},
|
||||
["_4"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, -0.25, 0.5},
|
||||
},
|
||||
},
|
||||
["_12"] = {
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, 0.25, 0.5},
|
||||
},
|
||||
},
|
||||
["_14"] = {
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, 0.375, 0.5},
|
||||
},
|
||||
},
|
||||
["_15"] = {
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0, 0.4375, 0.5},
|
||||
@@ -156,42 +163,49 @@ stairsplus.defs = {
|
||||
},
|
||||
["panel"] = {
|
||||
[""] = {
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, 0, 0.5},
|
||||
},
|
||||
},
|
||||
["_1"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, -0.4375, 0.5},
|
||||
},
|
||||
},
|
||||
["_2"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, -0.375, 0.5},
|
||||
},
|
||||
},
|
||||
["_4"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, -0.25, 0.5},
|
||||
},
|
||||
},
|
||||
["_12"] = {
|
||||
_circular_saw_cost = 3,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, 0.25, 0.5},
|
||||
},
|
||||
},
|
||||
["_14"] = {
|
||||
_circular_saw_cost = 4,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, 0.375, 0.5},
|
||||
},
|
||||
},
|
||||
["_15"] = {
|
||||
_circular_saw_cost = 4,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
|
||||
@@ -199,41 +213,83 @@ stairsplus.defs = {
|
||||
}
|
||||
},
|
||||
["slab"] = {
|
||||
[""] = 8,
|
||||
["_quarter"] = 4,
|
||||
["_three_quarter"] = 12,
|
||||
["_1"] = 1,
|
||||
["_2"] = 2,
|
||||
["_14"] = 14,
|
||||
["_15"] = 15,
|
||||
[""] = {
|
||||
_circular_saw_cost = 4,
|
||||
size = 8
|
||||
},
|
||||
["_quarter"] = {
|
||||
_circular_saw_cost = 2,
|
||||
size = 4
|
||||
},
|
||||
["_three_quarter"] = {
|
||||
_circular_saw_cost = 6,
|
||||
size = 12
|
||||
},
|
||||
["_1"] = {
|
||||
_circular_saw_cost = 1,
|
||||
size = 1
|
||||
},
|
||||
["_2"] = {
|
||||
_circular_saw_cost = 1,
|
||||
size = 2
|
||||
},
|
||||
["_14"] = {
|
||||
_circular_saw_cost = 7,
|
||||
size = 14
|
||||
},
|
||||
["_15"] = {
|
||||
_circular_saw_cost = 8,
|
||||
size = 15;
|
||||
},
|
||||
["_two_sides"] = {
|
||||
{ -0.5, -0.5, -0.5, 0.5, -7/16, 7/16 },
|
||||
{ -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 }
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -0.5, -0.5, -0.5, 0.5, -7/16, 7/16 },
|
||||
{ -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 }
|
||||
}
|
||||
};
|
||||
},
|
||||
["_three_sides"] = {
|
||||
{ -7/16, -0.5, -0.5, 0.5, -7/16, 7/16 },
|
||||
{ -7/16, -0.5, 7/16, 0.5, 0.5, 0.5 },
|
||||
{ -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -7/16, -0.5, -0.5, 0.5, -7/16, 7/16 },
|
||||
{ -7/16, -0.5, 7/16, 0.5, 0.5, 0.5 },
|
||||
{ -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }
|
||||
}
|
||||
}
|
||||
},
|
||||
["_three_sides_u"] = {
|
||||
{ -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
|
||||
{ -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
|
||||
{ -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 }
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
|
||||
{ -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
|
||||
{ -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
["slope"] = {
|
||||
[""] = {
|
||||
_circular_saw_cost = 4,
|
||||
mesh = "moreblocks_slope.obj",
|
||||
collision_box = box_slope,
|
||||
selection_box = box_slope,
|
||||
|
||||
},
|
||||
["_half"] = {
|
||||
_circular_saw_cost = 2,
|
||||
mesh = "moreblocks_slope_half.obj",
|
||||
collision_box = box_slope_half,
|
||||
selection_box = box_slope_half,
|
||||
},
|
||||
["_half_raised"] = {
|
||||
_circular_saw_cost = 6,
|
||||
mesh = "moreblocks_slope_half_raised.obj",
|
||||
collision_box = box_slope_half_raised,
|
||||
selection_box = box_slope_half_raised,
|
||||
@@ -242,16 +298,19 @@ stairsplus.defs = {
|
||||
--==============================================================
|
||||
|
||||
["_inner"] = {
|
||||
_circular_saw_cost = 7,
|
||||
mesh = "moreblocks_slope_inner.obj",
|
||||
collision_box = box_slope_inner,
|
||||
selection_box = box_slope_inner,
|
||||
},
|
||||
["_inner_half"] = {
|
||||
_circular_saw_cost = 3,
|
||||
mesh = "moreblocks_slope_inner_half.obj",
|
||||
collision_box = box_slope_inner_half,
|
||||
selection_box = box_slope_inner_half,
|
||||
},
|
||||
["_inner_half_raised"] = {
|
||||
_circular_saw_cost = 7,
|
||||
mesh = "moreblocks_slope_inner_half_raised.obj",
|
||||
collision_box = box_slope_inner_half_raised,
|
||||
selection_box = box_slope_inner_half_raised,
|
||||
@@ -260,16 +319,19 @@ stairsplus.defs = {
|
||||
--==============================================================
|
||||
|
||||
["_inner_cut"] = {
|
||||
_circular_saw_cost = 7,
|
||||
mesh = "moreblocks_slope_inner_cut.obj",
|
||||
collision_box = box_slope_inner,
|
||||
selection_box = box_slope_inner,
|
||||
},
|
||||
["_inner_cut_half"] = {
|
||||
_circular_saw_cost = 4,
|
||||
mesh = "moreblocks_slope_inner_cut_half.obj",
|
||||
collision_box = box_slope_inner_half,
|
||||
selection_box = box_slope_inner_half,
|
||||
},
|
||||
["_inner_cut_half_raised"] = {
|
||||
_circular_saw_cost = 8,
|
||||
mesh = "moreblocks_slope_inner_cut_half_raised.obj",
|
||||
collision_box = box_slope_inner_half_raised,
|
||||
selection_box = box_slope_inner_half_raised,
|
||||
@@ -278,16 +340,19 @@ stairsplus.defs = {
|
||||
--==============================================================
|
||||
|
||||
["_outer"] = {
|
||||
_circular_saw_cost = 3,
|
||||
mesh = "moreblocks_slope_outer.obj",
|
||||
collision_box = box_slope_outer,
|
||||
selection_box = box_slope_outer,
|
||||
},
|
||||
["_outer_half"] = {
|
||||
_circular_saw_cost = 2,
|
||||
mesh = "moreblocks_slope_outer_half.obj",
|
||||
collision_box = box_slope_outer_half,
|
||||
selection_box = box_slope_outer_half,
|
||||
},
|
||||
["_outer_half_raised"] = {
|
||||
_circular_saw_cost = 6,
|
||||
mesh = "moreblocks_slope_outer_half_raised.obj",
|
||||
collision_box = box_slope_outer_half_raised,
|
||||
selection_box = box_slope_outer_half_raised,
|
||||
@@ -296,21 +361,25 @@ stairsplus.defs = {
|
||||
--==============================================================
|
||||
|
||||
["_outer_cut"] = {
|
||||
_circular_saw_cost = 2,
|
||||
mesh = "moreblocks_slope_outer_cut.obj",
|
||||
collision_box = box_slope_outer,
|
||||
selection_box = box_slope_outer,
|
||||
},
|
||||
["_outer_cut_half"] = {
|
||||
_circular_saw_cost = 1,
|
||||
mesh = "moreblocks_slope_outer_cut_half.obj",
|
||||
collision_box = box_slope_outer_half,
|
||||
selection_box = box_slope_outer_half,
|
||||
},
|
||||
["_outer_cut_half_raised"] = {
|
||||
_circular_saw_cost = 3,
|
||||
mesh = "moreblocks_slope_outer_cut_half_raised.obj",
|
||||
collision_box = box_slope_outer_half_raised,
|
||||
selection_box = box_slope_outer_half_raised,
|
||||
},
|
||||
["_cut"] = {
|
||||
_circular_saw_cost = 4,
|
||||
mesh = "moreblocks_slope_cut.obj",
|
||||
collision_box = box_slope_outer,
|
||||
selection_box = box_slope_outer,
|
||||
@@ -318,6 +387,7 @@ stairsplus.defs = {
|
||||
},
|
||||
["stair"] = {
|
||||
[""] = {
|
||||
_circular_saw_cost = 6,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -327,6 +397,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_half"] = {
|
||||
_circular_saw_cost = 3,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -335,6 +406,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
},
|
||||
-- TODO FIXME not included in circular_saw.names
|
||||
["_right_half"] = {
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
@@ -345,6 +417,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_inner"] = {
|
||||
_circular_saw_cost = 7,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -355,6 +428,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_outer"] = {
|
||||
_circular_saw_cost = 5,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -364,6 +438,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_alt"] = {
|
||||
_circular_saw_cost = 4,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -373,6 +448,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_alt_1"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -382,6 +458,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_alt_2"] = {
|
||||
_circular_saw_cost = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@@ -391,6 +468,7 @@ stairsplus.defs = {
|
||||
},
|
||||
},
|
||||
["_alt_4"] = {
|
||||
_circular_saw_cost = 2,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
|
||||
Reference in New Issue
Block a user