Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SLOT_COUNT = 16
- local width, depth = 10, 10
- if (#arg == 2) then
- width = tonumber(arg[1])
- depth = tonumber(arg[2])
- else
- print('None or Malformed Size Given, Defaulting to 10x10')
- end
- function moveDigForward()
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.forward()
- end
- function refuelTurtle()
- for slot = 1, SLOT_COUNT, 1 do
- turtle.select(slot)
- local item = turtle.getItemDetail(slot)
- if (turtle.refuel(2)) then
- print("Turtle refueled")
- return true
- end
- end
- end
- function checkFuel()
- local fuel = turtle.getFuelLevel()
- if(fuel < 20) then
- refuelTurtle()
- else
- print("No fuel needed")
- end
- end
- function turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.forward()
- turtle.turnLeft()
- end
- function turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.forward()
- turtle.turnRight()
- end
- function returnHome()
- if(math.fmod(depth,2) == 0) then
- turtle.turnRight()
- for i = 1, depth, 1 do
- if(turtle.detect() == true) then
- turtle.dig()
- turtle.forward()
- else
- turtle.forward()
- end
- end
- else --depth not divisible by 2
- turtle.turnLeft()
- for i = 1, depth, 1 do
- if(turtle.detect() == true) then
- turtle.dig()
- turtle.forward()
- else
- turtle.forward()
- end
- end
- turtle.turnRight()
- for i = 1, width, 1 do
- if(turtle.detect() == true) then
- turtle.dig()
- turtle.forward()
- else
- turtle.forward()
- end
- end
- end
- print("Return home completed")
- listen()
- end
- function listen()
- rednet.open("left")
- while true do
- local sender, message, protocol = rednet.receive()
- if message == "ping" then
- broadcastGPS()
- end
- end
- end
- function broadcastGPS()
- rednet.open("left")
- local x,y,z = gps.locate()
- rednet.broadcast("gps: "..x.." "..y.." "..z)
- end
- DROPPED_ITEMS = {
- "minecraft:stone",
- "minecraft:dirt",
- "minecraft:cobblestone",
- "minecraft:sand",
- "minecraft:gravel"
- }
- function purgeCrap()
- for slot = 1, SLOT_COUNT, 1 do
- turtle.select(slot)
- local item = turtle.getItemDetail(slot)
- if (item ~= nil ) then
- for itemIndex = 1, #DROPPED_ITEMS, 1 do
- if(item["name"] == DROPPED_ITEMS[itemIndex]) then
- turtle.dropDown()
- print("Purging ",item["name"])
- end
- end
- end
- end
- end
- function start()
- checkFuel()
- for col = 1, depth, 1 do
- for row = 1, width, 1 do
- moveDigForward()
- print(string.format("position: column %d row %d ",col,row))
- end
- --start of each col
- checkFuel()
- purgeCrap()
- if(math.fmod(col,2) == 0) then
- turnRight()
- else
- turnLeft()
- end
- end
- returnHome()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement