Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get q5s1y8aH
- -- pastebin run q5s1y8aH
- print("Min X")
- local minX = tonumber(read())
- print("Min Y")
- local minY = tonumber(read())
- print("Min Z")
- local minZ = tonumber(read())
- print("Max X")
- local maxX = tonumber(read())
- print("Max Y")
- local maxY = tonumber(read())
- print("Max Z")
- local maxZ = tonumber(read())
- local pickSlot = 13
- local modemSlot = 14
- local chestSlot = 16
- local pickName = "minecraft:diamond_pickaxe"
- local modemName = "computercraft:wireless_modem_advanced"
- local minFuel = turtle.getFuelLimit() * 0.25
- local maxFuel = turtle.getFuelLimit() * 0.75
- local validFuels = {
- ["minecraft:coal_block"] = true,
- ["minecraft:coal"] = true,
- ["minecraft:charcoal"] = true,
- ["minecraft:blaze_rod"] = true
- }
- sleep(1)--might need to increase to prevent server crash
- function Hold(s)
- if turtle.getItemCount(s) == 1 then
- turtle.select(s)
- turtle.equipLeft()
- local i = turtle.getItemDetail()
- if i ~= nil then
- if i.name == pickName then
- turtle.transferTo(pickSlot)
- elseif i.name == geoName then
- turtle.transferTo(geoSlot)
- elseif i.name == modemName then
- turtle.transferTo(modemSlot)
- else
- turtle.transferTo(1)
- end
- end
- turtle.select(1)
- end
- end
- local facing = "unknown"
- local pos = "unknown"
- function Forward()
- while turtle.forward() == false do
- turtle.dig()
- end
- if facing == "south" then
- pos["z"] = pos["z"] + 1
- elseif facing == "north" then
- pos["z"] = pos["z"] - 1
- elseif facing == "east" then
- pos["x"] = pos["x"] + 1
- elseif facing == "west" then
- pos["x"] = pos["x"] - 1
- end
- print("Pos: " .. tostring(pos["x"]) .. ", " .. tostring(pos["y"]) .. ", " .. tostring(pos["z"]))
- end
- function Up()
- while turtle.up() == false do
- turtle.digUp()
- end
- pos["y"] = pos["y"] + 1
- print("Pos: " .. tostring(pos["x"]) .. ", " .. tostring(pos["y"]) .. ", " .. tostring(pos["z"]))
- end
- function Down()
- while turtle.down() == false do
- turtle.digDown()
- end
- pos["y"] = pos["y"] - 1
- print("Pos: " .. tostring(pos["x"]) .. ", " .. tostring(pos["y"]) .. ", " .. tostring(pos["z"]))
- end
- function Dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- function DigUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function DigDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- function GetIndex(v, t)
- for tk, tv in pairs(t) do
- if tv == v then
- return tk
- end
- end
- end
- local dirs = {
- [1] = "north",
- [2] = "east",
- [3] = "south",
- [4] = "west"
- }
- function Left()
- turtle.turnLeft()
- local cd = GetIndex(facing, dirs)
- nd = cd - 1
- if nd == 0 then
- nd = 4
- end
- print("Facing " .. dirs[nd])
- facing = dirs[nd]
- end
- function Right()
- turtle.turnRight()
- local cd = GetIndex(facing, dirs)
- nd = cd + 1
- if nd == 5 then
- nd = 1
- end
- print("Facing " .. dirs[nd])
- facing = dirs[nd]
- end
- function Face(nd)
- local cd = GetIndex(facing, dirs)
- local td = GetIndex(nd, dirs)
- print("Currently facing: " .. facing .. " " .. tostring(cd))
- print("Target facing: " .. nd .. " " .. tostring(td))
- facing = nd
- if cd == td then
- print("Already facing " .. nd)
- return
- end
- if cd == 1 and td == 4 then
- turtle.turnLeft()
- print("Facing " .. nd)
- return
- end
- if cd == 4 and td == 1 then
- turtle.turnRight()
- print("Facing " .. nd)
- return
- end
- if cd < td then
- for i = cd, td - 1 do
- turtle.turnRight()
- end
- end
- if cd > td then
- for i = cd, td + 1, -1 do
- turtle.turnLeft()
- end
- end
- print("Facing " .. nd)
- end
- function Inv()
- Hold(pickSlot)
- DigUp()
- turtle.select(16)
- while turtle.placeUp() == false do
- DigUp()
- turtle.attackUp()
- end
- local c = peripheral.wrap("top")
- while turtle.getItemCount(6) > 0 or turtle.getItemCount(1) > 0 do
- for i = 1, 12 do
- turtle.select(i)
- turtle.dropUp(64)
- end
- end
- if turtle.getFuelLevel() < minFuel then
- local fuelAttempts = 0
- turtle.select(1)
- while turtle.getFuelLevel() < maxFuel do
- local cl = c.list()
- print(cl[1].name)
- if cl[1] ~= nil and validFuels[cl[1].name] then
- turtle.suckUp(cl[1].count - 1)
- turtle.refuel(64)
- else
- print("Waiting for fuel")
- end
- sleep(1)
- fuelAttempts = fuelAttempts + 1
- if fuelAttempts > 10 and turtle.getFuelLevel() > minFuel then
- print("Will try get more fuel later")
- break
- end
- end
- end
- turtle.select(16)
- Hold(pickSlot)
- turtle.digUp()
- turtle.select(1)
- end
- function GetDir()
- Hold(modemSlot)
- local sx, sy, sz = gps.locate()
- while sx == nil do
- print("Coudn't get GPS")
- sleep(3)
- sx, sy, sz = gps.locate()
- end
- Hold(pickSlot)
- Forward()
- Hold(modemSlot)
- local nx, ny, nz = gps.locate()
- while nx == nil do
- print("Coudn't get GPS")
- sleep(3)
- nx, ny, nz = gps.locate()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- Hold(pickSlot)
- Forward()
- turtle.turnLeft()
- turtle.turnLeft()
- if nz > sz then
- facing = "south"
- elseif nz < sz then
- facing = "north"
- elseif nx > sx then
- facing = "east"
- elseif nx < sx then
- facing = "west"
- end
- print("Facing: " .. facing)
- end
- function GetPos()
- Hold(modemSlot)
- local cx, cy, cz = gps.locate()
- pos = {}
- pos["x"] = cx
- pos["y"] = cy
- pos["z"] = cz
- print("Pos: " .. tostring(cx) .. ", " .. tostring(cy) .. ", " .. tostring(cz))
- end
- ---
- if turtle.getItemCount(16) == 0 then
- Hold(pickSlot)
- turtle.select(16)
- turtle.digUp()
- end
- Inv()
- GetPos()
- GetDir()
- function GotoRel(rx, ry, rz)
- print("Going to rel: " .. tostring(rx) .. ", " .. tostring(ry) .. ", " .. tostring(rz))
- Hold(pickSlot)
- if ry >= 0 then
- for i = 1, ry do
- Up()
- end
- else
- for i = -1, ry, -1 do
- Down()
- end
- end
- if rx > 0 then
- dir = Face("east")
- for i = 1, rx do
- Forward()
- end
- elseif rx < 0 then
- dir = Face("west")
- for i = -1, rx, -1 do
- Forward()
- end
- end
- if rz > 0 then
- dir = Face("south")
- for i = 1, rz do
- Forward()
- end
- elseif rz < 0 then
- dir = Face("north")
- for i = -1, rz, -1 do
- Forward()
- end
- end
- end
- function Goto(x, y, z)
- print("Going to: " .. tostring(x) .. ", " .. tostring(y) .. ", " .. tostring(z))
- GotoRel(x - pos["x"], y - pos["y"], z - pos["z"])
- end
- function CheckSelf()
- Hold(pickSlot)
- if turtle.getItemCount(6) > 0 or turtle.getFuelLevel() < minFuel then
- Inv()
- end
- turtle.select(1)
- end
- --[[
- for x = minX, maxX do
- for y = minY, maxY do
- CheckSelf()
- for z = minZ, maxZ do
- Goto(x, y, z)
- end
- end
- end
- ]]--
- for y = maxY, minY, -1 do
- for x = minX, maxX, 2 do
- CheckSelf()
- for z = minZ, maxZ do
- Goto(x, y, z)
- end
- CheckSelf()
- if x + 1 <= maxX then
- for z = maxZ, minZ, -1 do
- Goto(x + 1, y, z)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment