Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ********************************************************************
- -- ** Prep for Quarry - Turtle (Tekkit/Minecraft) by SirDimples **
- -- ** ComputerCraft 1.58 **
- -- ** **
- -- ** Features: **
- -- ** - TODO **
- -- ** **
- -- ** Usage: **
- -- ** PrepQuarry width length startheight **
- -- ** **
- -- ** Versions/Changelog: **
- -- ** [0.0] First submit **
- -- ** **
- -- ** Warning: script is work in progress **
- -- ********************************************************************
- local fuelLevelToRefuelAt = 5
- local currentlySelectedSlot = 0 -- The slot that the last noise block was found in
- local fuelLevelToRefuelAt = 5
- local refuelItemsToUseWhenRefuelling = 63
- local emergencyFuelToRetain = 0
- local maximumGravelStackSupported = 25
- local returningToStart = false
- -- Enum: Direction
- direction = { FORWARD=0, RIGHT=1, BACK=2, LEFT=3, UP=4, DOWN=5 }
- -- Enum: State
- state = { START=0, EMPTYINVENTORY=1 }
- -- Location information
- local currX
- local currY
- local currZ
- local currOrient
- local currState = state.START
- -- Turtle information
- local isWirelessTurtle
- local startHeight -- Represents the height (y co-ord) that the turtle started at
- local quarryWidth -- Represents the length of the mines that the turtle will dig
- local quarryLength -- (Optional) the length if it's not the same as width
- messageLevel = { DEBUG=0, INFO=1, WARNING=2, ERROR=3, FATAL=4 }
- local messageOutputLevel = messageLevel.INFO
- function writeMessage(message, msgLevel)
- if (msgLevel >= messageOutputLevel) then
- print(message)
- -- If this turtle has a modem, then write the message to red net
- if (isWirelessTurtle == true) then
- if (turtleId == nil) then
- rednet.broadcast(message)
- else
- -- Broadcast the message (prefixed with the turtle's id)
- rednet.broadcast("[".. turtleId.."] "..message)
- end
- end
- end
- end
- function ensureFuel()
- -- Determine whether a refuel is required
- local fuelLevel = turtle.getFuelLevel()
- if (fuelLevel ~= "unlimited") then
- if (fuelLevel < fuelLevelToRefuelAt) then
- -- Need to refuel
- turtle.select(16)
- currentlySelectedSlot = 16
- local fuelItems = turtle.getItemCount(16)
- -- Do we need to impact the emergency fuel to continue? (always
- -- keep one fuel item in slot 16)
- if (fuelItems == 0) then
- writeMessage("Completely out of fuel!", messageLevel.FATAL)
- elseif (fuelItems == 1) then
- writeMessage("Out of Fuel!", messageLevel.ERROR)
- turtle.refuel()
- elseif (fuelItems <= (emergencyFuelToRetain + 1)) then
- writeMessage("Consuming emergency fuel supply. "..(fuelItems - 2).." emergency fuel items remain", messageLevel.WARNING)
- turtle.refuel(1)
- else
- -- Refuel the lesser of the refuelItemsToUseWhenRefuelling and the number of items more than
- -- the emergency fuel level
- if (fuelItems - (emergencyFuelToRetain + 1) < refuelItemsToUseWhenRefuelling) then
- turtle.refuel(fuelItems - (emergencyFuelToRetain + 1))
- else
- turtle.refuel(refuelItemsToUseWhenRefuelling)
- end
- end
- end
- end
- end
- function ensureInventorySpace()
- -- If already returning to start, then don't need to do anything
- if (returningToStart == false) then
- -- If the last inventory slot is full, then need to return to the start and empty
- if (turtle.getItemCount(lastEmptySlot) > 0) then
- -- Return to the starting point and empty the inventory, then go back to mining
- returnToStartAndUnload(true)
- end
- end
- end
- function returnToStartAndUnload(returnBackToMiningPoint)
- writeMessage("returnToStartAndUnload called", messageLevel.DEBUG)
- returningToStart = true
- local storedX, storedY, storedZ, storedOrient
- local prevMiningState = currMiningState
- storedX = currX
- storedY = currY
- storedZ = currZ
- storedOrient = currOrient
- -- Store the current location and orientation so that it can be returned to
- currState = state.EMPTYINVENTORY
- writeMessage("last item count = "..turtle.getItemCount(lastEmptySlot), messageLevel.DEBUG)
- end
- function prepQuarry()
- -- Dig 4 high rectangular tunnel
- writeMessage("Prep Quarry placeholder, quarry dimensions: "..quarryWidth.."x"..quarryLength, messageLevel.INFO)
- end
- -- Process the input arguments - storing them to global variables
- local args = { ... }
- local paramsOK = true
- -- Detect whether this is a wireless turtle, and if so, open the modem
- local peripheralConnected = peripheral.getType("right")
- if (peripheralConnected == "modem") then
- isWirelessTurtle = true
- end
- -- If a wireless turtle, open the modem
- if (isWirelessTurtle == true) then
- turtleId = os.getComputerLabel()
- rednet.open("right")
- end
- if (#args == 0) then
- -- TODO Resume support
- elseif (#args == 1) then
- quarryWidth = tonumber(args[1])
- quarryLength = quarryWidth
- local x, y, z = gps.locate(5)
- startHeight = y
- if (startHeight == nil) then
- writeMessage("Can't locate GPS", messageLevel.FATAL)
- paramsOK = false
- end
- elseif (#args == 2) then
- if (args[2] == "/r") then
- quarryWidth = tonumber(args[1])
- quarryLength = tonumber(args[2])
- else
- quarryWidth = tonumber(args[1])
- quarryLength = tonumber(args[2])
- startHeight = tonumber(args[3])
- end
- elseif (#args == 3) then
- if(args[3] == "/r") then
- quarryWidth = tonumber(args[1])
- quarryLength = tonumber(agrs[2])
- else
- quarryWidth = tonumber(args[1])
- quarryLength = tonumber(args[2])
- startHeight = tonumber(args[3])
- end
- end
- if (paramsOK == false) then
- writeMessage("Usage: "..shell.getRunningProgram().." <diameter> [turtleY] [/r]", messageLevel.FATAL)
- paramsOK = false
- end
- if (paramsOK == true) then
- if ((startHeight < 6) or (startHeight > 128)) then
- writeMessage("turtleY must be between 6 and 128", messageLevel.FATAL)
- paramsOK = false
- end
- if ((quarryWidth < 2) or (quarryWidth > 64)) then
- writeMessage("diameter must be between 2 and 64", messageLevel.FATAL)
- paramsOK = false
- end
- writeMessage("----------------", messageLevel.INFO)
- writeMessage("** QuarryPrep **", messageLevel.INFO)
- writeMessage("----------------", messageLevel.INFO)
- -- Set the turtle's starting position
- currX = 0
- currY = startHeight
- currZ = 0
- currOrient = direction.FORWARD
- -- Create a Quarry
- turtle.select(1)
- currentlySelectedSlot = 1
- prepQuarry()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement