Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local controlId = 5
- local builtMessages = {}
- local builtIndex = 1
- local function send(msg, type)
- local response = {
- type = type,
- message = msg
- }
- builtMessages[builtIndex] = response
- builtIndex = builtIndex + 1;
- end
- local function finalizeMessage()
- rednet.send(controlId, builtMessages)
- end
- local function sendInventory()
- local response = {
- slots = {},
- current = turtle.getSelectedSlot(),
- fuel = turtle.getFuelLevel()
- }
- for i=1,16,1 do
- response.slots[i] = turtle.getItemDetail(i)
- end
- send(response, "inventory")
- end
- local function refuel()
- if turtle.getFuelLevel() > 5 then
- return true
- end
- send("Refueling")
- local currentSlot = turtle.getSelectedSlot()
- turtle.select(1)
- if turtle.refuel(1) == false then
- turtle.select(currentSlot)
- send("Failed to refuel!", "log")
- return false
- end
- turtle.select(currentSlot)
- sendInventory()
- return true
- end
- local function sendInspect()
- end
- local function sendInspect_DISABLE()
- local response = {
- top = {},
- forward = {},
- bottom = {}
- }
- local hasBlock, data = turtle.inspectUp()
- if hasBlock then
- response.top = data
- else
- response.top = nil
- end
- hasBlock, data = turtle.inspect()
- if hasBlock then
- response.forward = data
- else
- response.forward = nil
- end
- hasBlock, data = turtle.inspectDown()
- if hasBlock then
- response.bottom = data
- else
- response.bottom = nil
- end
- send(response, "inspect")
- end
- local function handleMessage(msg)
- if msg == "left" then
- turtle.turnLeft()
- sendInspect()
- return
- end
- if msg == "right" then
- turtle.turnRight()
- sendInspect()
- return
- end
- if msg == "forward" then
- refuel();
- turtle.forward()
- sendInspect()
- sendInventory()
- return
- end
- if msg == "back" then
- refuel();
- turtle.back()
- sendInspect()
- sendInventory()
- return
- end
- if msg == "up" then
- refuel();
- turtle.up()
- sendInspect()
- sendInventory()
- return
- end
- if msg == "down" then
- refuel();
- turtle.down()
- sendInspect()
- sendInventory()
- return
- end
- if msg == "refuel" then
- refuel()
- return
- end
- if msg == "dig" then
- turtle.dig()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "digUp" then
- turtle.digUp()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "digDown" then
- turtle.digDown()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "place" then
- turtle.place()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "placeUp" then
- turtle.placeUp()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "placeDown" then
- turtle.placeDown()
- sendInventory()
- sendInspect()
- return
- end
- if msg == "inventory" then
- sendInventory()
- return
- end
- for i=1,16,1 do
- if msg == ("select " .. i) then
- send("Current slot: " .. i, "log")
- turtle.select(i)
- sendInventory()
- return
- end
- end
- send("Unexpected message: " .. msg, "log")
- end
- rednet.close("left")
- rednet.open("left")
- while true do
- local id, message = rednet.receive()
- if id == controlId then
- handleMessage(message)
- finalizeMessage()
- end
- end
Add Comment
Please, Sign In to add comment