This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclipboard.lua
78 lines (56 loc) · 1.72 KB
/
clipboard.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
local lwcomp = ...
local S = lwcomp.S
local function on_use (itemstack, user, pointed_thing)
if itemstack and user and user:is_player () then
local ver = lwcomp.get_minetest_version ()
local meta = itemstack:get_meta()
local formspec
if ver.major >= 5 and ver.minor >= 4 then
formspec =
"formspec_version[3]\n"..
"size[17,12.5]\n"..
"style[clipboard;font=mono]\n"..
"textarea[0.5,0.5;16,10;clipboard;;"..
minetest.formspec_escape (meta:get_string ("contents"))..
"]\nbutton_exit[7.5,11;2,1;save;Save]"
else
formspec =
"formspec_version[3]\n"..
"size[17,12.5]\n"..
"textarea[0.5,0.5;16,10;clipboard;;"..
minetest.formspec_escape (meta:get_string ("contents"))..
"]\nbutton_exit[7.5,11;2,1;save;Save]"
end
minetest.show_formspec (user:get_player_name (), "lwcomputers:clipboard", formspec)
end
return nil
end
lwcomputers.register_clipboard ("lwcomputers:clipboard", nil, {
description = S("Computer Clipboard"),
short_description = S("Computer Clipboard"),
inventory_image = "lwcomputers_clipboard_item.png",
on_use = on_use
})
minetest.register_on_player_receive_fields(function (player, formname, fields)
if formname == "lwcomputers:clipboard" then
if fields.save then
if player then
if player:is_player () then
local stack = player:get_wielded_item ()
if stack then
if stack:get_name() == "lwcomputers:clipboard" then
local meta = stack:get_meta ()
if meta then
local content = (fields.clipboard or ""):sub (1, lwcomp.settings.max_clipboard_length)
meta:set_string ("contents", content)
player:set_wielded_item (stack)
end
end
end
end
end
end
end
return nil
end)
--