-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetInfo.lua
60 lines (56 loc) · 1.6 KB
/
getInfo.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
--[[
This is a LUA code snipet for use in Minecraft with Computercraft and Logistic Pipes Mods.
Original code found at https://pastebin.com/7gb2cH88 credit MOOMOOMOO309 Jan 25th, 2015
]]
filePath="Info"
local function removeAll(str,char)
if #char~=1 then
return nil
end
for i=1,#str do
if string.sub(str,i,i)==char then
str=string.sub(str,1,i-1)..string.sub(str,i+1)
end
end
return str
end
local function findPeripheral(type)
local Peripherals=peripheral.getNames()
wildcardBeginning=string.sub(type,1,1)=="*"
wildcardEnd=string.sub(type,#type)=="*"
for i=1,#Peripherals do
index1,index2=string.find(peripheral.getType(Peripherals[i]),removeAll(type,"*"))
if wildcardBeginning and wildcardEnd and index1 then
return Peripherals[i]
elseif wildcardBeginning then
if index2==#peripheral.getType(Peripherals[i]) then
return Peripherals[i]
end
elseif wildcardEnd then
if index1==1 then
return Peripherals[i]
end
elseif peripheral.getType(Peripherals[i])==type then
return Peripherals[i]
end
end
end
local Items=peripheral.call(findPeripheral("LogisticsPipes*"),"getAvailableItems")
f=fs.open(filePath,"w")
for k,v in pairs(Items) do
id=v.getValue1()
f.write("ID: "..id.getId().."\n")
f.write("Unlocalized Name: "..id.getName().."\n")
f.write("Mod Name: "..id.getModName().."\n")
f.write("Meta: "..id.getData().."/"..id.getUndamaged().getData().."\n")
f.write("Count: "..m.getItemAmount(id).."\n\n")
end
f.close()
--[[
Sample Output:
ID: 542
Unlocalized Name: Copper Ore
Mod Name: IC2
Meta: 0/0
Count: 50251
]]