-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathench.lua
More file actions
87 lines (76 loc) · 1.63 KB
/
ench.lua
File metadata and controls
87 lines (76 loc) · 1.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
local args = { ... }
p = peripheral.wrap("right")
emptyRef = 1
bookRef = 2
books = 3
eBook = 4
enchLevel = tonumber(args[1])
pause = 1
currLevel = 0
outOfBooks = false
function suckBooks()
turtle.suckDown()
if not turtle.compareTo(bookRef) then
print("No books found in chest, disabling enchanting.")
outOfBooks = true
else
print("Books grabbed from chest.")
outOfBooks = false
end
end
function getBook()
print("Checking for book...")
turtle.select(books)
if turtle.compareTo(bookRef) then
print("Book(s) found in slot #" .. books .. ".")
outOfBooks = false
elseif turtle.compareTo(emptyRef) then
print("Slot #" .. books .. " is empty, sucking from chest...")
suckBooks()
else
print("Slot #" .. books .. " not a book and not empty, dropping item...")
turtle.dropDown()
print("Sucking from chest...")
suckBooks()
end
if not outOfBooks then
turtle.transferTo(eBook, 1)
end
end
function enchBook()
if not outOfBooks then
turtle.select(eBook)
if p.enchant(enchLevel) then
print("Enchant successful, dropping enchanted book...")
dropBook()
else
print("Enchant failed!?")
end
else
print("Out of books, skipping enchant.")
end
end
function dropBook()
turtle.select(eBook)
turtle.dropDown()
end
function ench()
print("Getting a book...")
getBook()
print("Enchanting book...")
enchBook()
end
turtle.select(books)
while true do
sleep(pause)
p.collect()
local newLevel = p.getLevels()
if(newLevel ~= currLevel) then
currLevel = newLevel
print("Level: " .. currLevel)
end
if p.getLevels() >= enchLevel then
print("Level " .. enchLevel .. " reached, enchanting...")
ench()
end
end