Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Take and parse arguments
- local arg1, arg2, arg3, arg4 = ...
- local width = tonumber(arg1)
- local height = tonumber(arg2)
- local depth = tonumber(arg3)
- local superSecretFix = tonumber(arg4)
- -- Validate arguments
- if not (depth % 3 == 0) then
- print("- Depth should be a multiple of 3 for maximum efficiency.")
- return
- end
- -- Declare values used for mining
- local distanceMovedAlongZ = 0
- local distanceMovedAlongY = 0
- local distanceMovedAlongX = 0
- -- Plan fuel necessary for each layer
- local fuelNeededForEachLayer = width * height + (height % 2 == 0 and height or width) + 3
- -- Begin mining loop
- for z = 1, depth - 1, 3 do
- -- Check if we have enough fuel
- if turtle.getFuelLevel() < fuelNeededForEachLayer + distanceMovedAlongZ then
- -- We don't have enough fuel
- print("- Not enough fuel, trying to refuel using all fuel in own inventory...")
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- -- Fix seleection back to first slot
- turtle.select(1)
- -- Did we get anything?
- if turtle.getFuelLevel() < fuelNeededForEachLayer + distanceMovedAlongZ then
- -- We didn't
- print("- There wasn't enough fuel in the inventory to get through this layer, coming back up...")
- for i = 1, distanceMovedAlongZ do
- turtle.up()
- end
- print("- Quitting because of no fuel :(")
- return
- end
- end
- -- Check if we have enough inventory space
- local freeSlots = 0
- for i = 1, 16 do
- if turtle.getItemSpace(i) == 64 then
- freeSlots = freeSlots + 1
- end
- end
- if freeSlots < 2 then
- print("- There aren't enough free slots, coming back up to empty inventory...")
- -- Move back up and dump everything to the chest
- for i = 1, distanceMovedAlongZ do
- turtle.up()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- if not turtle.drop() then
- print("- Chest seems to be full, quitting.")
- turtle.turnRight()
- turtle.turnRight()
- return
- end
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- -- Move back down to continue with next layer
- for i = 1, distanceMovedAlongZ do
- turtle.down()
- end
- else
- print("- There are " .. freeSlots .. " item slots available still.")
- end
- -- Get into position
- turtle.digDown()
- turtle.down()
- distanceMovedAlongZ = distanceMovedAlongZ + 1
- turtle.digDown()
- turtle.down()
- distanceMovedAlongZ = distanceMovedAlongZ + 1
- turtle.digDown()
- -- Loop vertically
- for h = 1, height, 1 do
- -- At the start of each row, check if we are at the further end from the chest or not
- if h % 2 == 0 then
- -- We are horizontally far away from the initial position, so we turn left to come back towards the chest
- turtle.turnLeft()
- else
- -- We aim away from the initial position
- turtle.turnRight()
- end
- -- Loop along the width
- for w = 1, width - 1, 1 do
- -- Do a dig cycle
- while turtle.inspect() do
- turtle.dig()
- end
- turtle.forward()
- -- If we are going away from the chest we increase X distance, otherwise decrease it
- if h % 2 == 0 then
- distanceMovedAlongX = distanceMovedAlongX - 1
- else
- distanceMovedAlongX = distanceMovedAlongX + 1
- end
- turtle.digUp()
- turtle.digDown()
- end
- -- We have reached the end of the cube to mine,
- -- we can turn and move towards the new row
- if h % 2 == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- -- Check if this is the last row or not
- if not (h == height) then
- -- If there's gonna be a new row we do a dig cycle to start it
- while turtle.inspect() do
- turtle.dig()
- end
- turtle.forward()
- distanceMovedAlongY = distanceMovedAlongY + 1
- turtle.digUp()
- turtle.digDown()
- end
- end
- -- At the end of a layer, we come back to the start of the current layer
- -- Cancel all Y movement
- for i = 1, distanceMovedAlongY, 1 do
- turtle.back()
- end
- -- Cancel all X movement
- turtle.turnLeft()
- for i = 1, distanceMovedAlongX, 1 do
- turtle.forward()
- end
- turtle.turnRight()
- -- Move down one last block to get back to start of the cycle
- turtle.down()
- distanceMovedAlongZ = distanceMovedAlongZ + 1
- -- Reset distances traveled to be used in the next layer
- distanceMovedAlongX = 0
- distanceMovedAlongY = 0
- end
- -- Come back up
- for i = 1, distanceMovedAlongZ - 1 do
- turtle.up()
- end
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement