Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions circular_saw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stairsplus/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
```
Expand Down
14 changes: 7 additions & 7 deletions stairsplus/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading