Aaron Suen d1a937e973 Add crude glass.
This makes glassmaking more challenging, as glass that is quenched
when not molded, or left wandering too long, will tend to quench to
crude glass, which is inferior.

This also prevents molten glass from wandering the countryside
forever from failed glassmaking attempts, and precludes keeping
molten glass in "captivity" as a crude infinite light source.
2019-04-07 09:12:44 -04:00

129 lines
3.1 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_random
= math.random
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
nodecore.register_craft({
label = "melt sand to glass",
action = "cook",
touchgroups = {
coolant = 0,
flame = 3
},
duration = 20,
cookfx = true,
nodes = {
{
match = "nc_terrain:sand_loose",
replace = modname .. ":glass_hot_source"
}
}
})
nodecore.register_cook_abm({
nodenames = {"nc_terrain:sand_loose"},
neighbors = {"group:flame"}
})
local src = modname .. ":glass_hot_source"
local flow = modname .. ":glass_hot_flowing"
nodecore.register_craft({
label = "cool clear glass",
action = "cook",
priority = -1,
duration = 120,
cookfx = {smoke = true, hiss = true},
check = function(pos)
return #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y, z = pos.z + 1},
{flow}) < 1
end,
nodes = {
{
match = src,
replace = modname .. ":glass"
}
}
})
nodecore.register_craft({
label = "quench opaque glass",
action = "cook",
cookfx = true,
check = function(pos)
return #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y, z = pos.z + 1},
{flow}) < 1
and #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y, z = pos.z + 1},
{"group:coolant"}) > 0
end,
nodes = {
{
match = src,
replace = modname .. ":glass_opaque"
}
}
})
nodecore.register_craft({
label = "quench crude glass",
action = "cook",
cookfx = true,
priority = -1,
check = function(pos)
return #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y, z = pos.z + 1},
{"group:coolant"}) > 0
end,
nodes = {
{
match = src,
replace = modname .. ":glass_crude"
}
}
})
nodecore.register_cook_abm({nodenames = {src}})
nodecore.register_limited_abm({
label = "Molten Glass Flowing",
interval = 1,
chance = 4,
nodenames = {src},
action = function(pos, node)
local meta = minetest.get_meta(pos)
local gen = meta:get_int("glassgen")
if gen >= 32 and math_random(1, 2) == 1 then
minetest.set_node(pos, {name = modname .. ":glass_crude"})
minetest.sound_play("nc_api_craft_hiss", {gain = 1, pos = pos})
return nodecore.smokefx(pos, 0.2, 80)
end
local miny = pos.y
local found = {}
nodecore.scan_flood(pos, 5, function(p)
local nn = minetest.get_node(p).name
if nn == src then return end
if nn ~= flow then return false end
if p.y > miny then return end
if p.y == miny then
found[#found + 1] = p
return
end
miny = p.y
found = {p}
end)
if #found < 1 then return end
local np = nodecore.pickrand(found)
minetest.set_node(np, node)
minetest.get_meta(np):set_int("glassgen", gen + 1)
minetest.set_node(pos, {name = flow, param2 = 7})
end})