Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local length = 10 -- x
- local width = 10 -- y
- local height = 3 -- z
- local key1 = false
- local key2 = false
- local key3 = false
- local chestName = "minecraft:ender_chest"
- --"enderstorage:ender_storage"
- local slotCount = 16
- --Sets the dimensions for the Mining Area from command line arguments
- -- Default size is listed above
- function SetDimensions(...)
- local args = {...}
- if(#args == 3) then
- length = tonumber(args[1])
- width = tonumber(args[2])
- if(tonumber(args[3]) > 1) then
- height = tonumber(args[3])
- else
- print("minimum height is 2, for walkability reasons, setting height = 3")
- end
- else
- print("Malformed input given, please input using the format: 'Command' 'x' 'y' 'z' ")
- print("Defaulting to 10x10x3")
- end
- end
- SetDimensions(...)
- --Checks fuel level and refules if fuel level is less than 10
- --refuels by checking each slot for fuel
- function CheckFuel()
- if(turtle.getFuelLevel() < 10) then
- for slot = 1, slotCount do
- print("Attempting to refuel on slot " .. slot)
- turtle.select(slot)
- if(turtle.refuel(1)) then
- return true
- end
- end
- return false
- end
- return true
- end
- --Checks each inv slot for enderchest
- --returns ender chest slot number
- function GetEnderIndex()
- print("Searching for chest")
- for slot = 1, slotCount do
- local item = turtle.getItemDetail(slot)
- if(item ~= nil) then
- if(item["name"] == chestName) then
- return slot
- end
- end
- end
- return nil
- end
- --Checks if all inventory slots are full
- --if full returns true
- function InvFullCheck()
- print("Checking if Inventory Full")
- local sum = 0
- for slot = 1, slotCount do
- if(turtle.getItemCount(slot) > 0) then
- sum = sum + 1
- end
- end
- if (sum == slotCount) then
- return true
- end
- return false
- end
- --Dumps all items but coal into an enderchest its carrying
- function DumpItems()
- print("Attempting to dump items")
- turtle.select(GetEnderIndex())
- turtle.digUp()
- turtle.placeUp()
- print("Dumping Items")
- for slot = 1, slotCount do
- if(turtle.getItemDetail(slot) ~= nil) then
- local item = turtle.getItemDetail(slot)
- if(item["name"] ~= "minecraft:coal") then
- turtle.select(slot)
- turtle.dropUp()
- end
- end
- end
- turtle.digUp()
- end
- --For cases of gravel
- function DetectAndDig()
- while(turtle.detect()) do
- turtle.dig()
- end
- end
- function Forward()
- DetectAndDig()
- turtle.forward()
- end
- function OneLayer()
- Forward()
- end
- function TwoLayers()
- Forward()
- turtle.digDown()
- end
- function ThreeLayers()
- TwoLayers()
- turtle.digUp()
- end
- function Up()
- while(turtle.detectUp) do
- turtle.digUp()
- end
- turtle.up()
- end
- function turnRight()
- turtle.turnRight()
- Forward()
- turtle.turnRight()
- end
- function turnLeft()
- turtle.turnLeft()
- Forward()
- turtle.turnLeft()
- end
- --Calculates the number of Up()s taken based on the turtles position always being between
- --base and last layer of a 3 layer square, (i.e. 2, in 1-3) by checking if z index is less than layer index
- --then calculates number of times the turtle needs to go Up by comparing
- function CalculateUp(z)
- if(z < height - 2) then
- if((z + 3) == height) then
- Up()
- Up()
- elseif((z + 3) < height) then
- Up()
- Up()
- Up()
- end
- end
- end
- function SetKey(z)
- if(z == height) then
- key1 = true
- key2 = false
- key3 = false
- elseif(height - z == 1) then
- key2 = true
- key1 = false
- key3 = false
- else
- key3 = true
- key1 = false
- key2 = false
- end
- end
- function TurnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- --Checks to see if has ender chest and coal
- function ReadyForJourney()
- return true
- end
- --------------Main----------------------
- function Main()
- if (not ReadyForJourney()) then
- print("Your turtle isnt ready to journey out!")
- print("Make sure your turtle has enough fuel and an enderchest!")
- return
- end
- for z = 1, height, 3 do --
- SetKey(z)
- for y = 1, width do --starting length cuts one turn off
- for x = 1, length - 1 do --width cuts one length down off the next
- if(not CheckFuel()) then
- print("Your turtle is out of fuel!")
- print("Powering down....")
- return
- end
- if(InvFullCheck == true) then
- DumpItems()
- end
- if(key1)then
- OneLayer()
- elseif(key2)then
- TwoLayers()
- elseif(key3)then
- ThreeLayers()
- end
- --run some function with some local variable as a param, that gets changed every z changed
- --based on the number the function will run the right, function of mine one two or three layers
- --somehow WITHOUT doing checks (because if it does checks, its redundancy)
- end
- if(y ~= 3) then
- if(math.fmod(y, 2) == 0) then
- turnLeft()
- else
- turnRight()
- end
- else
- TurnAround()
- end
- end
- CalculateUp(z)
- end
- end
- Main()
Add Comment
Please, Sign In to add comment