forked from minetest-mapserver/mapserver_mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoi.lua
87 lines (66 loc) · 2.19 KB
/
poi.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
-- possible icons: https://fontawesome.com/icons?d=gallery&s=brands,regular,solid&m=free
-- default: "home"
local update_formspec = function(meta)
local name = meta:get_string("name")
local icon = meta:get_string("icon") or "home"
local url = meta:get_string("url") or ""
meta:set_string("infotext", "POI, name:" .. name .. ", icon:" .. icon)
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0.2,1;4,1;name;Name;" .. name .. "]" ..
"field[4.2,1;4,1;icon;Icon;" .. icon .. "]" ..
-- col 2
"field[0.2,2;8,1;url;URL;" .. url .. "]" ..
-- col 3
"button_exit[0,3;8,1;save;Save]" ..
"")
end
local on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
if fields.save then
meta:set_string("name", fields.name)
meta:set_string("url", fields.url)
meta:set_string("icon", fields.icon or "home")
end
update_formspec(meta)
end
local register_poi = function(color, dye)
minetest.register_node("mapserver:poi_" .. color, {
description = "Mapserver POI (" .. color .. ")",
tiles = {
"[combine:16x16:0,0=mapserver_gold_block.png:3,2=mapserver_poi_" .. color .. ".png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = moditems.sound_glass(),
can_dig = mapserver.can_interact,
after_place_node = mapserver.after_place_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("name", "<unconfigured>")
meta:set_string("icon", "home")
meta:set_string("url", "")
update_formspec(meta)
end,
on_receive_fields = on_receive_fields
})
if mapserver.enable_crafting and (minetest.get_modpath("dye") or minetest.get_modpath("mcl_core")) then
minetest.register_craft({
output = 'mapserver:poi_' .. color,
recipe = {
{"", moditems.dye .. dye, ""},
{moditems.paper, moditems.goldblock, moditems.paper},
{"", moditems.glass, ""}
}
})
end
end
register_poi("blue", "blue")
register_poi("green", "green")
register_poi("orange", "orange")
register_poi("red", "red")
register_poi("purple", "violet")
-- default poi was always blue
minetest.register_alias("mapserver:poi", "mapserver:poi_blue")