summaryrefslogtreecommitdiff
path: root/homedecor/cobweb.lua
blob: 43b7794fa65cc1b566d22da62956fc637d34bdfe (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

local S = homedecor_i18n.gettext

minetest.register_node("homedecor:cobweb_corner", {
	description = S("Cobweb"),
	drawtype = "torchlike",
	tiles = { "homedecor_cobweb_torchlike.png" },
	inventory_image = "homedecor_cobweb.png",
	wield_image = "homedecor_cobweb.png",
	paramtype = "light",
	paramtype2 = "wallmounted",
	sunlight_propagates = true,
	liquid_viscosity = 8,
	liquidtype = "source",
	liquid_alternative_flowing = "homedecor:cobweb_corner",
	liquid_alternative_source = "homedecor:cobweb_corner",
	liquid_renewable = false,
	liquid_range = 0,
	walkable = false,
	selection_box = { type = "regular" },
	visual_scale = 1.4,
	groups = { snappy = 3, liquid=3 },
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		homedecor.rotate_cobweb(pos)
	end
})

minetest.register_node("homedecor:cobweb_centered", {
	description = S("Cobweb"),
	drawtype = "nodebox",
	tiles = { "homedecor_cobweb.png" },
	inventory_image = "homedecor_cobweb.png",
	paramtype = "light",
	paramtype2 = "facedir",
	sunlight_propagates = true,
	liquid_viscosity = 8,
	liquidtype = "source",
	liquid_alternative_flowing = "homedecor:cobweb_centered",
	liquid_alternative_source = "homedecor:cobweb_centered",
	liquid_renewable = false,
	liquid_range = 0,
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = { -0.5, -0.5, -0.1, 0.5, 0.5, 0.1 }
	},
	node_box = {
		type = "fixed",
		fixed = { -0.5, -0.5, 0, 0.5, 0.5, 0 }
	},
	groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
	drop = "homedecor:cobweb_corner"
})

minetest.register_node("homedecor:cobweb_flat", {
	description = S("Cobweb"),
	drawtype = "nodebox",
	tiles = { "homedecor_cobweb.png" },
	inventory_image = "homedecor_cobweb.png",
	paramtype = "light",
	paramtype2 = "facedir",
	sunlight_propagates = true,
	liquid_viscosity = 8,
	liquidtype = "source",
	liquid_alternative_flowing = "homedecor:cobweb_flat",
	liquid_alternative_source = "homedecor:cobweb_flat",
	liquid_renewable = false,
	liquid_range = 0,
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = { -0.5, -0.5, 0.4, 0.5, 0.5, 0.5 }
	},
	node_box = {
		type = "fixed",
		fixed = { -0.5, -0.5, 0.495, 0.5, 0.5, 0.495 }
	},
	groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
	drop = "homedecor:cobweb_corner"
})

minetest.register_node("homedecor:cobweb_plantlike", {
	description = S("Cobweb"),
	drawtype = "plantlike",
	tiles = { "homedecor_cobweb_plantlike.png" },
	inventory_image = "homedecor_cobweb.png",
	paramtype = "light",
	paramtype2 = "facedir",
	sunlight_propagates = true,
	liquid_viscosity = 8,
	liquidtype = "source",
	liquid_alternative_flowing = "homedecor:cobweb_plantlike",
	liquid_alternative_source = "homedecor:cobweb_plantlike",
	liquid_renewable = false,
	liquid_range = 0,
	walkable = false,
	selection_box = { type = "regular" },
	visual_scale = 1.189,
	groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
	drop = "homedecor:cobweb_corner"
})

-- helper function to rotate the cobweb after it's placed

function homedecor.rotate_cobweb(pos)
	local wall_xm = minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name
	local wall_xp = minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name
	local wall_zm = minetest.get_node({ x=pos.x,   y=pos.y, z=pos.z-1}).name
	local wall_zp = minetest.get_node({ x=pos.x,   y=pos.y, z=pos.z+1}).name

	local iswall_xm = (wall_xm ~= "air" and not string.find(wall_xm, "homedecor:cobweb"))
	local iswall_xp = (wall_xp ~= "air" and not string.find(wall_xp, "homedecor:cobweb"))
	local iswall_zm = (wall_zm ~= "air" and not string.find(wall_zm, "homedecor:cobweb"))
	local iswall_zp = (wall_zp ~= "air" and not string.find(wall_zp, "homedecor:cobweb"))

	-- only xm+zp, or only xp+zm means on-floor torchlike

	if (iswall_xm and iswall_zp and not iswall_xp and not iswall_zm)
	or (iswall_xp and iswall_zm and not iswall_xm and not iswall_zp) then
		minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 1})

	-- only xm+zm, or only xp+zp means on-ceiling torchlike

	elseif (iswall_xm and iswall_zm and not iswall_xp and not iswall_zp)
	or (iswall_xp and iswall_zp and not iswall_xm and not iswall_zm) then
		minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 0})

	-- only xm+xp means nodebox (not rotated, 0 degrees)

	elseif iswall_xm and iswall_xp and not iswall_zm and not iswall_zp then
		minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 0})

	-- only zm+zp means nodebox rotated to 90 degrees

	elseif iswall_zm and iswall_zp and not iswall_xm and not iswall_xp then
		minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 1})

	-- ok, there aren't any simple two-wall corners or opposing walls.
	-- Are there any standalone walls?

	elseif iswall_xm and not iswall_xp and not iswall_zm and not iswall_zp then
		minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 3})

	elseif iswall_xp and not iswall_xm and not iswall_zm and not iswall_zp then
		minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 1})

	elseif iswall_zm and not iswall_xm and not iswall_xp and not iswall_zp then
		minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 2})

	elseif iswall_zp and not iswall_xm and not iswall_xp and not iswall_zm then
		minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 0})

	-- if all else fails, place the plantlike version as a fallback.

	else
		minetest.set_node(pos, {name = "homedecor:cobweb_plantlike", param2 = 0})
	end

end

-- convert existing cobwebs

minetest.register_abm({
	nodenames = { "homedecor:cobweb" },
	interval = 1,
	chance = 1,
	action = function(pos, node, active_object_count, active_object_count_wider)
		homedecor.rotate_cobweb(pos)
	end
})