Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local cp = require("component")
- local navi = cp.navigation
- local inv = cp.inventory_controller
- --require specific used libraries
- local chest_pos = navi.getFacing() - 2
- if(chest_pos < 1) then
- chest_pos = chest_pos + 4
- end
- --save charger and chest position
- --charger is on the left of the robot and chest is behind the robot
- local waypoint = navi.findWaypoints(64)
- local relX = waypoint[1]["position"][1]
- local relZ = waypoint[1]["position"][3]
- --save ending position, Y is not needed
- local area = (math.abs(relX) + 1) * (math.abs(relZ) + 1)
- --calculate total columns
- mined = 0
- charge_time = 0
- --global varibles for mined columns and drill charge time
- local function path_finding(m)
- local length = 0
- if(chest_pos % 2 == 1) then
- length = math.abs(relZ) + 1
- --facing z
- else
- length = math.abs(relX) + 1
- --facing x
- end
- local forwards = mined % length
- local rights = math.floor(mined / length)
- --calculate needed moves
- if(m == 0) then
- --return mode
- robot.turnRight()
- local i = 0
- while(i < forwards) do
- robot.forward()
- i = i + 1
- end
- i = 0
- robot.turnRight()
- while(i < rights) do
- robot.forward()
- i = i + 1
- end
- else
- --travel mode
- local i = 0
- while(i < forwards) do
- robot.forward()
- i = i + 1
- end
- i = 0
- robot.turnRight()
- while(i < rights) do
- robot.forward()
- i = i + 1
- end
- end
- end
- local function dump()
- robot.turnLeft()
- for i=1,16 do
- robot.select(i)
- robot.drop(64)
- end
- robot.turnRight()
- robot.select(1)
- inv.equip()
- robot.drop()
- os.sleep(charge_time)
- robot.suck()
- inv.equip()
- robot.turnRight()
- end
- --dump robot inventory
- local function excavate()
- while (mined < area) do
- path_finding(1)
- local relY = 0
- while 1 do
- robot.swingDown()
- os.sleep(1)
- if(robot.detectDown()) then
- break
- else
- robot.down()
- relY = relY + 1
- end
- end
- charge_time = math.ceil(relY / 10)
- while(relY > 0) do
- robot.up()
- relY = relY - 1
- end
- path_finding(0)
- dump()
- mined = mined + 1
- end
- end
- excavate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement