sorcery  Artifact [26814ac7ca]

Artifact 26814ac7ca443a299ff8744bdb287dd792a04c2abc117595b39356fa7a11136e:


local gem = sorcery.lib.image('default_diamond_block.png')
local amethyst = gem:multiply(sorcery.lib.color(sorcery.data.gems.amethyst.tone))
local emerald = gem:multiply(sorcery.lib.color(sorcery.data.gems.emerald.tone))
local hitbox = {
	type = 'fixed';
	fixed = {
		-0.5, -0.5, -0.4;
		0.5, 1.5, 0.4;
	};
}

local update_inv = function(pos)
	minetest.get_node_timer(pos):start(60)
end

minetest.register_node('sorcery:harvester', {
	description = 'Harvester';
	drawtype = 'mesh';
	paramtype = 'light';
	paramtype2 = 'facedir';
	mesh = 'sorcery-harvester.obj';
	groups = { cracky = 2; oddly_breakable_by_hand = 1; };
	sunlight_propagates = true;
	selection_box = hitbox;
	collision_box = hitbox;
	tiles = {
		amethyst:render();
		'default_copper_block.png';
		'default_stone.png';
		'default_gold_block.png';
		'default_tin_block.png';
		emerald:render();
	};

	on_timer = function(pos,elapse)
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		if inv:is_empty('charge') then return false end
		
		local ley = sorcery.ley.estimate(pos)
		local charged = false
		for i=1,inv:get_size('charge') do
			local repair_per_tick = (65536 / 64) * (15 * ley.force)
			local item = inv:get_stack('charge',i)
			if minetest.get_item_group(item:get_name(), 'sorcery_wand') ~= 0 then
				local spell = item:get_meta():get_string('sorcery_wand_spell')
				if spell == '' then goto skip end
				local aff = sorcery.data.spells[spell].leytype
				if aff == ley.aff[1] or aff == ley.aff[2] then
					repair_per_tick = repair_per_tick * 2 end
			else goto skip end -- item is not magical
			print('repair cycle! repairing item'..item:get_name()..' by',repair_per_tick * (elapse / 60))
			item:set_wear(math.max(0,item:get_wear() - repair_per_tick * (elapse / 60)))
			inv:set_stack('charge',i,item)
			charged = true
		::skip::end

		return charged
	end;

	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		inv:set_size('charge', 3)
		meta:set_string('formspec', [[
			size[8,5]
			list[context;charge;2.5,0;3,1;]
			list[current_player;main;0,1.3;8,4;]
			listring[]
		]])
	end;
	on_metadata_inventory_put = update_inv;
	on_metadata_inventory_move = update_inv;
})

minetest.register_craftitem('sorcery:harvester_receptacle', {
	description = 'Harvester Receptacle';
	inventory_image = 'sorcery_harvester_receptacle.png';
})

minetest.register_craft {
	output = 'sorcery:harvester_receptacle';
	recipe = {
		{'','default:stone','default:copper_ingot'};
		{'','default:gold_ingot',''};
		{'stairs:slab_stone','stairs:slab_stone','stairs:slab_stone'};
	};
}

minetest.register_craftitem('sorcery:accumulator', {
	description = 'Accumulator';
	inventory_image = 'sorcery_accumulator.png';
})

minetest.register_craft {
	output = 'sorcery:accumulator';
	recipe = {
		{'default:tin_ingot', 'default:tin_ingot', 'default:tin_ingot'};
		{'sorcery:gem_amethyst','sorcery:gem_emerald','sorcery:gem_amethyst'};
		{'default:copper_ingot', 'default:copper_ingot', 'default:copper_ingot'};
	};
}
minetest.register_craft {
	output = 'sorcery:harvester';
	recipe = {
		{'sorcery:accumulator'};
		{'default:gold_ingot'};
		{'sorcery:harvester_receptacle'};
	};
}