-
Notifications
You must be signed in to change notification settings - Fork 0
/
epic_block.lua
74 lines (61 loc) · 1.86 KB
/
epic_block.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
local update_formspec = function(meta)
local skyboxname = meta:get_string("skyboxname")
meta:set_string("infotext", "Set skybox block: name=" .. skyboxname)
local selected = 1
local list = ""
for i,skyboxdef in ipairs(epic_skybox.list) do
if skyboxdef.name == skyboxname then
selected = i
end
list = list .. minetest.formspec_escape(skyboxdef.name)
if i < #epic_skybox.list then
-- not end of list
list = list .. ","
end
end
meta:set_string("formspec", "size[8,6;]" ..
"textlist[0,0.1;8,5;skyboxname;" .. list .. ";" .. selected .. "]" ..
"button_exit[0.1,5.5;8,1;save;Save]" ..
"")
end
minetest.register_node("epic_skybox:set", {
description = "Epic set skybox block: sets the skybox for the player",
tiles = epic.create_texture("action", "epic_sky.png"),
paramtype2 = "facedir",
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1},
on_rotate = epic.on_rotate,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("skyboxname", "")
update_formspec(meta, pos)
end,
on_receive_fields = function(pos, _, fields, sender)
if not sender or minetest.is_protected(pos, sender:get_player_name()) then
-- not allowed
return
end
local meta = minetest.get_meta(pos)
if fields.skyboxname then
local parts = fields.skyboxname:split(":")
if parts[1] == "CHG" then
local selected_box = tonumber(parts[2])
local skyboxdef = epic_skybox.list[selected_box]
if skyboxdef and skyboxdef.name then
meta:set_string("skyboxname", skyboxdef.name)
end
update_formspec(meta, pos)
end
end
end,
epic = {
on_enter = function(_, meta, player, ctx)
local skyboxname = meta:get_string("skyboxname")
for _, skyboxdef in ipairs(epic_skybox.list) do
if skyboxdef.name == skyboxname then
epic_skybox.set_skybox(player, skyboxdef)
end
end
ctx.next()
end
}
})