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
|
local S = core.get_translator("digitoilet")
--This part is technically copied from homedecor but probably not copyrightable,
--with it just being the shape of the selection/collision boxes
local toilet_sbox = {
type = "fixed",
fixed = { -6/16, -8/16, -8/16, 6/16, 9/16, 8/16 },
}
local toilet_cbox = {
type = "fixed",
fixed = {
{-6/16, -8/16, -8/16, 6/16, 0, 8/16 },
{-6/16, -8/16, 4/16, 6/16, 9/16, 8/16 }
}
}
--Copied part ends here
local function handlefields(pos,_,fields,player)
if not (fields.channel and player:is_player()) then
return
end
local name = player:get_player_name()
if core.is_protected(pos,name) and not core.check_player_privs(name,{protection_bypass=true}) then
core.record_protection_violation(pos,name)
return
end
core.get_meta(pos):set_string("channel",fields.channel)
end
local function handledigilines(pos,node,channel,msg)
if channel ~= core.get_meta(pos):get_string("channel") then return end
if type(msg) ~= "string" then return end
msg = string.lower(msg)
if msg == "open" then
node.name = "digitoilet:toilet_open"
core.swap_node(pos,node)
elseif msg == "close" then
node.name = "digitoilet:toilet_closed"
core.swap_node(pos,node)
elseif msg == "flush" then
core.sound_play("homedecor_toilet_flush", {
pos = pos,
max_hear_distance = 10,
})
elseif msg == "spray" then
if node.name ~= "digitoilet:toilet_open" then return end
local dir = core.fourdir_to_dir(node.param2)
dir = vector.rotate_around_axis(dir,vector.new(0,1,0),math.pi)
core.add_particlespawner({
amount = 300,
time = 2.5,
size = 1,
glow = 10,
collisiondetection = true,
object_collision = true,
texture = "homedecor_water_particle.png",
pos = {
min = pos,
max = pos,
},
vel = {
min = vector.add(vector.multiply(dir,4),vector.new(0,4,0)),
max = vector.add(vector.multiply(dir,5),vector.new(0,5,0)),
},
acc = {
min = vector.new(0,-1.5,0),
max = vector.new(0,-1,0),
},
exptime = {
min = 8,
max = 10,
},
drag = {
min = vector.new(0.7,0,0.7),
max = vector.new(0.9,0,0.9),
},
})
core.sound_play("homedecor_faucet", {
pos = pos,
max_hear_distance = 10,
})
elseif msg == "overflow" then
if node.name ~= "digitoilet:toilet_open" then return end
core.add_particlespawner({
amount = 150,
time = 2.5,
size = 1,
glow = 10,
collisiondetection = true,
object_collision = true,
texture = "homedecor_water_particle.png",
pos = {
min = pos,
max = pos,
},
vel = {
min = vector.new(-0.5,0,-0.5),
max = vector.new(0.5,0,0.5),
},
acc = {
min = vector.new(0,-1.5,0),
max = vector.new(0,-1,0),
},
exptime = {
min = 8,
max = 10,
},
})
core.sound_play("homedecor_toilet_flush", {
pos = pos,
max_hear_distance = 10,
})
end
end
core.register_node("digitoilet:toilet_closed", {
description = S("Digilines-Controlled Toilet"),
drawtype = "mesh",
paramtype = "light",
paramtype2 = "4dir",
mesh = "homedecor_toilet_closed.obj",
tiles = {
"building_blocks_marble.png",
"building_blocks_marble.png",
"building_blocks_marble.png",
"homedecor_generic_metal.png^[colorize:#495dc244",
},
selection_box = toilet_sbox,
node_box = toilet_cbox,
groups = {cracky=3,},
on_construct = function(pos)
local meta = core.get_meta(pos)
meta:set_string("formspec","field[channel;"..S("Channel")..";${channel}]")
end,
on_receive_fields = handlefields,
digilines = {
receptor = {},
effector = {
action = handledigilines,
},
},
})
core.register_node("digitoilet:toilet_open", {
description = S("Digilines-Controlled Toilet (open)"),
drawtype = "mesh",
paramtype = "light",
paramtype2 = "4dir",
drop = "digitoilet:toilet_closed",
mesh = "homedecor_toilet_open.obj",
tiles = {
"building_blocks_marble.png",
"building_blocks_marble.png",
"building_blocks_marble.png",
"default_water.png",
"homedecor_generic_metal.png^[colorize:#495dc244",
},
selection_box = toilet_sbox,
node_box = toilet_cbox,
groups = {cracky=3,not_in_creative_inventory=1},
on_construct = function(pos)
local meta = core.get_meta(pos)
meta:set_string("formspec","field[channel;"..S("Channel")..";${channel}]")
end,
on_receive_fields = handlefields,
digilines = {
receptor = {},
effector = {
action = handledigilines,
},
},
})
core.register_craft({
type = "shapeless",
output = "digitoilet:toilet_closed",
recipe = {"homedecor:toilet","digilines:wire_std_00000000"},
})
|