starlit  terrain.lua at [9d4ddb7701]

File mods/starlit/terrain.lua artifact 4e1556f916 part of check-in 9d4ddb7701


local T = starlit.translator
local lib = starlit.mod.lib

starlit.terrain = {}
local soilSounds = {
	footstep = 'default-dirt-footstep';
	dug = 'default-dug-node';
}
local sandSounds = {
	footstep = {name='default-sand-footstep',gain=0.1};
	dug = 'default-dug-node';
}
local grassSounds = {
	footstep = 'default-grass-footstep';
	dug = 'default-dug-node';
}
local hardSounds = {
	footstep = 'default-hard-footstep';
	dug = 'default-dug-node';
}

local soilDrop = {
	max_items = 3;
	items = {
		{rarity = 2, items = {'starlit:soil_clump'}};
		{rarity = 3, items = {'starlit:soil_clump'}};
		{rarity = 4, items = {'starlit:soil_clump'}};
	};
}
minetest.register_node('starlit:soil', {
	description = T 'Soil';
	tiles = {'starlit-terrain-soil.png'};
	groups = {looseClump = 2, soil = 1};
	drop = soilDrop;
	sounds = soilSounds;
	_starlit = {
		kind = 'block';
		elements = {};
	};
})


minetest.register_node('starlit:sand', {
	description = T 'Sand';
	tiles = {'starlit-terrain-sand.png'};
	groups = {looseClump = 1, sand = 1, falling_node = 1};
	drop = '';
	sounds = sandSounds;
	_starlit = {
		kind = 'block';
		fab = starlit.type.fab { element = { silicon = 25 } };
	};
})

minetest.register_node('starlit:lifesilt', {
	description = T 'Lifesilt';
	tiles = {'starlit-terrain-lifesilt.png'};
	groups = {looseClump = 1, lifesilt = 1, falling_node = 1};
	drop = '';
	sounds = sandSounds;
	_starlit = {
		kind = 'block';
		fab = starlit.type.fab { element = { carbon = 8, silicon = 4 } };
	};
})

minetest.register_craftitem('starlit:soil_clump', {
	short_description = T 'Soil';
	description = starlit.ui.tooltip {
		title = T 'Soil';
		desc = 'A handful of nutrient-packed soil, suitable for growing plants';
		color = lib.color(0.3,0.2,0.1);
	};
	inventory_image = 'starlit-item-soil.png';
	groups = {looseClump = 2, soil = 1};
	on_place = function(me, luser, point)
		if me:get_count() < 3 then return end
		if minetest.place_node(point.above, {name = 'starlit:soil'}, luser) then
			me:take_item(3)
		end
		return me
	end;
	_starlit = {
		fab = starlit.type.fab { element = { carbon = 12 / 4 } };
	};
})

function starlit.terrain.createGrass(def)
	local drop = {
		max_items = 4;
		items = {
			{
				items = {'starlit:soil'}, rarity = 2;
				tool_groups = { 'shovel', 'trowel' };
			};
		};
	}
	minetest.register_node(def.name, {
		description = T 'Greengraze';
		tiles = {
			def.img .. '.png';
			'starlit-terrain-soil.png';
			{
				name = 'starlit-terrain-soil.png^' .. def.img ..'-overlay.png';
				tileable_vertical = false;
			};
		};
		groups = {looseClump = 2, grass = 1, soil = 1, sub_walk = 1};
		drop = soilDrop;
		sounds = grassSounds;
		_starlit = {
			fab = def.fab;
			recover = def.recover;
			recover_vary = def.recover_vary;
		};
	})
end


starlit.terrain.createGrass {
	name = 'starlit:greengraze';
	desc = T 'Greengraze';
	img = 'starlit-terrain-greengraze';
	fab = starlit.type.fab {
		element = { carbon = 12; };
		time = { shred = 2.5; };
	};
}

starlit.terrain.createGrass {
	name = 'starlit:undergloam';
	desc = T 'Undergloam';
	-- fungal carpet
	img = 'starlit-terrain-undergloam';
	fab = starlit.type.fab {
		element = {
			carbon = 12;
		};
		time = { shred = 2.5; };
	};
}

for _, w in pairs {false,true} do
	minetest.register_node('starlit:liquid_water' .. (w and '_flowing' or ''), {
		description = T 'Water';
		drawtype = 'liquid';
		waving = 3;
		tiles = {
			{
				name = "default_water_source_animated.png";
				backface_culling = false;
				animation = {
					type = "vertical_frames";
					aspect_w = 16;
					aspect_h = 16;
					length = 2.0;
				};
			};
			{
				name = "default_water_source_animated.png";
				backface_culling = true;
				animation = {
					type = "vertical_frames";
					aspect_w = 16;
					aspect_h = 16;
					length = 2.0;
				};
			};
		};
		use_texture_alpha = 'blend';
		paramtype = 'light';
		walkable = false, pointable = "blocking", diggable = false, buildable_to = true;
		is_ground_content = false;
		drop = '';
		drowning = 1;
		liquidtype = w and 'flowing' or 'source';
		liquid_alternative_flowing = 'starlit:liquid_water_flowing';
		liquid_alternative_source = 'starlit:liquid_water';
		liquid_viscosity = 1;
		liquid_renewable = true;
		liquid_range = 2;
		drowning = 40;
		post_effect_color = {a=103, r=10, g=40, b=70};
		groups = {water = 3, liquid = 3};
	});
end


starlit.world.mineral.foreach('starlit:mineral_generate', {}, function(name,m)
	local node = string.format('starlit:mineral_%s', name)
	local grp = {mineral = 1}
	minetest.register_node(node, {
		short_description = m.name;
		description = starlit.ui.tooltip {
			title = m.name;
			desc = m.desc;
			color = m.tone;
		};
		tiles = m.tiles or 
				(m.tone and {
					lib.image'starlit-terrain-granite.png':shift(m.tone):render()
				}) or nil;
		groups = grp;
		drop = m.rocks or '';
		sounds = hardSounds;
		_starlit = {
			kind = 'block';
			elements = m.elements;
			fab = m.fab;
			recover = m.recover;
			recover_vary = m.recover_vary;
		};
	})
	if not m.excludeOre then
		local seed = 0
-- 		grp.ore = 1
		for i = 1, #m.name do
			seed = seed*50 + string.byte(m.name, i)
		end
		minetest.register_ore {
			ore = node;
			ore_type = m.dist.kind;
			wherein = m.dist.among;
			clust_scarcity = m.dist.rare;
			y_max = m.dist.height[1], y_min = m.dist.height[2];
			column_height_min = m.dist.sheetCols and m.dist.sheetCols[1] or nil;
			column_height_max = m.dist.sheetCols and m.dist.sheetCols[2] or nil;
			noise_params = m.dist.noise or {
				scale = 1;
				spread = vector.new(128,128,128);
				seed = seed;
				octaves = 2;
			};
		}
	end
end)

starlit.world.mineral.link('feldspar', {
	name = T 'Feldspar';
	tiles = {'starlit-terrain-feldspar.png'};
	excludeOre = true;
	recover = starlit.type.fab {
		time = { shred = 3; };
		cost = { shredPower = 3; };
	};
	recover_vary = function(rng, ctx)
		-- print('vary!', rng:int(), rng:int(0,10))
		return starlit.type.fab {
			element = {
				aluminum  = rng:int(0,4);
				potassium = rng:int(0,2);
				calcium   = rng:int(0,2);
			}
		};
	end;
})

starlit.world.mineral.link('granite', {
	name = T 'Granite';
	tiles = {'starlit-terrain-granite.png'};
	dist = {
		kind = 'sheet';
		among = 'starlit:feldspar';
		height = {-200,30};
		sheetCols = {1, 16};
	};
	recover = starlit.type.fab {
		time = { shred = 4; };
		cost = { shredPower = 8; };
	};
	recover_vary = function(rng, ctx)
		-- print('vary!', rng:int(), rng:int(0,10))
		return starlit.type.fab {
			element = {
				aluminum  = rng:int(0,4);
				potassium = rng:int(0,2);
				calcium   = rng:int(0,2);
			}
		};
	end;
})

-- map generation

minetest.register_alias('mapgen_stone', 'starlit:mineral_feldspar')
minetest.register_alias('mapgen_water_source', 'starlit:liquid_water')
minetest.register_alias('mapgen_river_water_source', 'starlit:liquid_water')