survival={}
local default_path = minetest.get_modpath("survival")
local q = minetest.settings:get("texturequality")or "1"--"1"

minetest.register_on_joinplayer(function(player)
	local meta = player:get_meta()
    
	if meta:get_int("texturequality") == 1 then
		q = "1"
    elseif meta:get_int("texturequality") == 10 then
        q ="10"
	end
    minetest.log("action", "[" .. q .. "] PlayerQQQQQQQ.")
end)

minetest.register_node('survival:dirtwithgrass1', {
	tiles ={'dirtQ'..q..'.png^grassQ'..q..'.png', 'dirtQ'..q..'.png'}, 
	description= 'dirt',
	drawtype= 'normal',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	damage_per_second=10,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=true,
	pointable=true,
})
minetest.register_node('survival:dirt', {
	tiles ={'dirtQ'..q..'.png'}, 
	description= 'dirt',
	drawtype= 'allfaces_optional',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	damage_per_second=10,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=10.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=true,
	pointable=true,
	waving=0,
})
minetest.register_node('survival:tree', {
	tiles ={'woodQ'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'tree.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	damage_per_second=10,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=false,
	pointable=true,
	waving=0,
	collisionbox = {-0.5, 0.0, -0.5, 0.5, 10.0, 0.5},
})
minetest.register_node('survival:treebase', {
	tiles ={'woodQ'..q..'.png'}, 
	description= 'treebase',
	drawtype= 'mesh',
	mesh= 'treebase.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	damage_per_second=10,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=true,
	pointable=true,
	waving=0,
})
minetest.register_node('survival:tree_leaves', {
	tiles ={'leavesfullQ'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'leaves.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	damage_per_second=10,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=true,
	pointable=true,
	waving=0,
})

minetest.register_node('survival:deco1', {
	tiles ={'leave1Q'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'deco1.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=false,
	pointable=false,
	waving=0,
})
minetest.register_node('survival:deco2', {
	tiles ={'leave2Q'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'deco2.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=false,
	pointable=false,
	waving=0,
})
minetest.register_node('survival:deco3', {
	tiles ={'leave3Q'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'deco3.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=false,
	pointable=false,
	waving=0,
})
minetest.register_node('survival:deco4', {
	tiles ={'leave4Q'..q..'.png'}, 
	description= 'tree',
	drawtype= 'mesh',
	mesh= 'deco4.obj',
	is_ground_content=true,
	climbable=false,
	buildable_to=false,
	diggable=true,
	drop= '',
	drowning=1,
	floodable=false,
	range=1.0,
	sunlight_propagates=false,
	use_texture_alpha=false,
	walkable=false,
	pointable=false,
	waving=0,
})

local objects = {
	'survival:dirtwithgrass1',
    'survival:dirt',
    'survival:tree',
    'survival:treebase',
    'survival:tree_leaves',
    'survival:deco1',
    'survival:deco2',
    'survival:deco3',
    'survival:deco4',
}


--
-- Nodes overrider
--
minetest.register_on_player_receive_fields(function(player, formname, fields)
    local meta = player:get_meta()
    name = player:get_player_name()
	if formname ~= "configuration:texturequality" then
		return
	end
    q = "1"
    if fields.pixel then
        meta:set_int("texturequality",1)
        q="1"
	elseif fields.low then
        meta:set_int("texturequality",10)
        q="10"
	elseif fields.medium then
        meta:set_int("texturequality",25)
        q="25"
    elseif fields.big then
        meta:set_int("texturequality",50)
        q="50"
    
	end
    minetest.after(0.1, function()
        minetest.log("action", "[" .. q .. "] QQQQQQQQQQQQQQQQQQQQQQQQQQ.")
    	minetest.override_item('survival:dirtwithgrass1', {
    		tiles ={'dirtQ'..q..'.png^grassQ'..q..'.png', 'dirtQ'..q..'.png'}, })
        minetest.override_item('survival:dirt', {
    		tiles ={'dirtQ'..q..'.png'}, })
        minetest.override_item('survival:tree', {
    		tiles ={'woodQ'..q..'.png'}, })
        minetest.override_item('survival:treebase', {
    		tiles ={'woodQ'..q..'.png'}, })
        minetest.override_item('survival:tree_leaves', {
    		tiles ={'leavesfullQ'..q..'.png'}, })
        minetest.override_item('survival:deco1', {
    		tiles ={'leave1Q'..q..'.png'}, })
        minetest.override_item('survival:deco2', {
    		tiles ={'leave2Q'..q..'.png'}, })
        minetest.override_item('survival:deco3', {
    		tiles ={'leave3Q'..q..'.png'}, })
        minetest.override_item('survival:deco4', {
    		tiles ={'leave4Q'..q..'.png'}, })
	end)
	
end)