-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooks.lua
More file actions
64 lines (55 loc) · 1.53 KB
/
Copy pathbooks.lua
File metadata and controls
64 lines (55 loc) · 1.53 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
local data = {}
rednet.open("left")
p = peripheral.wrap("bottom")
function checkSlots(id)
data = {}
local slot
local name
local slots = p.getAllStacks()
for i,j in pairs(slots) do
slot = i
name = j["display_name"]
-- print(name)
data[slot]=name
end
rednet.send(id,"done")
end
function removeSlot(slot)
p.pushItem("up", slot, 1)
rs.setOutput("left", true)
sleep(1)
rs.setOutput("left", false)
end
function book(slot,id)
p.pushItem("up", slot, 1)
turtle.select(1)
turtle.drop()
sleep(5)
getBook()
turtle.select(1)
turtle.dropDown()
rednet.send(tonumber(id), "done")
end
function getBook()
turtle.suck()
end
function getNames(id)
local nameTbl = textutils.serialize(data)
rednet.send(tonumber(id), nameTbl)
end
while true do
local id, msg, dis = rednet.receive()
local newmsg = string.match(msg, "%a+")
-- print(msg)
if newmsg == "checkSlots" then
checkSlots(id)
elseif newmsg == "getNames" then
getNames(id)
elseif newmsg == "remove" then
removeSlot(tonumber(string.match(msg, "%d+")))
rednet.send(id,"done")
elseif newmsg == "books" then
slot = string.match(msg, "%d+")
book(tonumber(slot), id)
end
end