Browse code

Added mod "ts_furniture".

Tirifto authored on 2018-03-25 22:38:52
Showing 9 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+Ts_Furniture
2
+=====================================================================
3
+Main: Thomas-S
4
+Lisc: CC0
5
+Link: https://github.com/minetest-mods/ts_furniture
0 6
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+1,6c1,5
2
+< ts_furniture
3
+< ============
4
+< 
5
+< This mod adds basic furniture (Chairs, Tables, Small Tables, Tiny Tables, Benches).
6
+< It was made by Thomas-S.
7
+< It is published under the CC0 license.
8
+---
9
+> Ts_Furniture
10
+> =====================================================================
11
+> Main: Thomas-S
12
+> Lisc: CC0
13
+> Link: https://github.com/minetest-mods/ts_furniture
0 14
new file mode 100755
... ...
@@ -0,0 +1,3 @@
1
+CC0 Public Domain
2
+
3
+See https://creativecommons.org/publicdomain/zero/1.0/ for details.
0 4
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+Ts_Furniture
2
+=====================================================================
3
+Main: Thomas-S
4
+Lisc: CC0
5
+Link: https://github.com/minetest-mods/ts_furniture
0 6
new file mode 100755
... ...
@@ -0,0 +1,2 @@
1
+default
2
+moretrees?
0 3
new file mode 100755
... ...
@@ -0,0 +1 @@
1
+This mod adds basic furniture (Chairs, Tables, Small Tables, Tiny Tables, Benches).
0 2
new file mode 100755
... ...
@@ -0,0 +1,196 @@
1
+ts_furniture = {}
2
+
3
+-- If true, you can sit on chairs and benches, when right-click them.
4
+ts_furniture.enable_sitting = true
5
+
6
+
7
+-- The following code is from "Get Comfortable [cozy]" (by everamzah; published under WTFPL).
8
+-- Thomas S. modified it, so that it can be used in this mod
9
+minetest.register_globalstep(function(dtime)
10
+	local players = minetest.get_connected_players()
11
+	for i = 1, #players do
12
+		local name = players[i]:get_player_name()
13
+		if default.player_attached[name] and not players[i]:get_attach() and
14
+				(players[i]:get_player_control().up == true or
15
+						players[i]:get_player_control().down == true or
16
+						players[i]:get_player_control().left == true or
17
+						players[i]:get_player_control().right == true or
18
+						players[i]:get_player_control().jump == true) then
19
+			players[i]:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 })
20
+			players[i]:set_physics_override(1, 1, 1)
21
+			default.player_attached[name] = false
22
+			default.player_set_animation(players[i], "stand", 30)
23
+		end
24
+	end
25
+end)
26
+
27
+ts_furniture.sit = function(name, pos)
28
+	local player = minetest.get_player_by_name(name)
29
+	if default.player_attached[name] then
30
+		player:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 })
31
+		player:set_physics_override(1, 1, 1)
32
+		default.player_attached[name] = false
33
+		default.player_set_animation(player, "stand", 30)
34
+	else
35
+		player:moveto(pos)
36
+		player:set_eye_offset({ x = 0, y = -7, z = 2 }, { x = 0, y = 0, z = 0 })
37
+		player:set_physics_override(0, 0, 0)
38
+		default.player_attached[name] = true
39
+		default.player_set_animation(player, "sit", 30)
40
+	end
41
+end
42
+-- end of cozy-code
43
+
44
+local furnitures = {
45
+	["chair"] = {
46
+		description = "Chair",
47
+		sitting = true,
48
+		nodebox = {
49
+			{ -0.3, -0.5, 0.2, -0.2, 0.5, 0.3 }, -- foot 1
50
+			{ 0.2, -0.5, 0.2, 0.3, 0.5, 0.3 }, -- foot 2
51
+			{ 0.2, -0.5, -0.3, 0.3, -0.1, -0.2 }, -- foot 3
52
+			{ -0.3, -0.5, -0.3, -0.2, -0.1, -0.2 }, -- foot 4
53
+			{ -0.3, -0.1, -0.3, 0.3, 0, 0.2 }, -- seating
54
+			{ -0.2, 0.1, 0.25, 0.2, 0.4, 0.26 } -- conector 1-2
55
+		},
56
+		craft = function(recipe)
57
+			return {
58
+				{ "", "group:stick" },
59
+				{ recipe, recipe },
60
+				{ "group:stick", "group:stick" }
61
+			}
62
+		end
63
+	},
64
+	["table"] = {
65
+		description = "Table",
66
+		nodebox = {
67
+			{ -0.4, -0.5, -0.4, -0.3, 0.4, -0.3 }, -- foot 1
68
+			{ 0.3, -0.5, -0.4, 0.4, 0.4, -0.3 }, -- foot 2
69
+			{ -0.4, -0.5, 0.3, -0.3, 0.4, 0.4 }, -- foot 3
70
+			{ 0.3, -0.5, 0.3, 0.4, 0.4, 0.4 }, -- foot 4
71
+			{ -0.5, 0.4, -0.5, 0.5, 0.5, 0.5 }, -- table top
72
+		},
73
+		craft = function(recipe)
74
+			return {
75
+				{ recipe, recipe, recipe },
76
+				{ "group:stick", "", "group:stick" },
77
+				{ "group:stick", "", "group:stick" }
78
+			}
79
+		end
80
+	},
81
+	["small_table"] = {
82
+		description = "Small Table",
83
+		nodebox = {
84
+			{ -0.4, -0.5, -0.4, -0.3, 0.1, -0.3 }, -- foot 1
85
+			{ 0.3, -0.5, -0.4, 0.4, 0.1, -0.3 }, -- foot 2
86
+			{ -0.4, -0.5, 0.3, -0.3, 0.1, 0.4 }, -- foot 3
87
+			{ 0.3, -0.5, 0.3, 0.4, 0.1, 0.4 }, -- foot 4
88
+			{ -0.5, 0.1, -0.5, 0.5, 0.2, 0.5 }, -- table top
89
+		},
90
+		craft = function(recipe)
91
+			return {
92
+				{ recipe, recipe, recipe },
93
+				{ "group:stick", "", "group:stick" }
94
+			}
95
+		end
96
+	},
97
+	["tiny_table"] = {
98
+		description = "Tiny Table",
99
+		nodebox = {
100
+			{ -0.5, -0.1, -0.5, 0.5, 0, 0.5 }, -- table top
101
+			{ -0.4, -0.5, -0.5, -0.3, -0.1, 0.5 }, -- foot 1
102
+			{ 0.3, -0.5, -0.5, 0.4, -0.1, 0.5 }, -- foot 2
103
+		},
104
+		craft = function(recipe)
105
+			local bench_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_bench"
106
+			return {
107
+				{ bench_name, bench_name }
108
+			}
109
+		end
110
+	},
111
+	["bench"] = {
112
+		description = "Bench",
113
+		sitting = true,
114
+		nodebox = {
115
+			{ -0.5, -0.1, 0, 0.5, 0, 0.5 }, -- seating
116
+			{ -0.4, -0.5, 0, -0.3, -0.1, 0.5 }, -- foot 1
117
+			{ 0.3, -0.5, 0, 0.4, -0.1, 0.5 }, -- foot 2
118
+		},
119
+		craft = function(recipe)
120
+			return {
121
+				{ recipe, recipe },
122
+				{ "group:stick", "group:stick" }
123
+			}
124
+		end
125
+	},
126
+}
127
+
128
+local ignore_groups = {
129
+	["wood"] = true,
130
+	["stone"] = true,
131
+}
132
+
133
+function ts_furniture.register_furniture(recipe, description, texture)
134
+	local recipe_def = minetest.registered_items[recipe]
135
+	if not recipe_def then
136
+		return
137
+	end
138
+
139
+	local groups = {}
140
+	for k, v in pairs(recipe_def.groups) do
141
+		if not ignore_groups[k] then
142
+			groups[k] = v
143
+		end
144
+	end
145
+
146
+	for furniture, def in pairs(furnitures) do
147
+		local node_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_" .. furniture
148
+
149
+		def.on_rightclick = nil
150
+
151
+		if def.sitting and ts_furniture.enable_sitting then
152
+			def.on_rightclick = function(pos, node, player, itemstack, pointed_thing)
153
+				ts_furniture.sit(player:get_player_name(), pos)
154
+			end
155
+		end
156
+
157
+		minetest.register_node(":" .. node_name, {
158
+			description = description .. " " .. def.description,
159
+			drawtype = "nodebox",
160
+			paramtype = "light",
161
+			paramtype2 = "facedir",
162
+			sunlight_propagates = true,
163
+			tiles = { texture },
164
+			groups = groups,
165
+			node_box = {
166
+				type = "fixed",
167
+				fixed = def.nodebox
168
+			},
169
+			on_rightclick = def.on_rightclick
170
+		})
171
+
172
+		minetest.register_craft({
173
+			output = node_name,
174
+			recipe = def.craft(recipe)
175
+		})
176
+	end
177
+end
178
+
179
+ts_furniture.register_furniture("default:aspen_wood", "Aspen", "default_aspen_wood.png")
180
+ts_furniture.register_furniture("default:pine_wood", "Pine", "default_pine_wood.png")
181
+ts_furniture.register_furniture("default:acacia_wood", "Acacia", "default_acacia_wood.png")
182
+ts_furniture.register_furniture("default:wood", "Wooden", "default_wood.png")
183
+ts_furniture.register_furniture("default:junglewood", "Jungle Wood", "default_junglewood.png")
184
+
185
+if (minetest.get_modpath("moretrees")) then
186
+	ts_furniture.register_furniture("moretrees:apple_tree_planks", "Apple Tree", "moretrees_apple_tree_wood.png")
187
+	ts_furniture.register_furniture("moretrees:beech_planks", "Beech", "moretrees_beech_wood.png")
188
+	ts_furniture.register_furniture("moretrees:birch_planks", "Birch", "moretrees_birch_wood.png")
189
+	ts_furniture.register_furniture("moretrees:fir_planks", "Fir", "moretrees_fir_wood.png")
190
+	ts_furniture.register_furniture("moretrees:oak_planks", "Oak", "moretrees_oak_wood.png")
191
+	ts_furniture.register_furniture("moretrees:palm_planks", "Palm", "moretrees_palm_wood.png")
192
+	ts_furniture.register_furniture("moretrees:rubber_tree_planks", "Rubber Tree", "moretrees_rubber_tree_wood.png")
193
+	ts_furniture.register_furniture("moretrees:sequoia_planks", "Sequoia", "moretrees_sequoia_wood.png")
194
+	ts_furniture.register_furniture("moretrees:spruce_planks", "Spruce", "moretrees_spruce_wood.png")
195
+	ts_furniture.register_furniture("moretrees:willow_planks", "Willow", "moretrees_willow_wood.png")
196
+end
0 197
new file mode 100755
... ...
@@ -0,0 +1 @@
1
+name = ts_furniture
0 2
new file mode 100755
1 3
Binary files /dev/null and b/mods/ts_furniture/screenshot.png differ