-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
227 lines (204 loc) · 6.2 KB
/
init.lua
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
218
219
220
221
222
223
224
225
226
227
--[[
.___.__ .__.__ .__
__| _/|__| ____ |__| | |__| ____ ____ ______ ___________ ____ ____ ____ ______
/ __ | | |/ ___\| | | | |/ \_/ __ \ / ___// ___\_ __ \_/ __ \_/ __ \ / \ / ___/
/ /_/ | | / /_/ > | |_| | | \ ___/ \___ \\ \___| | \/\ ___/\ ___/| | \\___ \
\____ | |__\___ /|__|____/__|___| /\___ >____/____ >\___ >__| \___ >\___ >___| /____ >
\/ /_____/ \/ \/_____/ \/ \/ \/ \/ \/ \/
--]]
local load_time_start = os.clock()
digiline_screens = {}
digiline_screens.registered_screens = {}
minetest.register_entity("digiline_screens:entity", {
collisionbox = {0,0,0, 0,0,0},
physical = false,
visual = "upright_sprite",
textures = {"blank.png"},
})
-- not used yet:
--~ local function formate(i, w)
--~ if i.format == w then return i end
--~ local o = {}
--~ if i.format == 1 and w == 2 then
--~ for y = 1, #i do
--~ for x = 1, #i do
--~ local colp = o[i[y][x]]
--~ if colp == nil then colp = {} end
--~ colp[#colp+1] = {x, y}
--~ end
--~ end
--~ end
--~ end
local function make_texture(base, t, w, h)
local px = "digiline_screens_px.png"
local tex = base
if t.format == 0 then
tex = tex.."^[combine:"..w.."x"..h
for i = 1, #t do
tex = tex..":0,0="..t[i]
end
elseif t.format == 1 or t.format == nil then
for y = 1, #t do
for x = 1, #t[y] do
if t[y][x] then
tex = tex.."^([combine:"..w.."x"..h..":"..tostring(x-1)..","..
tostring(y-1).."="..px.."^[colorize:"..t[y][x]..":255)"
end
end
end
elseif t.format == 2 then
for col, poss in pairs(t) do
if col ~= "format" then
tex = tex.."^([combine:"..w.."x"..h
for i = 1, #poss do
local pos = poss[i]
local x = pos.x or pos[1]
local y = pos.y or pos[2]
tex = tex..":"..tostring(x-1)..","..tostring(y-1).."="..px
end
tex = tex.."^[colorize:"..col..":255)"
end
end
end
return tex
end
function digiline_screens.register_screen(name, spec, width, hight, entposs)
spec.digiline = spec.digiline or {}
spec.digiline.effector = spec.digiline.effector or {}
local f = spec.digiline.effector.action
spec.digiline.effector.action = function(pos, node, channel, msg)
if f then f(pos, node, channel, msg) end
local meta = minetest.get_meta(pos)
local setchan = meta:get_string("channel")
if setchan ~= channel then
return
end
if type(msg) ~= "table" then
return
end
local ent
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
local lent = obj:get_luaentity()
if lent and lent.name == "digiline_screens:entity" then
ent = obj
break
end
end
ent:set_properties({
textures={make_texture(spec.tiles[1], msg, 16, 16)}
})
end
local f = spec.after_place_node
spec.after_place_node = function(pos, placer, itemstack, pointed_thing)
if f then f(pos, placer, itemstack, pointed_thing) end
if spec.paramtype2 == "wallmounted" then
local entpos = entposs[minetest.get_node(pos).param2]
if entpos == nil then return end
local ent = minetest.add_entity(
vector.add(pos, entpos.delta),
"digiline_screens:entity")
ent:setyaw(entpos.yaw or 0)
else
minetest.add_entity(pos, "digiline_screens:entity")
end
end
local f = spec.on_construct
spec.on_construct = function(pos)
if f then f(pos) end
minetest.get_meta(pos):set_string("formspec",
"field[channel;Channel;${channel}]")
end
local f = spec.on_destruct
spec.on_destruct = function(pos)
if f then f(pos) end
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
local lent = obj:get_luaentity()
if lent and lent.name == "digiline_screens:entity" then
obj:remove()
break
end
end
end
local f = spec.on_receive_fields
spec.on_receive_fields = function(pos, formname, fields, player)
if f then f(pos, formname, fields, player) end
local name = player:get_player_name()
if minetest.is_protected(pos, name) and not
minetest.check_player_privs(name, {protection_bypass=true}) then
minetest.record_protection_violation(pos, name)
return
end
if fields.channel then
minetest.get_meta(pos):set_string("channel", fields.channel)
end
end
minetest.register_node(name, spec)
digiline_screens.registered_screens[name] = minetest.registered_nodes[name]
end
local entposs = {
[2] = {delta = {x = 0.437, y = 0, z = 0}, yaw = math.pi * 1.5},
[3] = {delta = {x = -0.437, y = 0, z = 0}, yaw = math.pi * 0.5},
[4] = {delta = {x = 0, y = 0, z = 0.437}, yaw = 0},
[5] = {delta = {x = 0, y = 0, z = -0.437}, yaw = math.pi},
}
local box = {
type = "wallmounted",
wall_top = {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}
}
digiline_screens.register_screen("digiline_screens:screen",
{
description = "digiline screen",
drawtype = "nodebox",
inventory_image = "digiline_screens_screen.png",
wield_image = "digiline_screens_screen.png",
tiles = {"digiline_screens_screen.png"},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
node_box = box,
selection_box = box,
groups = {choppy = 3, dig_immediate = 2},
light_source = 6,
after_place_node = function (pos, placer, itemstack)
local param2 = minetest.get_node(pos).param2
if param2 == 0 or param2 == 1 then
minetest.add_node(pos, {name = "digiline_screens:screen", param2 = 3})
end
end,
},
16,
16,
entposs
)
digiline_screens.register_screen("digiline_screens:screen2",
{
description = "digiline screen 8x8",
drawtype = "nodebox",
inventory_image = "digiline_screens_screen2.png",
wield_image = "digiline_screens_screen2.png",
tiles = {"digiline_screens_screen2.png"},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
node_box = box,
selection_box = box,
groups = {choppy = 3, dig_immediate = 2},
light_source = 6,
after_place_node = function (pos, placer, itemstack)
local param2 = minetest.get_node(pos).param2
if param2 == 0 or param2 == 1 then
minetest.add_node(pos, {name = "digiline_screens:screen2", param2 = 3})
end
end,
},
8,
8,
entposs
)
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "[digiline_screens] loaded after ca. "..time
if time > 0.05 then
print(msg)
else
minetest.log("info", msg)
end