nodecore-skyblock/nc_sky_liquids/init.lua

177 lines
4.3 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, nodecore, pairs, type
= ipairs, minetest, nodecore, pairs, type
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local function regterrain(def)
def.name = def.name or def.description:gsub("%W", "_"):lower()
def.fullname = modname .. ":" .. def.name
def.tiles = def.tiles or { def.fullname:gsub("%W", "_") .. ".png" }
def.is_ground_content = true
if def.liquidtype then
def.liquid_alternative_flowing = def.fullname .. "_flowing"
def.liquid_alternative_source = def.fullname .. "_source"
def.fullname = def.fullname .. "_" .. def.liquidtype
def.special_tiles = def.special_tiles or { def.tiles[1], def.tiles[1] }
end
def.mapgen = def.mapgen or { def.name }
minetest.register_node(def.fullname, def)
for _, v in pairs(def.mapgen) do
minetest.register_alias("mapgen_" .. v, def.fullname)
end
end
local function clone(t)
local c = minetest.deserialize(minetest.serialize(t))
for k, v in pairs(t) do
if type(v) == "function" then c[k] = v end
end
return c
end
local function regliquid(def)
local t = clone(def)
t.drawtype = "liquid"
t.liquidtype = "source"
regterrain(t)
t = clone(def)
t.mapgen = { }
t.drawtype = "flowingliquid"
t.liquidtype = "flowing"
t.paramtype2 = "flowingliquid"
regterrain(t)
end
regliquid({
description = "HM Water",
mapgen = {},
tiles = {"nc_terrain_water.png"},
paramtype = "light",
liquid_viscosity = 1,
liquid_renewable = false,
alpha = 160,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
drop = "",
groups = { coolant = 1, water = 2, moist = 2 },
post_effect_color = {a = 103, r = 30, g = 76, b = 90},
sounds = nodecore.sounds("nc_terrain_watery")
})
local src = modname..":hm_water_source"
local flow = modname..":hm_water_flowing"
nodecore.register_limited_abm({
label = "Water Renew",
interval = 1,
chance = 1,
nodenames = {flow},
neirbours = {src},
action = function(pos, node)
local n2 = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
if n2 == flow then
local count = 0
for x=-1,1 do
for y=0,1 do
for z=-1,1 do
if (x*x+y*y+z*z)^0.5 == 1 and minetest.get_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}) == src then
count = count + 1
end
end
end
end
if count >= 2 then
minetest.set_node(pos,{name=src})
end
end
end
})
nodecore.register_limited_abm({
label = "Water Flowing",
interval = 1,
chance = 2,
nodenames = {src},
neighbours = {flow},
action = function(pos, node)
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.set_node(pos, {name = flow, param2 = 7})
end
})
nodecore.register_craft({
label = "melt cobble to lava",
action = "cook",
touchgroups = {flame = 4},
duration = 30,
cookfx = true,
nodes = {
{
match = "nc_terrain:cobble",
replace = "nc_terrain:lava_source"
}
}
})
nodecore.register_cook_abm({nodenames = {"nc_terrain:cobble"}, neighbors = {"group:flame"}})
local src2 = "nc_terrain:lava_source"
local flow2 = "nc_terrain:lava_flowing"
nodecore.register_limited_abm({
label = "Lava Flowing",
interval = 2,
chance = 2,
nodenames = {src2},
neighbours = {flow2},
action = function(pos, node)
local miny = pos.y
local found = {}
nodecore.scan_flood(pos, 5, function(p)
local nn = minetest.get_node(p).name
if nn == src2 then return end
if nn ~= flow2 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.set_node(pos, {name = flow2, param2 = 7})
end
})