Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Quarry programm for a turtle.
- Features:
- - finds adjacent chest
- - checks refuel and makes its way back to the chest if out of fuel
- - empties its inventory to chest
- - some minor intelligence stuff
- Note:
- - the first argument you pass will determine the start height of the quarry
- Copyright Thorsten Schmiedel 2014
- Do NOT post this without noticing me! (schmiedel.thorsten@gmail.com)
- --]]
- -- Variables and constants
- -- Constants
- local FuelSlot = 1
- local ChestSlot = 2
- -- Variables
- local tArgs = { ... }
- local startHeightDiff = 0
- local sizeXZ = 16
- local debug = true
- local dX, dY, dZ;
- -- Arguments
- if (#tArgs >= 1) then
- startHeightDiff = tonumber(tArgs[1])
- if (#tArgs >= 2) then
- sizeXZ = tonumber(tArgs[2])
- end
- end
- -- end Arguments
- -- FUNCTIONS
- -- HELPER FUNCTIONS
- local function ForceMoveDown()
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- sleep(0.2)
- end
- end
- local function ForceMoveUp()
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- sleep(0.2)
- end
- end
- local function CheckFuel()
- local lengthOfWay = startHeightDiff + dX + dY + dZ
- if (lengthOfWay <= turtle.getFuelLevel()) then
- return false
- else
- return true
- end
- end
- -- Finds a chest adjacent to the turtle
- local function FindChest()
- for i = 1, 4 do
- if turtle.detect() then
- if debug then
- print("Chest found!")
- end
- return
- else
- turtle.turnRight()
- end
- end
- if debug then
- print("No adjacent chest found! New attempt in 3 secs")
- end
- return
- end
- -- Pick up the chest
- local function PickUp(slot)
- local tmp = turtle.getSelectedSlot()
- turtle.select(slot)
- if not turtle.dig() and debug then
- print("Error in picking up the chest! Aborting programm!")
- end
- turtle.select(tmp)
- end
- -- Dig to the begin of the quarry
- local function GoToStartHeight()
- if (startHeightDiff == 0) then
- if debug then
- print("Reached startheight! Mining begins...")
- end
- return
- end
- for i = 1, startHeightDiff do
- ForceMoveDown()
- end
- if debug then
- print("Reached startheight! Mining begins...")
- end
- end
- -- Go back to the chest
- local function GoUpToChest()
- if (startHeightDiff == 0) then
- if debug then
- print("Reached chest! Inventory empty begins...")
- end
- return
- end
- for i = 1, startHeightDiff do
- ForceMoveUp()
- end
- if debug then
- print("Reached chest! Inventory empty begins...")
- end
- end
- -- Mines one column
- local function MineColumn(amount)
- end
- FindChest()
- GoToStartHeight()
- GoUpToChest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement