summaryrefslogtreecommitdiff
path: root/trafficlight/init.lua
blob: bec44105be8b18ed198ca2d2e2e46252a2635aea (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
--[[
	StreetsMod: inDev Trafficlights
]]
minetest.register_node(":streets:trafficlight_bottom",{
	description = "Trafficlight",
	groups = {cracky = 1},
	paramtype = "light",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.25,-0.5,-0.25,0.25,0.25,0.25},
			{-0.2,0.25,-0.2,0.2,0.5,0.2}
		}
	},
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.25,-0.5,-0.25,0.25,2.5,0.25}
		}
	},
	after_place_node = function(pos,placer,itemstack)
		if minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" and minetest.get_node({x = pos.x, y = pos.y + 2, z = pos.z}).name == "air" then
			pos.y = pos.y + 1
			minetest.set_node(pos,{name="streets:trafficlight_middle"})
			pos.y = pos.y + 1
			minetest.set_node(pos,{name="streets:trafficlight_top"})
		else
			minetest.chat_send_player(placer:get_player_name(),"Not enough vertical space! The traffic light has a height of 3 blocks.")
			minetest.remove_node(pos)
		end
		--
		pos.y = pos.y - 2
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec", "field[channel;Channel;${channel}]")
	end,
	after_dig_node = function(pos, oldnode, oldmetadata, digger)
		pos.y = pos.y + 1
		minetest.remove_node(pos)
		pos.y = pos.y + 1
		minetest.remove_node(pos)
	end,
	on_receive_fields = function(pos, formname, fields, sender)
		minetest.env:get_meta(pos):set_string("channel", fields.channel)
	end,
	digiline = {
		receptor = {},
		effector = {
			action = function(pos,node,channel,msg)
				local setchannel = minetest.get_meta(pos):get_string("channel")
				if channel == setchannel then
					-- Trafficlight code goes here
				end
			end
		}
	}
})

minetest.register_node(":streets:trafficlight_middle",{
	description = "U cheater U",
	groups = {cracky = 1, not_in_creative_inventory = 1},
	paramtype = "light",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.2,-0.5,-0.2,0.2,0.5,0.2}
		}
	},
	pointable = false,
})

minetest.register_node(":streets:trafficlight_top",{
	description = "U cheater U",
	groups = {cracky = 1, not_in_creative_inventory = 1},
	paramtype = "light",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
			{-0.25,-0.5,-0.25,0.25,0.5,0.25}
		}
	},
	pointable = false,
})