Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Move Bot
- function moveToLocation()
- newX = botCoords["x"] - newCoords["x"]
- newY = botCoords["y"] - newCoords["y"]
- newZ = botCoords["z"] - newCoords["z"]
- if newX > 0 then
- iWantToFace = 3
- else if newX < 0 then
- iWantToFace = 1
- end
- if newY > 0 then
- iWantToFace = 0
- else if newY < 0 then
- iWantToFace = 2
- end
- if newZ > 0 then
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- botCoords["z"] = botCoords["z"] - 1
- else if newZ < 0 then
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- botCoords["z"] = botCoords["z"] + 1
- end
- if facing == iWantToFace then
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- if facing == 0 then
- botCoords["y"] = botCoords["y"] - 1
- elseif facing == 1 then
- botCoords["x"] = botCoords["x"] + 1
- elseif facing == 2 then
- botCoords["y"] = botCoords["y"] + 1
- elseif facing == 3 then
- botCoords["x"] = botCoords["x"] - 1
- end
- else
- turtle.turnRight()
- facing = facing + 1
- if facing > 3 then
- faceing = facing - 4
- end
- end
- end
- function canDig()
- hardParimeter = 10
- if botCoords["x"] + hardParimeter > nextCoords["x"] and botCoords["x"] - hardParimeter < nextCoords["x"] and botCoords["y"] +
- hardParimeter > nextCoords["y"] and botCoords["y"] - hardParimeter < nextCoords["y"] and botCoords["z"] +
- hardParimeter > nextCoords["z"] and botCoords["z"] - hardParimeter < nextCoords["z"] then
- return false
- else
- return true
- end
- end
- --Main Program
- botCoords = {}
- homeCoords = {}
- chestCoords = {}
- facing = 0
- iWantToFace = 0
- pathBack = {}
- print("Gathering Coordinates")
- file = fs.open("Locations", "r")
- file.readLine()
- x = tonumber(file.readLine())
- botCoords["x"] = x
- homeCoords["x"] = x
- y = tonumber(file.readLine())
- botCoords["y"] = y
- homeCoords["y"] = y
- z = tonumber(file.readLine())
- botCoords["z"] = z
- homeCoords["z"] = z
- file.readLine()
- chestCoords["x"] = tonumber(file.readLine())
- chestCoords["y"] = tonumber(file.readLine())
- chestCoords["z"] = tonumber(file.readLine())
- goBackAt = 0
- isGoingBack = true
- needCoords = false
- while true do
- if turtle.getFuelLevel() == 0 and turtle.getItemCount(16) > 0 then
- goBackAt = (turtle.getItemCount(16) * 80) / 2
- turtle.select(16)
- turtle.refuel(turtle.getItemCount(16))
- print("YUM")
- print(turtle.getFuelLevel())
- elseif turtle.getFuelLevel() == 0 then
- print("Sleepy Time")
- os.sleep(60)
- elseif turtle.getFuelLevel() <= goBackAt or isGoingBack then
- isGoingBack = true
- newCoords["x"] = chestCoords["x"]
- newCoords["y"] = chestCoords["y"]
- newCoords["z"] = chestCoords["z"]
- if turtle.detect() then
- data = turtle.inspect()
- if data.name == "Minecraft:Chest" then
- chest = peripheral.isPresent("front")
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- for slot, item in pairs(chest.getAllStacks()) do
- if item.id == "Minecraft:Coal" then
- chest.pushItem("south", slot)
- break
- end
- end
- goBackAt = (turtle.getItemCount(16) * 80) / 2
- turtle.select(16)
- turtle.refuel(turtle.getItemCount(16))
- isGoingBack = false
- needCoords = true
- end
- end
- elseif needCoords then
- newCoords["x"] = math.floor(math.random() * goBackAt)
- newCoords["y"] = math.floor(math.random() * goBackAt)
- newCoords["z"] = math.floor(math.random() * goBackAt)
- needCoords = false
- end
- if not needCoords then
- moveToLocation()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement