87fba22f3b
using the new falling node hooks provided by `bg_api`, add alternative versions of existing stoneworking recipes, where instead of pummeling, a stoney node must fall onto the input nodes with sufficient force. note that since the only currently existing stoney node that can fall, loose cobblestone, is unobtainable without cheats, so are these recipes.
66 lines
1.8 KiB
Lua
66 lines
1.8 KiB
Lua
local modname = minetest.get_current_modname()
|
|
|
|
local function is_stoney_below (pos)
|
|
local below_node = minetest.get_node(pos + blockgame.vector.dirs.down)
|
|
return blockgame.item_matches(below_node.name, {"group:stoney"})
|
|
end
|
|
|
|
blockgame.crafting.register_pummel_recipe({
|
|
name = modname .. ":craft_tile",
|
|
label = "pummel stone into tile",
|
|
used = {"group:stoney"},
|
|
target = {"bg_terrain:cobblestone"},
|
|
check = function (pos, used_node, target_node)
|
|
return is_stoney_below(pos)
|
|
end,
|
|
on_success = function (pos, used_node, target_node)
|
|
minetest.set_node(pos, {name = modname .. ":tile"})
|
|
end,
|
|
})
|
|
|
|
blockgame.crafting.register_pummel_recipe({
|
|
name = modname .. ":craft_bricks",
|
|
label = "pummel tile into bricks",
|
|
used = {"group:stoney"},
|
|
target = {modname .. ":tile"},
|
|
check = function (pos, used_node, target_node)
|
|
return is_stoney_below(pos)
|
|
end,
|
|
on_success = function (pos, used_node, target_node)
|
|
minetest.set_node(pos, {name = modname .. ":bricks"})
|
|
end,
|
|
})
|
|
|
|
local crush_recipes = {
|
|
{
|
|
input = {"bg_terrain:cobblestone", "bg_terrain:cobblestone_loose"},
|
|
output = modname .. ":tile",
|
|
},
|
|
{
|
|
input = {modname .. ":tile"},
|
|
output = modname .. ":bricks",
|
|
},
|
|
}
|
|
|
|
blockgame.register_after_falling_node_lands(function (pos, node, entity)
|
|
if not blockgame.item_matches(node.name, {"group:stoney"}) then return end
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
local mass = def.mass or 1
|
|
local force = math.abs(entity.fall_velocity.y) * mass
|
|
|
|
if force < 5 then return end
|
|
|
|
local below = pos + blockgame.vector.dirs.down
|
|
local target = minetest.get_node(below).name
|
|
if not blockgame.item_matches(target, {"group:stoney"}) then return end
|
|
|
|
for _, recipe in pairs(crush_recipes) do
|
|
local input = recipe.input
|
|
local output = recipe.output
|
|
if blockgame.item_matches(target, input) then
|
|
minetest.set_node(below, {name = output})
|
|
return
|
|
end
|
|
end
|
|
end)
|