Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- deposit = peripheral.wrap("top")
- ender = peripheral.wrap("front")
- while ender == nil do
- turtle.turnRight()
- ender = peripheral.wrap("front")
- end
- lastSlot = ender.getInventorySize()
- function set(channel, data)
- -- Function originally coded by ilgazzi
- data = tostring(data)
- url = "http://craft-a-cloud.mooo.com/upload.php?name="..channel.."&data="..data
- encoded=textutils.urlEncode(url)
- http.request(url)
- local i=0
- while get(channel) ~= data do
- if i >= 20 then
- return false
- end
- sleep(0.25)
- i = i+1
- end
- return true
- end
- function get(channel)
- -- Function originally coded by ilgazzi
- url = "http://craft-a-cloud.mooo.com/download.php?name="..channel
- encoded=textutils.urlEncode(url)
- response = ""
- while response == "" do
- http.request(url)
- event, returnurl, response = os.pullEvent("http_success")
- response = response.readAll()
- end
- return response
- end
- function suckSlot(chest, slot, qty)
- chest.swapStacks(1,slot)
- if not qty then
- local ret = turtle.suck()
- else
- local ret = turtle.suck(qty)
- end
- chest.swapStacks(1,slot)
- return ret
- end
- turtle.suckSlot = suckSlot
- function suckSlotUp(chest, slot, qty)
- chest.swapStacks(1,slot)
- if not qty then
- local ret = turtle.suckUp()
- else
- local ret = turtle.suckUp(qty)
- end
- chest.swapStacks(1,slot)
- return ret
- end
- turtle.suckSlotUp = suckSlotUp
- function split(str,splitter)
- if not splitter then return end
- if not str then return end
- words = {}
- i=0
- for part in string.gmatch(str, "[^%"..splitter.."]+") do -- get each part
- i=i+1
- words[i] = part
- end
- return words
- end
- string.split = split
- function searchForItem(chest, itemRequest)
- inv = chest.getAllStacks()
- if #inv <= 0 then
- return false, "Inventory is empty"
- end
- for i=1,#inv do
- inv[i] = inv[i].all()
- if type(inv[i]) == "table" then
- if string.lower(inv[i].display_name) == itemRequest then
- return i
- end
- end
- end
- return false, "Item not found"
- end
- while true do
- slot = ender.getStackInSlot(lastSlot)
- if type(slot) == "table" then
- suckSlot(ender, lastSlot)
- turtle.dropUp()
- else
- commands = get("action")
- commands = string.split(commands, " ")
- if type(commands) == "table" then
- if commands[1] == "nil" then
- sleep(1)
- else
- set("action", "nil")
- print(commands[1])
- if commands[1] == "store" then -- ##store
- itemRequest = string.lower(string.gsub(commands[2], "_", " "))
- print("Storing "..itemRequest)
- slot,sError = searchForItem(ender, itemRequest)
- if not sError then
- turtle.suckSlot(ender, slot, tonumber(commands[3]))
- turtle.dropUp()
- print("Success.")
- set("return", true)
- else
- print("Error: "..sError)
- set("return", false)
- end
- elseif commands[1] == "get" then -- ##get
- itemRequest = string.lower(string.gsub(commands[2], "_", " "))
- print("Pulling "..itemRequest)
- slot,sError = searchForItem(deposit, itemRequest)
- if not sError then
- turtle.suckSlotUp(deposit, slot, tonumber(commands[3]))
- turtle.drop()
- print("Success.")
- set("return", true)
- else
- print("Error: "..sError)
- set("return", false)
- end
- elseif commands[1] == "charge" then -- ##charge
- itemRequest = string.lower(string.gsub(commands[2], "_", " "))
- print("Charging "..itemRequest)
- slot,sError = searchForItem(ender, itemRequest)
- if not sError then
- turtle.suckSlot(ender, slot)
- turtle.turnRight()
- turtle.turnRight()
- turtle.drop()
- sleep(10)
- turtle.suck()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.drop()
- print("Success.")
- set("return", true)
- else
- print("Error: "..sError)
- set("return", false)
- end
- else
- set("return", false)
- end
- sleep(1)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement