Aaron Suen b2f78c0daa Indexing for craft checks
By restricting the recipes we check based
on the name of the central object being
checked, we can do many fewer craft
checks per item and avoid expensive
checks.
2020-06-27 12:20:35 -04:00

73 lines
2.0 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_floor
= math.floor
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
minetest.register_craftitem(modname .. ":lump_ash", {
description = "Ash Lump",
inventory_image = modname .. "_ash.png^[mask:" .. modname .. "_lump.png",
sounds = nodecore.sounds("nc_terrain_crunchy")
})
minetest.register_craftitem(modname .. ":lump_coal", {
description = "Charcoal Lump",
inventory_image = modname .. "_coal_4.png^[mask:" .. modname .. "_lump.png",
groups = {flammable = 1},
sounds = nodecore.sounds("nc_terrain_crunchy")
})
local function split(items, name, qty)
local two = math_floor(qty / 2)
if two > 0 then
items[#items + 1] = {name = name .. " 2", count = two, scatter = 5}
end
qty = qty - (two * 2)
if qty > 0 then
items[#items + 1] = {name = name, count = qty, scatter = 5}
end
end
for num = 0, nodecore.fire_max do
local items = {}
split(items, modname .. ":lump_coal", num)
split(items, modname .. ":lump_ash", nodecore.fire_max - num)
local name = modname .. ((num == 0) and ":ash" or (":coal" .. num))
nodecore.register_craft({
label = "chop " .. name,
action = "pummel",
toolgroups = {choppy = 1},
indexkeys = {name},
nodes = {
{match = name, replace = "air"}
},
items = items
})
end
nodecore.register_craft({
label = "compress ash block",
action = "pummel",
toolgroups = {thumpy = 1},
indexkeys = {modname .. ":lump_ash"},
nodes = {
{
match = {name = modname .. ":lump_ash", count = 8},
replace = modname .. ":ash"
}
}
})
nodecore.register_craft({
label = "compress coal block",
action = "pummel",
toolgroups = {thumpy = 2},
indexkeys = {modname .. ":lump_coal"},
nodes = {
{
match = {name = modname .. ":lump_coal", count = 8},
replace = modname .. ":coal8"
}
}
})