summaryrefslogtreecommitdiff
path: root/infrastructure/advanced_lane_control_lights.lua
blob: 94d7ce1a2b64040ddcc8bf2f1326396581c81a49 (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
-- Lane control lights

for i = 1, 6 do
	local groups = {}
	if i == 1 then 
		groups = {cracky = 3}
	else
		groups = {cracky = 3, not_in_creative_inventory = 1}
	end

	minetest.register_node("infrastructure:lane_control_lights_"..tostring(i), {
		description = "Lane control lights",
		tiles = {
			"infrastructure_traffic_lights_side.png",
			"infrastructure_traffic_lights_side.png",
			"infrastructure_traffic_lights_side.png",
			"infrastructure_traffic_lights_side.png",
			"infrastructure_traffic_lights_side.png",
			"infrastructure_lane_control_lights_"..tostring(i)..".png"
		},
		drawtype = "nodebox",
		paramtype = "light",
		paramtype2 = "facedir",
		on_construct = function(pos)
			local meta = minetest.get_meta(pos)
			meta:set_string("formspec", "field[channel;Channel;${channel}]")
		end,
		groups = {cracky = 3, not_in_creative_inventory = (i == 1 and 0 or 1)},
		light_source = TRAFFIC_LIGHTS_LIGHT_RANGE,
		drop = "infrastructure:lane_control_lights_1",
		node_box = {
			type = "fixed",
				fixed = {
					{-7/16, -7/16, -1/8, 7/16, 7/16, 1/8},
					{-7/16, 0, -1/4, -3/8, 7/16, -1/8},
					{3/8, 0, -1/4, 7/16, 7/16, -1/8},
					{-7/16, 3/8, -5/16, 7/16, 7/16, -1/8},
					{-1/16, -1/4, 0, 1/16, 1/4, 1/2 - 0.001},
					{-1/4, -1/4, 3/8, 1/4, 1/4, 1/2 - 0.001},
					{-1/4, -1/16, 0, 1/4, 1/16, 1/2 - 0.001}
				}
		},
		selection_box = {
			type = "fixed",
				fixed = {
					{-7/16, -7/16, -1/8, 7/16, 7/16, 1/8},
					{-7/16, 0, -1/4, -3/8, 7/16, -1/8},
					{3/8, 0, -1/4, 7/16, 7/16, -1/8},
					{-7/16, 3/8, -5/16, 7/16, 7/16, -1/8},
					{-1/16, -1/4, 0, 1/16, 1/4, 1/2 - 0.001},
					{-1/4, -1/4, 3/8, 1/4, 1/4, 1/2 - 0.001},
					{-1/4, -1/16, 0, 1/4, 1/16, 1/2 - 0.001}
				}

		},
		on_receive_fields = function(pos, formname, fields)
			if (fields.channel) then
				minetest.get_meta(pos):set_string("channel", fields.channel)
			end
		end,
		digiline = {
			receptor = {},
			effector = {
				action = function(pos, node, channel, msg)
					local setchan = minetest.get_meta(pos):get_string("channel")
					if setchan ~= channel or type(msg) ~= "string" then
						return
					end
					msg = string.lower(msg)
					if (msg=="off") then
						node.name = "infrastructure:lane_control_lights_1"
					elseif (msg=="green") then
						node.name = "infrastructure:lane_control_lights_3"
					elseif (msg=="red") then
						node.name = "infrastructure:lane_control_lights_2"
					elseif (msg=="yellowleft") then
						node.name = "infrastructure:lane_control_lights_5"
					elseif (msg=="yellowright") then
						node.name = "infrastructure:lane_control_lights_4"
					elseif (msg=="yellow") then
						node.name = "infrastructure:lane_control_lights_6"
					end
					minetest.set_node(pos,node)
					minetest.get_meta(pos):set_string("channel",setchan)
				end
			}
		}
	})
end

minetest.register_alias("infrastructure:lane_control_lights", "infrastructure:lane_control_lights_1")