-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.lua
51 lines (44 loc) · 1.25 KB
/
Helper.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
local function GetItem(desiredItemID)
for i = 1, 16, 1 do
local data = turtle.getItemDetail(i)
if(data ~= nil) then
if(data.name == desiredItemID) then
return i
end
end
end
-- to avoid "too long without yielding" error:
turtle.inspect()
end
local function DropItem(desiredItemID)
for i = 1, 16, 1 do
local data = turtle.getItemDetail(i)
if(data ~= nil) then
if(data.name == desiredItemID) then
turtle.select(i)
turtle.drop()
end
end
end
end
local function isInvFull()
for i = 1, 16, 1 do
local data = turtle.getItemDetail(i)
if(data == nil) then
return false
end
end
return true
end
local function readState()
local file = fs.open("State.txt","a")
file.flush()
return fs.open("State.txt","r")
end
local function writeState(state)
local file = fs.open("State.txt","w")
file.write(state)
file.flush()
end
-- should create functions which automatically look if the way is free (for forward and up and that stuff)
return { GetItem = GetItem, DropItem = DropItem, isInvFull = isInvFull, readState = readState, writeState = writeState}