local S = minetest.get_translator("hades_furniture")

--[[
   Some adjustments and expansions for Hades game added 2015 by Glünggi

   3D Forniture

   Copyright 2012 Tonyka

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   MA 02110-1301, USA.

   Contributors:

    InfinityProject

        suggested creating bathroom kit.

    cosarara97

        code.

]]--

--[[ ----- Basic furniture ----- ]]

-- Table and chair
local furniture_colors = {
	{"_uncolored", S("Uncolored Table"), S("Uncolored Chair")},
	{"_black", S("Black Table"), S("Black Chair")},
	{"_white", S("White Table"), S("White Chair")},
}
for f=1, #furniture_colors do
	local append = furniture_colors[f][1]
	local desc_t = furniture_colors[f][2]
	local desc_c = furniture_colors[f][3]

	-- Table
	minetest.register_node("hades_furniture:table"..append, {
		description = desc_t,
		tiles = {
			"hades_furniture_wood"..append..".png",
		},
		drawtype = "nodebox",
		sunlight_propagates = true,
		paramtype = 'light',
		paramtype2 = "facedir",
		is_ground_content = false,
		node_box = {
			type = "fixed",
			fixed = {
				{-0.5,7/16,-0.5, 0.5,0.5,0.5},
				{-6/16, -0.5, -6/16, -4/16, 7/16, -4/16},
				{4/16, -0.5, -6/16, 6/16, 7/16, -4/16},
				{-6/16, -0.5, 4/16, -4/16, 7/16, 6/16},
				{4/16, -0.5, 4/16, 6/16, 7/16, 6/16},
			},
		},
		groups = {table=1, choppy=3,oddly_breakable_by_hand=2},
		sounds = hades_sounds.node_sound_wood_defaults(),
	})

	-- Chair
	minetest.register_node("hades_furniture:chair"..append,
		{ description = desc_c,
		tiles = {
			"hades_furniture_wood"..append..".png",
		},
		drawtype = "nodebox",
		sunlight_propagates = true,
		paramtype = 'light',
		paramtype2 = "facedir",
		is_ground_content = false,
		_hades_itemshow_offset = { x=-0.118, y=0, z=-0.118 },
		node_box = {
			type = "fixed",
			fixed = {
				-- front legs
				{-5/16,-0.5,-5/16, -4/16,0,-4/16},
				{4/16,-0.5,-5/16, 5/16,0,-4/16},
				-- back legs
				{4/16,-0.5,4/16, 5/16,0.5,5/16},
				{-5/16,-0.5,4/16, -4/16,0.5,5/16},
				-- seat
				{-5/16,-1/16,-5/16, 5/16,0,5/16},
				-- backrest
				{-4/16,1/16,4/16, 4/16,7/16,5/16},
			},
		},
		selection_box = {
			type = "fixed",
			fixed = {-5/16, -0.5, -5/16, 5/16, 0.5, 5/16},
		},
		groups = {chair=1, choppy=3,oddly_breakable_by_hand=2},
		sounds = hades_sounds.node_sound_wood_defaults(),
	})
end

local armchair_colors = {
	{"", "black", S("Black Armchair")},
	{"_white", "white", S("White Armchair")},
	{"_red", "red", S("Red Armchair")},
	{"_brown", "brown", S("Brown Armchair")},
	{"_blue", "blue", S("Blue Armchair")},
	{"_dark_green", "dark_green", S("Dark Green Armchair")},
}

-- Armchair
for a=1, #armchair_colors do
	local append = armchair_colors[a][1]
	local color = armchair_colors[a][2]
	local desc = armchair_colors[a][3]
	minetest.register_node("hades_furniture:armchair"..append, {
		description = desc,
		tiles = {
			"hades_furniture_armchair_top_" .. color .. ".png",
			"hades_furniture_armchair_back.png",
			"hades_furniture_armchair_left_side_" .. color .. ".png",
			"hades_furniture_armchair_right_side_" .. color .. ".png",
			"hades_furniture_armchair_back_" .. color .. ".png",
			"hades_furniture_armchair_front_" .. color .. ".png",
		},
		drawtype = "nodebox",
		sunlight_propagates = true,
		paramtype = 'light',
		paramtype2 = "facedir",
		is_ground_content = false,
		node_box = {
			type = "fixed",
			fixed = {
				--legs
				{ -0.4375, -0.5,   -0.4375, -0.375,  -0.375, -0.375 },
				{ 0.375,   -0.5,   -0.4375, 0.4375,  -0.375, -0.375 },
				{ -0.4375, -0.5,   0.375,   -0.375,  -0.375, 0.4375 },
				{ 0.375,   -0.5,   0.375,   0.4375,  -0.375, 0.4375 },
				--base/cushion
				{ -0.5,    -0.375, -0.5,    0.5,     0,      0.5 },
				--back
				{ -0.5,    0,      0.3125,  0.5,     0.5,    0.5 },
				--arms
				{ -0.5,    0,      -0.5,    -0.3125, 0.25,   0.3125 },
				{ 0.3125,  0,      -0.5,    0.5,     0.25,   0.3125 },
			},
		},
		collision_box = {
			type = "fixed",
			fixed = {
				--base/cushion down to floor
				{ -0.5,    -0.5, -0.5,    0.5,     0,      0.5 },
				--back
				{ -0.5,    0,      0.3125,  0.5,     0.5,    0.5 },
			},
		},
		selection_box = {
			type = "fixed",
			fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
		},
		groups = {armchair=1, choppy=3,oddly_breakable_by_hand=2},
		sounds = hades_sounds.node_sound_wood_defaults({
			footstep = hades_sounds.node_sound_cloth_defaults().footstep,
		}),
	})
end

--[[ ----- Medieval theme -----]]

-- Bars

local bars = {
	{ "bars_iron", "L_binding_bars_iron",
		--~ node name; iron bars that are aligned along an axis
		S("Straight Iron Bars"),
		--~ node name; iron bars that connect with each other
		S("Binding Iron Bars"),
		{ "hades_furniture_black_iron_s1.png" } },
	{ "bars", "L_binding_bars",
		--~ node name; steel bars that are aligned along an axis
		S("Straight Steel Bars"),
		--~ node name; steel bars that connect with each other
		S("Binding Steel Bars"),
		{ "hades_furniture_black_metal_s1.png" } },
	{ "rusty_bars", "binding_rusty_bars",
		--~ node name; rusty bars that are aligned along an axis
		S("Straight Rusty Bars"),
		--~ node name; rusty bars that connect with each other
		S("Binding Rusty Bars"),
		{ "columnia_rusty.png" } },
}

for b=1, #bars do
	local bar = bars[b]
	local id = bar[1]
	local id2 = bar[2]
	local desc1 = bar[3]
	local desc2 = bar[4]
	local tiles = bar[5]

	minetest.register_node("hades_furniture:"..id, {
		description = desc1,
		tiles = tiles,
		drawtype = "nodebox",
		sunlight_propagates = true,
		paramtype = 'light',
		paramtype2 = 'facedir',
		is_ground_content = false,
		node_box = {
			type = "fixed",
			fixed = {
				{-0.1,-0.5,-0.1, 0.1,0.5,0.1}, -- center bar
				{0.4,-0.5,-0.1, 0.5,0.5,0.1}, -- right bar
				{0.1,-0.5,-0.05, 0.4,-0.45,0.05}, -- right low rail
				{0.1,0.45,-0.05, 0.4,0.5,0.05}, -- right high rail
				{-0.5,-0.5,-0.1, -0.4,0.5,0.1}, -- left bar
				{-0.4,-0.5,-0.05, -0.1,-0.45,0.05}, -- left low rail
				{-0.4,0.45,-0.05, -0.1,0.5,0.05}, -- left high rail
			},
		},
		collision_box = {
			type = "fixed",
			fixed = {-0.5,-0.5,-0.15, 0.5,0.5,0.15},
		},
		groups = {metal_bars=1, cracky=1},
		sounds = hades_sounds.node_sound_metal_defaults(),
		on_rotate = "simple",
		_hades_shaper_next = "hades_furniture:"..id2,
	})

	-- Binding bars (for corners and junctions).
	-- Also, center bar is slightly thicker
	minetest.register_node("hades_furniture:"..id2,
		{
		description = desc2,
		tiles = tiles,
		drawtype = "nodebox",
		sunlight_propagates = true,
		paramtype = 'light',
		is_ground_content = false,
		connects_to = {"group:metal_bars", "hades_core:steelblock", "hades_columnia:rusty_block"},
		connect_sides = { "left", "right", "front", "back" },
		node_box = {
			type = "connected",
			fixed = {
				{-0.15,-0.5,-0.15, 0.15,0.5,0.15}, -- center bar
			},
			connect_right = {
				{0.4,-0.5,-0.1, 0.5,0.5,0.1}, -- bar
				{0.15,-0.5,-0.05, 0.4,-0.45,0.05}, -- low rail
				{0.15,0.45,-0.05, 0.4,0.5,0.05}, -- high rail
			},
			connect_left = {
				{-0.5,-0.5,-0.1, -0.4,0.5,0.1}, -- bar
				{-0.4,-0.5,-0.05, -0.15,-0.45,0.05}, -- low rail
				{-0.4,0.45,-0.05, -0.15,0.5,0.05}, -- high rail
			},
			connect_front = {
				{-0.1,-0.5,-0.5,0.1,0.5,-0.4}, -- bar
				{-0.05,-0.5,-0.4, 0.05,-0.45,-0.15}, -- low rail
				{-0.05,0.45,-0.4, 0.05,0.5,-0.15}, -- high rail
			},
			connect_back = {
				{-0.1,-0.5,0.4,0.1,0.5,0.5}, -- bar
				{-0.05,-0.5,0.15, 0.05,-0.45,0.4}, -- low rail
				{-0.05,0.45,0.15, 0.05,0.5,0.4}, -- high rail
			},
		},
		collision_box = {
			type = "connected",
			fixed = {
				{-0.15,-0.5,-0.15, 0.15,0.5,0.15}, -- center bar
			},
			connect_right = {
				{0.15,-0.5,-0.15, 0.5,0.5,0.15},
			},
			connect_left = {
				{-0.5,-0.5,-0.15, -0.15,0.5,0.15},
			},
			connect_back = {
				{-0.15,-0.5,-0.15, 0.15,0.5,0.5},
			},
			connect_front = {
				{-0.15,-0.5,-0.5, 0.15,0.5,-0.15},
			},

		},
		groups = {metal_bars=1, cracky=1,},
		sounds = hades_sounds.node_sound_metal_defaults(),
		_hades_shaper_next = "hades_furniture:"..id,
	})
end

-- The plant pot itself is passive, but it meant to be used to sustain
-- small plants and saplings and grow SOME seeds.
-- The intended use of the plant pot is that small plants be put
-- on it and they will survive by default.
-- Their growth is meant to be limited, usually up to stage 1.
-- This makes the plant pot useful to "lock" a plant in its growth
-- stage.
-- How plants and seeds interact with the plant pot must be
-- decided on a case-by-case basis in the code for that
-- plant.
minetest.register_node("hades_furniture:plant_pot", {
	description = S("Plant Pot"),
	-- This help text assumes that plants that actually utilize the plant pot
	-- exist, e.g. in hades_trees, hades_seeds and hades_grass
	_tt_help = S("Sustains small plants without growing large").."\n"..S("Some seeds can grow here"),
	paramtype = "light",
	tiles = {"hades_furniture_plant_pot_top.png", "hades_furniture_plant_pot_bottom.png", "hades_furniture_plant_pot_sides.png"},
	is_ground_content = false,
	drawtype = "nodebox",
	is_ground_content = false,
	node_box = {
		type = "fixed",
		fixed = {
			{-0.5,-0.5,-3/16, 0.5,0.5,3/16},
			{-7/16,-0.5,-5/16, 7/16,0.5,5/16},
			{-6/16,-0.5,-6/16, 6/16,0.5,6/16},
			{-5/16,-0.5,-7/16, 5/16,0.5,7/16},
			{-3/16,-0.5,-0.5, 3/16,0.5,0.5},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }},
	},
	groups = {cracky=3},
	sounds = hades_sounds.node_sound_stone_defaults({
		footstep = hades_sounds.node_sound_dirt_defaults().footstep,
	}),
})


-- Legacy aliases for removed table lamp
minetest.register_alias("hades_furniture:table_lamp_off", "hades_lamps:lantern_rusty")
minetest.register_alias("hades_furniture:table_lamp_low", "hades_lamps:lantern_rusty")
minetest.register_alias("hades_furniture:table_lamp_med", "hades_lamps:lantern_rusty")
minetest.register_alias("hades_furniture:table_lamp_hi", "hades_lamps:lantern_rusty")
minetest.register_alias("hades_furniture:table_lamp_max", "hades_lamps:lantern_rusty")


