sorcery  crafttools.lua at trunk

File crafttools.lua artifact 68741b438c on branch trunk


minetest.register_on_craft(function(stack,crafter,recipe,grid)
	for i=1,grid:get_size('craft') do
		local s = grid:get_stack('craft',i)
		local v = minetest.get_item_group(s:get_name(),'crafttool')
		if v ~= 0 then
			local dmg = 65536 / v
			local tool = recipe[i] 
			tool:add_wear(dmg)
			grid:set_stack('craft',i,tool)
		end
	end
	return nil
end)

local mod_override = function(mod,name,val)
	if minetest.get_modpath(mod) then
		local id = mod..':'..name
		local og = minetest.registered_tools[id].groups
		og.crafttool = val
		minetest.override_item(id, {groups = og})
	end
end

mod_override('xdecor',     'hammer',     70)
mod_override('screwdriver','screwdriver',40)

minetest.register_tool('sorcery:vice', {
	description = 'Vice';
	inventory_image = 'sorcery_vice.png';
	group = { crafttool = 100; }
})
minetest.register_craft {
	output = 'sorcery:vice';
	recipe = {
		{'default:steel_ingot','sorcery:screw_steel','default:steel_ingot'};
		{'default:bronze_ingot','sorcery:screw_steel','default:bronze_ingot'};
		{'default:tin_ingot','default:tin_ingot','default:tin_ingot'};
	};
}
-- chisel