-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.lua
More file actions
160 lines (108 loc) · 2.63 KB
/
api.lua
File metadata and controls
160 lines (108 loc) · 2.63 KB
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
local lwcomp = ...
function lwcomputers.key_code (key)
return lwcomp.keys[key]
end
function lwcomputers.color (color)
return lwcomp.colors[color]
end
function lwcomputers.register_place_substitute (item, substitute)
if type (item) == "string" and (type (substitute) == "string" or
(type (substitute) == "table" and type (substitute[1]) == "string")) then
if not lwcomp.place_substitute[item] then
lwcomp.place_substitute[item] = substitute
return true
end
end
return false
end
function lwcomputers.register_crafting_mods (item, adds, removes)
local add = nil
local rem = nil
if type (item) == "string" and not lwcomp.crafting_mods[item] then
if type (adds) == "string" then
add = { adds }
elseif type (adds) == "table" then
add = adds
end
if type (removes) == "string" then
rem = { removes }
elseif type (removes) == "table" then
rem = removes
end
if add or rem then
local m = { }
if add then
m.add = add
end
if rem then
m.remove = rem
end
lwcomp.crafting_mods[item] = m
return true
end
end
return false
end
local function floppy_disk_on_destroy (itemstack)
local meta = itemstack:get_meta ()
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
lwcomp.filesys:delete_floppy (id)
end
end
end
function lwcomputers.register_floppy_disk (name, label, itemdef)
if type (name) ~= "string" then
return false
end
if lwcomp.floppy_disk[name] then
return false
end
lwcomp.floppy_disk[name] =
{
label = tostring (label or "")
}
if type (itemdef.diskfiles) == "table" then
lwcomp.floppy_disk[name].files = { }
local f = lwcomp.floppy_disk[name].files
for i = 1, #itemdef.diskfiles do
if type (itemdef.diskfiles[i]) == "table" then
if type (itemdef.diskfiles[i].source) == "string" and
type (itemdef.diskfiles[i].target) == "string" then
f[#f + 1] =
{
source = itemdef.diskfiles[i].source,
target = itemdef.diskfiles[i].target
}
end
end
end
itemdef.diskfiles = nil
end
itemdef.on_destroy = floppy_disk_on_destroy
itemdef.stack_max = 1
minetest.register_craftitem (name, itemdef)
return true
end
function lwcomputers.register_clipboard (name, size, itemdef)
size = tonumber (size or 0) or 0
if type (name) ~= "string" then
return false
end
if lwcomp.clipboards[name] then
return false
end
if size < 1 or size > lwcomp.settings.max_clipboard_length then
size = lwcomp.settings.max_clipboard_length
end
lwcomp.clipboards[name] =
{
contents = "contents",
size = size
}
itemdef.stack_max = 1
minetest.register_craftitem (name, itemdef)
return true
end
--