summaryrefslogtreecommitdiff
path: root/castle_tapestries/init.lua
blob: c4e5983f6a40acb78d9e762fe534bcf11b5b15f6 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")

local tapestry = {}

minetest.register_alias("castle:tapestry_top", "castle_tapestries:tapestry_top")
minetest.register_alias("castle:tapestry", "castle_tapestries:tapestry")
minetest.register_alias("castle:tapestry_long", "castle_tapestries:tapestry_long")
minetest.register_alias("castle:tapestry_very_long", "castle_tapestries:tapestry_very_long")

minetest.register_node("castle_tapestries:tapestry_top", {
	drawtype = "nodebox",
	description = S("Tapestry Top"),
	tiles = {"default_wood.png"},
	sunlight_propagates = true,
	groups = {flammable=3,oddly_breakable_by_hand=3},
	sounds = default.node_sound_defaults(),
	paramtype = "light",
	paramtype2 = "facedir",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.6,-0.5,0.375,0.6,-0.375,0.5},
		},
	},
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.6,-0.5,0.375,0.6,-0.375,0.5},
		},
	},
})

minetest.register_craft({
	type = "shapeless",
	output = 'castle_tapestries:tapestry_top',
	recipe = {'default:stick'},
})

tapestry.colours = {
	"white",
	"grey",
	"black",
	"red",
	"yellow",
	"green",
	"cyan",
	"blue",
	"magenta",
	"orange",
	"violet",
	"dark_grey",
	"dark_green",
	"pink",
	"brown",
}

-- Regular-length tapestry

minetest.register_node("castle_tapestries:tapestry", {
	drawtype = "mesh",
	mesh = "castle_tapestry.obj",
	description = S("Tapestry"),
	tiles = {"castle_tapestry.png"},
	inventory_image = "castle_tapestry_inv.png",
	groups = {oddly_breakable_by_hand=3,flammable=3, ud_param2_colorable = 1},
	sounds = default.node_sound_defaults(),
	paramtype = "light",
	paramtype2 = "colorwallmounted",
	palette = "unifieddyes_palette_colorwallmounted.png",
	walkable = false,
	selection_box = {
		type = "wallmounted",
		wall_side = {-0.5,-0.5,0.4375,0.5,1.5,0.5},
	},
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
		unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
	end,
	after_dig_node = unifieddyes.after_dig_node,
	on_rotate = unifieddyes.fix_after_screwdriver_nsew
})

-- Crafting from wool and a stick

minetest.register_craft({
	type = "shapeless",
	output = 'castle_tapestries:tapestry',
	recipe = {'wool:white', 'default:stick'},
})

-- Long tapestry

minetest.register_node("castle_tapestries:tapestry_long", {
	drawtype = "mesh",
	mesh = "castle_tapestry_long.obj",
	description = S("Tapestry (Long)"),
	tiles = {"castle_tapestry.png"},
	inventory_image = "castle_tapestry_long_inv.png",
	groups = {oddly_breakable_by_hand=3,flammable=3, ud_param2_colorable = 1},
	sounds = default.node_sound_defaults(),
	paramtype = "light",
	paramtype2 = "colorwallmounted",
	palette = "unifieddyes_palette_colorwallmounted.png",
	walkable = false,
	selection_box = {
		type = "wallmounted",
		wall_side = {-0.5,-0.5,0.4375,0.5,2.5,0.5},
	},
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
		unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
	end,
	after_dig_node = unifieddyes.after_dig_node,
	on_rotate = unifieddyes.fix_after_screwdriver_nsew
})

-- Crafting from normal tapestry and wool

minetest.register_craft({
	type = "shapeless",
	output = 'castle_tapestries:tapestry_long',
	recipe = {'wool:white', 'castle_tapestries:tapestry'},
})

-- Very long tapestry

minetest.register_node("castle_tapestries:tapestry_very_long", {
	drawtype = "mesh",
	mesh = "castle_tapestry_very_long.obj",
	description = S("Tapestry (Very Long)"),
	tiles = {"castle_tapestry.png"},
	inventory_image = "castle_tapestry_very_long_inv.png",
	groups = {oddly_breakable_by_hand=3,flammable=3, ud_param2_colorable = 1},
	sounds = default.node_sound_defaults(),
	paramtype = "light",
	paramtype2 = "colorwallmounted",
	palette = "unifieddyes_palette_colorwallmounted.png",
	walkable = false,
	selection_box = {
		type = "wallmounted",
		wall_side = {-0.5,-0.5,0.4375,0.5,3.5,0.5},
	},
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
		unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
	end,
	after_dig_node = unifieddyes.after_dig_node,
	on_rotate = unifieddyes.fix_after_screwdriver_nsew
})

-- Crafting from long tapestry and wool

minetest.register_craft({
	type = "shapeless",
	output = 'castle_tapestries:tapestry_very_long',
	recipe = {'wool:white', 'castle_tapestries:tapestry_long'},
})

-- Convert static tapestries to param2 color

local old_static_tapestries = {}

for _, color in ipairs(tapestry.colours) do
	table.insert(old_static_tapestries, "castle:tapestry_"..color)
	table.insert(old_static_tapestries, "castle:long_tapestry_"..color)
	table.insert(old_static_tapestries, "castle:very_long_tapestry_"..color)
end

minetest.register_lbm({
	name = "castle_tapestries:convert_tapestries",
	label = "Convert tapestries to use param2 color",
	run_at_every_load = false,
	nodenames = old_static_tapestries,
	action = function(pos, node)
		local oldname = node.name
		local color = string.sub(oldname, string.find(oldname, "_", -12) + 1)

		if color == "red" then
			color = "medium_red"
		elseif color == "cyan" then
			color = "medium_cyan"
		elseif color == "blue" then
			color = "medium_blue"
		elseif color == "magenta" then
			color = "medium_magenta"
		end

		local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, "wallmounted")

		local old_fdir = math.floor(node.param2 % 32)
		local new_fdir = 3

		if old_fdir == 0 then
			new_fdir = 3
		elseif old_fdir == 1 then
			new_fdir = 4
		elseif old_fdir == 2 then
			new_fdir = 2
		elseif old_fdir == 3 then
			new_fdir = 5
		end

		local param2 = paletteidx + new_fdir
		local newname = "castle_tapestries:tapestry"
		if string.find(oldname, ":long") then
			newname = "castle_tapestries:tapestry_long"
		elseif string.find(oldname, ":very_long") then
			newname = "castle_tapestries:tapestry_very_long"
		end

		minetest.set_node(pos, { name = newname, param2 = param2 })
		local meta = minetest.get_meta(pos)
		meta:set_string("dye", "unifieddyes:"..color)
	end
})