Created
December 28, 2014 02:32
-
-
Save JayWood/6b262c39a4d8d46d36ef to your computer and use it in GitHub Desktop.
DW20 Books lua update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Books LUA file... | |
Originally by Direwolf20 | |
Update by Jay | |
--]] | |
local data = {} | |
rednet.open("right") | |
p = peripheral.wrap("bottom") | |
function clearInv() | |
for i = 1,16 do | |
turtle.select(i) | |
turtle.dropDown() | |
end | |
end | |
function checkSlots(id) | |
data = {} | |
local slot | |
local name | |
local slots = p.getAllStacks() | |
for i,j in pairs(slots) do | |
slot = i | |
--[[ | |
New mystcraft tables require you to use | |
the myst_book key instead. | |
@author Jay | |
]] | |
name = j['myst_book']["destination"] | |
-- 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 | |
clearInv() | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just updated line 30, nothing more. Latest open peripherals has a different data structure for Mystcraft books, or maybe it's Mystcraft. So the turtle would always return zero and done to the main system. Updating line 30 to use the 'new' ( if it is ) myst_book array key works now.
Since I'm a PHP geek I found a print_r equivalent and dumped all the data from a single book to find that out, here's a good print_r to get table data if you'd like: http://pastebin.com/A7JScXWk