summaryrefslogtreecommitdiff
path: root/lrfurn/longsofas.lua
blob: a1721a9d1849cb575acfe8bbcbc344a1b039f4e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

local longsofa_sbox = {
	type = "fixed",
	fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 2.5}
}

local longsofa_cbox = {
	type = "fixed",
	fixed = { 
		{-0.5, -0.5, -0.5, 0.5, 0, 2.5 },
		{-0.5, -0.5, 0.5, -0.4, 0.5, 2.5 }
	}
}

for i in ipairs(lrfurn.colors) do
	local colour = lrfurn.colors[i][1]
	local hue = lrfurn.colors[i][2]

	minetest.register_node("lrfurn:longsofa_"..colour, {
		description = "Long Sofa ("..colour..")",
		drawtype = "mesh",
		mesh = "lrfurn_sofa_long.obj",
		tiles = {
			"lrfurn_bg_white.png^[colorize:"..hue.."^lrfurn_sofa_overlay.png",
			"lrfurn_sofa_bottom.png"
		},
		paramtype = "light",
		paramtype2 = "facedir",
		groups = {snappy=3},
		sounds = default.node_sound_wood_defaults(),
		selection_box = longsofa_sbox,
		node_box = longsofa_cbox,
		on_rotate = screwdriver.disallow,

		after_place_node = function(pos, placer, itemstack, pointed_thing)
			if minetest.is_protected(pos, placer:get_player_name()) then return true end

			local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false)

			if lrfurn.check_forward(pos, fdir, true, placer) then
				minetest.set_node(pos, {name = "lrfurn:longsofa_"..colour, param2 = fdir})
				itemstack:take_item()
			else
				minetest.chat_send_player(placer:get_player_name(), "No room to place the sofa!")
				minetest.set_node(pos, { name = "air" })
			end
			return itemstack
		end,
		on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
			if not clicker:is_player() then
				return itemstack
			end
			pos.y = pos.y-0.5
			clicker:setpos(pos)
			clicker:set_hp(20)
			return itemstack
		end
	})

	minetest.register_alias("lrfurn:longsofa_left_"..colour, "air")
	minetest.register_alias("lrfurn:longsofa_middle_"..colour, "air")
	minetest.register_alias("lrfurn:longsofa_right_"..colour, "lrfurn:longsofa_"..colour)

	minetest.register_craft({
		output = "lrfurn:longsofa_"..colour,
		recipe = {
			{"wool:"..colour, "wool:"..colour, "wool:"..colour, },
			{"stairs:slab_wood", "stairs:slab_wood", "stairs:slab_wood", },
			{"group:stick", "group:stick", "group:stick", }
		}
	})

	minetest.register_craft({
		output = "lrfurn:longsofa_"..colour,
		recipe = {
			{"wool:"..colour, "wool:"..colour, "wool:"..colour, },
			{"moreblocks:slab_wood", "moreblocks:slab_wood", "moreblocks:slab_wood", },
			{"group:stick", "group:stick", "group:stick", }
		}
	})

end

if minetest.setting_get("log_mods") then
	minetest.log("action", "long sofas loaded")
end