Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function refuel()
- count = turtle.getItemCount(16)
- print("Got "..tostring(count).." coal blocks")
- if count < 64 then
- toGet = 64 - count
- print("Getting "..tostring(toGet).." coal blocks")
- turtle.select(16)
- turtle.suck(toGet)
- end
- if turtle.getFuelLevel() < 1000 then
- print("Low on fuel --> refueling")
- turtle.select(16)
- turtle.refuel(64)
- refuel()
- end
- end
- refuel()
- print("Initial refil finished")
- rednet.open("left")
- h = fs.open("inventory","r")
- inventory = textutils.unserialize(h.readAll())
- h.close()
- inventoryState = {}
- for i=1,15 do
- inventoryState[i] = (turtle.getItemCount(i) > 0)
- end
- while true do
- event,id,msg = os.pullEvent()
- if event == "turtle_inventory" then
- for i=1,15 do
- if (turtle.getItemCount(i) > 0) ~= inventoryState[i] then
- inventoryState[i] = not inventoryState[i]
- newDestination = i
- end
- end
- rednet.send(5,"received","nexus_portal")
- id,msg=rednet.receive("nexus_portal")
- inventory[newDestination] = msg
- fs.delete("inventory")
- h = fs.open("inventory","w")
- h.write(textutils.serialize(inventory))
- h.close()
- elseif event == "rednet_message" and msg ~= "drawbridges" then
- msg = textutils.unserialize(msg)
- print("Looking for "..msg[2])
- local i = 1
- while inventory[i] ~= msg[2] and i < 16 do
- print("Not in slot "..tostring(i))
- i = i + 1
- end
- if i < 16 then
- selection = i
- print(msg[2].." is in slot "..tostring(selection))
- if msg[1] == "select" then
- refuel()
- print("Selecting "..msg[2].." in slot "..tostring(selection))
- turtle.select(selection)
- turtle.back()
- while turtle.up() do break end
- turtle.forward()
- turtle.dropUp()
- rednet.broadcast("drawbridges","nexus_portal")
- sleep(5)
- rednet.broadcast("drawbridges","nexus_portal")
- turtle.suckUp()
- turtle.back()
- while turtle.detect() do
- turtle.down()
- end
- turtle.forward()
- elseif msg[1] == "remove" then
- print("Removing "..msg[2].." in slot "..tostring(selection))
- turtle.select(selection)
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- table.remove(inventory,selection)
- fs.delete("inventory")
- h = fs.open("inventory","w")
- h.write(textutils.serialize(inventory))
- h.close()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement