Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local maxX,maxY = ...
- maxX= tonumber(maxX)
- maxY= tonumber(maxY)
- f=fs.open("log","a")
- f.writeLine("--------------------")
- f.write("maxX= ")
- f.write(maxX)
- f.write(" maxY= ")
- f.writeLine(maxY)
- noCoal=false
- refuel=function()
- success=false
- c=1
- while not success and c<16 do
- turtle.select(1)
- success=turtle.refuel()
- end
- return success
- end
- clearInventory = function()
- for c=1, 16 do
- turtle.select(c)
- item=turtle.getItemDetail()
- if item then
- if not check(item.name) then
- turtle.drop()
- end
- end
- end
- end
- check=function (item)
- if item=="minecraft:chest" or item:match "minecraft:.*stone.*" or item:match "minecraft:dirt.*" or item=="minecraft:gravel" or item:match "chisel:.*" or item=="minecraft:torch" then
- return false
- else
- return true
- end
- end
- find = function ()
- local success, item=turtle.inspectUp()
- if success then
- if check(item.name) then
- turtle.select(1)
- turtle.digUp()
- f.write("Found up: ")
- f.writeLine(item.name)
- end
- end
- success, item=turtle.inspectDown()
- if success then
- if check(item.name) then
- turtle.select(1)
- turtle.digDown()
- f.write("Found down: ")
- f.writeLine(item.name)
- end
- end
- turtle.turnLeft()
- success, item=turtle.inspect()
- if success then
- if check(item.name) then
- turtle.select(1)
- turtle.dig()
- f.write("Found left: ")
- f.writeLine(item.name)
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- success, item=turtle.inspect()
- if success then
- if check(item.name) then
- turtle.select(1)
- turtle.dig()
- f.write("Found right: ")
- f.writeLine(item.name)
- end
- end
- turtle.turnLeft()
- success, item=turtle.inspect()
- if success then
- if check(item.name) then
- turtle.select(1)
- turtle.dig()
- f.write("Found forward: ")
- f.writeLine(item.name)
- end
- end
- end
- local x=0
- local y=0
- local state = "up"
- while x<maxX do --a
- for y=0, maxY do --b
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel<= (x+y) then --c
- local fuelFound=false
- local currSelected=1
- repeat
- turtle.select(currSelected)
- fuelFound = turtle.refuel()
- currSelected = currSelected+1
- until fuelFound == true or currSelected>16
- if fuelFound==false then
- f.writeLine("Fuel not found")
- end
- end --c
- local nCoal=0
- freeSlots = 0
- for c=1,16 do --d
- local item=turtle.getItemDetail(c)
- if item then
- if item.name=="minecraft:coal" then
- nCoal = nCoal+item.count
- end
- if not check(item.name) then
- turtle.select(c)
- turtle.drop()
- freeSlots=freeSlots+1
- end
- else
- freeSlots=freeSlots+1
- end
- end --
- nCoal = nCoal*80+turtle.getFuelLevel()-4
- local dist=x+y
- noCoal=true
- if nCoal<=dist then
- f.write("Not enough coal for the journey, returning home (left:")
- f.write(nCoal)
- f.write(", coord(")
- f.write(x)
- f.write(",")
- f.write(y)
- f.writeLine("))")
- end
- stopx=x
- stopy=y
- if freeSlots <=1 then f.writeLine("Not enough slots, returning home") end
- if state=="up" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- while y>0 do
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- clearInventory()
- if turtle.getFuelLevel()<2 then refuel() end
- turtle.forward()
- y=y-1
- end
- turtle.turnRight()
- while x>0 do
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- clearInventory()
- if turtle.getFuelLevel()<2 then refuel() end
- turtle.forward()
- x=x-1
- end
- success,storage=turtle.inspect()
- if success and storage.name=="minecraft:chest" then
- for c=1,16 do
- turtle.select(c)
- item=turtle.getItemDetail()
- if item and not item.name=="minecraft:coal" then
- dropSuccess=turtle.drop()
- if dropSuccess then
- f.write(item.name)
- f.writeLine(" dropped in chest")
- else
- f.writeLine("Chest full!! Shutting down...")
- f.close()
- os.shutdown()
- end
- end
- end
- if noCoal then success=turtle.suckUp()
- if not success then
- f.writeLine("no coal chest or coal, shutting down...")
- f.close()
- os.shutdown()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- while x<stopx do
- find()
- if turtle.getFuelLevel()<2 then refuel() end
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- clearInventory()
- turtle.forward()
- x=x+1
- end
- turtle.turnLeft()
- while y<stopy do
- find()
- if turtle.getFuelLevel()<2 then refuel() end
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- clearInventory()
- turtle.forward()
- y=y+1
- end
- if state==down then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- else
- f.writeLine("No chest, shutting down...")
- os.shutdown()
- end
- find()
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- turtle.forward()
- end
- f.write("Ended x ")
- f.writeLine(x)
- if state=="up" then
- turtle.turnRight()
- else turtle.turnLeft()
- end
- for i=1, 3 do
- find()
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- turtle.forward()
- x=x+1
- end
- if state=="up" then
- turtle.turnRight()
- state="down"
- else
- turtle.turnLeft()
- state="up"
- end
- end --a
- f.writeLine("Returning home")
- if state=="up" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- while y>0 do
- find()
- if turtle.getFuelLevel()<2 then refuel() end
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- turtle.forward()
- y=y-1
- clearInventory()
- end
- turtle.turnRight()
- while x>0 do
- if turtle.getFuelLevel()<2 then refuel() end
- find()
- while turtle.detect() do
- turtle.select(1)
- turtle.dig()
- end
- turtle.forward()
- x=x-1
- clearInventory()
- end
- f.writeLine("Arrived! Shutting down...")
- f.close()
- os.shutdown()
Add Comment
Please, Sign In to add comment