starlit  Artifact [2a09a8ef6e]

Artifact 2a09a8ef6e8d94994992fdf18f14ae57fa02412bc1aca1951a9d584b2c285ddc:


local lib = starlit.mod.lib


do -- chemlamp
	local burnTime = 60*60
	local maxBright = 12
	local stages = maxBright
	local stageTimeout = burnTime / stages
	local function chemLampID(n)
		if n == stages then return 'starlit_tech:chem_lamp' end
		return string.format('starlit_tech:chem_lamp_%s',n)
	end
	local fab = starlit.type.fab {
		element = { carbon = 8, magnesium = 2 };
		cost = { power = 100 };
		flag = { print = true };
		time = { print = 5 };
		reverseEngineer = {
			complexity = 1;
			sw = 'starlit_tech:schematic_chem_lamp';
		};
	};
	for i = stages, 0, -1 do
		minetest.register_node(chemLampID(i), {
			short_description = 'Chem Lamp';
			description = starlit.ui.tooltip {
				title = 'Chem Lamp';
				desc = "A simple carbon-frame chemical light source powered by ambient oxygen. Cheap, quick to print, and biodedragable, without any need for an electric grid or complex power storage mechanism. However, the light only lasts a few days, after which the lamp must be recycled or discarded.";
				color = lib.color(1,.4,.1);
				props = {
					{title = 'Burn Remaining', desc=lib.math.timespec(stageTimeout * i), affinity=i > 4 and 'good' or 'bad'};
					{title = 'Mass', desc='10g', affinity='info'};
				};
			};
			drawtype = 'nodebox';
			groups = {
				object = 2;
				attached_node = 1;
			};
			node_box = {
				type = 'fixed';
				fixed = {
					-.4, -.5, -.20;
					 .4, -.3,  .20;
				};
			};
			tiles = {
				lib.image 'starlit-tech-lamp-glow.png'
					:fade(1 - i/stages)
					:blit(lib.image 'starlit-tech-lamp.png')
				:render();
			};
			paramtype = 'light';
			paramtype2 = 'wallmounted';
			wallmounted_rotate_vertical = true;
			light_source = math.floor(lib.math.lerp(i/stages, 0, maxBright));
			on_construct = i ~= 0 and function(pos)
				local t = minetest.get_node_timer(pos)
				t:start(stageTimeout)
			end or nil;
			on_timer = i ~= 0 and function(pos)
				local me = minetest.get_node(pos)
				minetest.swap_node(pos, {name=chemLampID(i-1), param2=me.param2})
				return i > 1
			end or nil;
			_starlit = {
				mass = 10;
				fab = fab;
				recover = starlit.type.fab {
					element = {
						carbon = 8;
						magnesium = math.floor(lib.math.lerp(i/stages, 0, 2));
					};
					time = {
						shred = .5;
						shredPower = 2;
					};
				};

			};
		})
	end
	starlit.item.sw.link('starlit_tech:schematic_chem_lamp', {
		name = 'Chem Lamp Schematic';
		kind = 'schematic';
		input = fab;
		output = chemLampID(stages);
		size = 32e6;
		cost = {
			cycles = 8e9;
			ram = 16e6;
		};
		rarity = 1;
	})
end