Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Create a circular platform
- --declare global variables that are relevant to platform
- R_hole = 50 --outer radius of the platform
- numStripes = 16 --number of stripes as it goes out.
- swirlFactor = 1 --control degree of swirl
- --declare the global variables
- theta = 0 --sweep of the spiral
- step = 0.001 --change in theta each step
- b = 0.14 --growth factor for spiral
- theta = theta / b
- --Now get the turtle identifier
- R_max = 15 --Outermost radius of the tower
- R_base = 6 --The radius at the base. Also the radius of the stairs all the way up.
- R_decay = 5000 --Half-life of the tower width
- Floor_Spacing = 6 --put a floor in every this many blocks
- lavaSum = 200 --sum of the YY locations for finding lava
- lavaCount = 0 --number of lava blocks collected
- cobbleCountMax = 1600 --give up if you check this many columns and they're all already done
- firstEmptyChest = 1
- Chest_Level = 5 --elevation of the chests
- top_column_height = 12 --don't start pinching in the radius until this far
- killMode = 0 --set to 1 to hunt and capture other turtles.
- fuelStop = 0 --stop when the tank is full
- if term.isColor() then
- maxFuel = 99000 --this is an advanced turtle
- else
- maxFuel = 19000 --this is a normal turtle
- end
- StartX = 0
- StartY = 20
- StartZ = 14
- curX = 0 --current X position relative to the start
- curY = 0 --current Y position relative to the start
- curZ = 0 --current Z position relative to the start
- facing = 0 --what direction is the turtle facing (0,1,2,3)
- --0 is toward positive Z
- waterLevel = -1000 --the highest location that water has been found
- function fuel(direction)
- --called periodically, and also when lava is detected.
- turtle.select(1)
- --Now let's pickup the lava
- if string.find(direction, "f") then
- --its in front
- turtle.place()
- elseif string.find(direction, "d") then
- turtle.placeDown()
- lavaSum = lavaSum + curY
- lavaCount = lavaCount + 1
- elseif string.find(direction, "u") then
- turtle.placeUp()
- lavaSum = lavaSum + curY
- lavaCount = lavaCount + 1
- end
- if turtle.getFuelLevel() < maxFuel then
- for slot = 4,16,1 do
- turtle.select(slot)
- turtle.refuel()
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- if turtle.getFuelLevel() > maxFuel then
- break
- end
- end
- if curY >=0 and turtle.getFuelLevel() < 1000 then
- local oldY = curY
- for i=1,4,1 do
- if not turtle.detectUp() then Up() end
- end
- repeat
- --Time to refuel
- for slot = 4,16,1 do
- turtle.select(slot)
- turtle.refuel()
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- end
- until (turtle.getFuelLevel() > 1000) --don't stop trying if the level is too low
- end
- else
- --fuel has been called, but the tank is full
- if turtle.getItemCount(1) == 1 or turtle.getItemCount(16) > 0 then
- --We're either out of buckets or out of space
- dumpLava()
- end
- end
- turtle.select(1)
- report("refueled")
- end
- function dumpLava()
- --return to the repository to get rid of excess lava
- local XX = curX
- local YY = curY
- local ZZ = curZ
- oldfacing = facing
- MoveTo(curX,1+turtID,curZ)
- MoveTo(0,1+turtID,0)
- lavaFuel()
- MoveTo(0,1+turtID,0)
- MoveTo(XX,1+turtID,ZZ)
- MoveTo(XX,-2,ZZ)
- setCobble("u")
- MoveTo(XX,YY,ZZ)
- TurnTo(oldfacing)
- end
- function lavaFuel()
- --refuel from onboard lava buckets.
- --if fuel is full, then dump excess in lava repository below (0,0,0)
- if turtle.getFuelLevel() < maxFuel then
- for slot = 4,16,1 do
- turtle.select(slot)
- turtle.refuel()
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- if turtle.getFuelLevel() > maxFuel then
- break
- end
- end
- end
- lava = 0
- for slot = 4,16,1 do
- local data = turtle.getItemDetail(slot)
- if data and string.find(data.name,"lava") then
- lava = lava + 1
- end
- end
- while lava > 0 or turtle.getFuelLevel() < 2000 do
- --either we have excess fuel or level is too low.
- --time to go to the repository
- print("Going to repository I have ", lava , "buckets.")
- MoveTo(curX,turtID+1,curZ)
- MoveTo(0,turtID+1,0)
- MoveTo(0,0,0)
- local success, data = turtle.inspectDown()
- local success_f, data_f = turtle.inspect()
- if success and string.find(data.name,"trap") then
- os.exit()
- end
- while not success or
- not ( (success and string.find(data.name,"bedrock") )
- or
- (success and string.find(data.name, "lava") and data.state.level == 0 )
- or
- (success_f and string.find(data_f.name, "lava") and data.state.level == 0 )
- or
- (success and string.find(data.name, "trapdoor") )
- ) do
- Down()
- if (success and string.find(data.name, "trapdoor") ) then
- while (success and string.find(data.name, "trapdoor")) do
- sleep(120)
- success, data = turtle.inspectDown()
- end
- end
- success, data = turtle.inspectDown()
- end
- --We're now either over lava or over bedrock
- print("At lava level")
- if turtle.getFuelLevel() < 2000 then
- --we're here to pick up lava
- done = 0
- while done==0 do
- for i=0,3,1 do
- fuel("f")
- TRight()
- end
- fuel("d")
- Down()
- if turtle.getFuelLevel() > 15000 or turtle.detectDown() then
- done = 1
- end
- end
- else
- --we're here to deposit
- print("Depositing")
- local done = 0
- local dir = 0
- while done == 0 do
- done = 1
- for s = 4,16,1 do
- data = turtle.getItemDetail(s)
- if data and string.find(data.name,"lava") then
- turtle.select(s)
- if dir < 4 then
- TurnTo(dir)
- if turtle.place() then
- turtle.transferTo(1)
- end
- else
- --we've already gone in all directions.
- Up()
- if turtle.placeDown() then
- turtle.transferTo(1)
- end
- dir = -1
- end
- done = 0
- dir = dir + 1
- end
- end
- end
- end
- if curY > -4 then
- --we've filled the repository
- MoveTo(0,1+turtID,1)
- os.exit()
- end
- MoveTo(0,1+turtID,0)
- if turtle.getFuelLevel() < 2000 then
- MoveTo(0,turtID+1,1) --park position
- sleep(120)
- fuel("n")
- end
- MoveTo(0,1+turtID,0)
- lava = 0
- for slot = 4,16,1 do
- local data = turtle.getItemDetail(slot)
- if data and string.find(data.name,"lava") then
- lava = lava + 1
- end
- end
- end
- end
- function Init()
- --called when I want the turtle to set up the chests for me
- turtle.select(4) -- slot to put a stack of chests
- local row = 0
- while turtle.getItemCount(4) > 0 or turtle.getItemCount(5) > 0 do
- MoveTo(row,5,1)
- TurnTo(0)
- for x=1,10,1 do
- turtle.placeUp()
- if turtle.getItemCount(4) == 0 then
- turtle.select(5)
- end
- Forward()
- end
- row = row+1
- end
- MoveTo(0,0,0)
- end
- function SlotItems(slot)
- turtle.select(slot)
- if turtle.getItemCount() == 0 then
- return "nothing"
- else
- local data = turtle.getItemDetail()
- return data.name
- end
- end
- function TRight()
- --Turn the turtle to the right
- turtle.turnRight()
- facing = facing +1
- if facing > 3 then
- facing = facing - 4
- end
- end
- function TLeft()
- --Turn the turtle to the right
- turtle.turnLeft()
- facing = facing - 1
- if facing < 0 then
- facing = facing + 4
- end
- end
- function Forward()
- local success, data = turtle.inspect()
- if success then
- local count = 0
- if string.find(data.name, "urtle") and killMode == 0 then
- local p=0
- while success do
- if not p then
- print("Turtle detected: Can't move forward!")
- p=1
- end
- sleep(math.random(100)/10)
- count = count + 1
- if count > 4 and count % 10 == 7 then
- if not turtle.detectUp() then
- Up()
- sleep(20)
- Down()
- elseif not turtle.detectDown() then
- Down()
- sleep(20)
- Up()
- end
- end
- success, data = turtle.inspect()
- if count > 2000 then
- --we've waited long enough the turtle must be stuck capture it and return home
- for s = 2,16,1 do
- turtle.select(s)
- turtle.drop()
- end
- turtle.dig()
- end
- end
- end
- if success and string.find(data.name, "lava") then
- fuel("f")
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- if facing == 0 then
- curZ = curZ + 1
- elseif facing == 1 then
- curX = curX +1
- elseif facing == 2 then
- curZ = curZ - 1
- else
- curX = curX - 1
- end
- end
- function Up()
- local success, data = turtle.inspectUp()
- if success then
- local count = 0
- if string.find(data.name, "urtle") and killMode == 0 then
- local p = 0
- while success do
- if not p then
- print("Turtle detected: Can't move up!")
- p=1
- end
- sleep(math.random(10))
- success, data = turtle.inspectUp()
- count = count +1
- if count > 3 and count % 10 == 4 then
- local olddir = facing
- while turtle.detect() do
- TRight()
- end
- Forward()
- sleep(20)
- TRight()
- TRight()
- Forward()
- TurnTo(olddir)
- end
- end
- end
- if success and string.find(data.name, "lava") and data.state.level ==0 then
- fuel("u")
- end
- end
- while not turtle.up() do
- turtle.digUp()
- end
- curY = curY + 1
- end
- function Down()
- local success, data = turtle.inspectDown()
- if success then
- --print(data.name)
- local count = 0
- if (string.find(data.name,"brick") or
- string.find(data.name,"end") ) then
- return 0
- end
- if string.find(data.name, "urtle") and killMode == 0 then
- local p = 0
- while success do
- if not p then
- print("Turtle detected: Can't move down")
- p=1
- end
- sleep(math.random(10))
- success, data = turtle.inspectDown()
- count = count +1
- if count > 3 and count % 10 == 4 then
- local olddir = facing
- while turtle.detect() do
- TRight()
- end
- Forward()
- sleep(20)
- TRight()
- TRight()
- Forward()
- TurnTo(olddir)
- end
- if count > 2000 then
- turtle.digDown() --the turtle is not getting out of the way. Eat it.
- end
- end
- end
- end
- if success and string.find(data.name, "lava") and data.state.level == 0 then
- fuel("d")
- end
- if success and (string.find(data.name, "bedrock") or
- string.find(data.name, "spawner") or
- string.find(data.name, "torch") ) then
- --we've hit bedrock. We can't go further.
- --print("hit something we can dig. Returning 0")
- return 0
- end
- while not turtle.down() do
- turtle.digDown()
- end
- curY = curY - 1
- return 1
- end
- function TurnTo(face)
- if (face - facing) % 4 == 3 then
- while (facing ~= face) do
- TLeft()
- end
- else
- while (facing ~= face) do
- TRight()
- end
- end
- end
- function MoveTo (MoveToX, MoveToY, MoveToZ)
- --Move the turtle to the desired position
- --first X
- --print(MoveToX, " " , MoveToY, " " ,MoveToZ)
- if MoveToX < curX then
- TurnTo(3)
- while MoveToX < curX do
- Forward()
- end
- elseif MoveToX > curX then
- TurnTo(1)
- while MoveToX > curX do
- Forward()
- end
- end
- --Now Z
- if MoveToZ < curZ then
- TurnTo(2)
- while MoveToZ < curZ do
- Forward()
- end
- elseif MoveToZ > curZ then
- TurnTo(0)
- while MoveToZ > curZ do
- Forward()
- end
- end
- --Now Y
- if MoveToY < curY then
- while MoveToY < curY do
- Down()
- end
- end
- while MoveToY > curY do
- Up()
- end
- end --MoveTo
- function cobbleBelow()
- local success, data = turtle.inspectDown()
- if success then
- if string.find(data.name, "cobble") or string.find(data.name, "urtle") then
- return 1
- end
- end
- return nil
- end
- function setCobble(direction)
- for i=1,2,1 do
- for slot = 2,3,1 do
- turtle.select(slot)
- if turtle.getItemCount() > 1 then
- if string.find(direction, "d") then
- turtle.placeDown()
- elseif string.find(direction, "u") then
- turtle.placeUp()
- else
- --forward
- turtle.place()
- end
- if turtle.getItemCount() < 10 then
- for s=5,16,1 do
- turtle.select(s)
- if turtle.compareTo(slot) then
- turtle.transferTo(slot)
- return(1)
- end
- end
- end
- return(1)
- end
- end
- replenishCobble()
- end
- moveTo(0,1+turtID,1)
- print("ran out of cobblestone")
- os.exit()
- end
- function replenishCobble()
- --return to the chests and load up on cobble.
- local XX = curX
- local YY = curY
- local ZZ = curZ
- oldfacing = facing
- MoveTo(curX,1+turtID,curZ)
- MoveTo(turtID,1+turtID,1)
- MoveTo(turtID,5,1)
- fuel("n")
- local chestNum = 11
- local needMore = 1
- while chestNum > 0 do
- chestNum = chestNum - 1
- MoveTo(2*math.floor(chestNum/10) +turtID ,curY, chestNum % 10 + 1)
- needMore = 0
- for slot = 2,4,1 do
- turtle.select(slot)
- turtle.suckUp()
- if turtle.getItemCount() < 64 then
- needMore = 1
- end
- end
- end
- if turtle.getItemCount(3) < 64 then
- print("I need more cobble.")
- MoveTo(curX,turtID+1,curZ)
- turtle.select(3)
- while turtle.getItemCount() < 64 do
- sleep(10)
- end
- fuel("n")
- end
- MoveTo(XX,1+turtID,ZZ)
- MoveTo(XX,-2,ZZ)
- setCobble("u")
- MoveTo(XX,YY,ZZ)
- TurnTo(oldfacing)
- end
- function facingOut()
- --determine if the turtle is facing toward the center or outward
- --return true if outward
- print( curX, ",", curY, "," ,curZ)
- if curX > 0 then
- if curZ > 0 then
- if facing == 0 or facing == 1 then
- return true
- else
- return false
- end
- elseif curZ < 0 then
- if facing == 1 or facing == 2 then
- return true
- else
- return false
- end
- else
- --Z is 0
- if facing == 0 or facing == 1 or facing == 2 then
- return true
- else
- return false
- end
- end
- elseif curX < 0 then
- if curZ > 0 then
- if facing == 0 or facing ==3 then
- return true
- else
- return false
- end
- elseif curZ < 0 then
- if facing == 2 or facing == 3 then
- return true
- else
- return false
- end
- else
- --Z is 0
- if facing == 0 or facing == 3 or facing == 2 then
- return true
- else
- return false
- end
- end
- else
- --x is zero
- if curZ > 0 then
- if facing == 0 or facing == 3 or facing == 1 then
- return true
- else
- return false
- end
- elseif curZ < 0 then
- if facing == 2 or facing == 3 or facing == 1 then
- return true
- else
- return false
- end
- else
- --we are at 0,0
- return true
- end
- end
- end
- function Outward()
- --determine the directions that are outward
- local directions = {}
- if math.abs(curX) >= math.abs(curZ)-1 then
- if curX >= 0 then
- table.insert(directions, 1)
- end
- if curX <= 0 then
- table.insert(directions, 3)
- end
- end
- if math.abs(curZ) >= math.abs(curX)-1 then
- if curZ >= 0 then
- table.insert(directions, 0)
- end
- if curZ <= 0 then
- table.insert(directions, 2)
- end
- end
- if curZ == 0 and theta*b < 5 then
- table.insert(directions, 0)
- table.insert(directions, 2)
- end
- if curX == 0 and theta*b < 5 then
- table.insert(directions, 1)
- table.insert(directions, 3)
- end
- return directions
- end
- function Dry(direction)
- if string.find(direction, "d") then
- --there is water below
- setCobble("d")
- else
- --there is water in front
- Forward()
- TLeft()
- for i=1,3,1 do
- local success, data = turtle.inspect()
- if success then
- --print(curX,",",curZ,",",facing,",",facingOut())
- if string.find(data.name, "water") and facingOut() then
- setCobble("f")
- elseif string.find(data.name, "seagrass") or
- string.find(data.name, "kelp") and facingOut() then
- turtle.dig()
- setCobble("f")
- end
- end
- TRight()
- end
- Forward()
- TRight()
- TRight()
- setCobble("f")
- turtle.dig()
- end
- end
- function report(out)
- --term.clear()
- print("theta=", theta, "fuel=", turtle.getFuelLevel())
- print(out)
- end
- function returnUp()
- local radius = math.sqrt(curX*curX + curZ*curZ)
- while curY < -1 do
- turtle.select(2)
- Up()
- if radius < R_base then
- --we're in the area to make the stairs and the lava column
- if (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 0 and theta > 9.2 or
- (math.abs(curX) == 1 and math.abs(curZ)==1) or
- (curX==0 and math.abs(curZ)==2) or
- (curZ==0 and math.abs(curX)==2) then
- setCobble("d")
- end
- elseif radius <= R_max and radius < R_base + (R_max - R_base)*2^((curY + top_column_height) / R_decay) then
- --we're in the region to put regular floors
- if curY % Floor_Spacing ==0 or radius > R_max - 1 then
- setCobble("d")
- end
- end
- end
- --place the cobbles at the top (YY=-1)
- Up()
- setCobble("d") --place a cobblestone in this location to mark it as done
- end
- --Start the program
- columnX = 0 --location to dig out a column
- columnY = 0
- oldXX = 0 --previous XX and ZZ positions
- oldZZ = 0
- XX = 0
- ZZ = 0
- while math.abs(theta) < R_hole/b do
- --find the next (XX,ZZ)
- --first change theuntil we get to a new column
- --print("new column")
- print("theta=", theta, " , fuel=" , turtle.getFuelLevel())
- if theta ~= 0 then
- while ((XX == oldXX) and (ZZ == oldZZ)) do
- theta = theta + step
- XX = math.floor(b*theta * math.cos(theta)+0.5)
- ZZ = math.floor(b*theta * math.sin(theta)+0.5)
- end
- else
- theta = theta + step
- end
- --now the column has changed, but is it really one we've never done before?
- MoveTo(XX,curY,ZZ)
- MoveTo(XX,0,ZZ)
- oldXX = XX
- oldZZ = ZZ
- turtle.digUp()
- --determine which color to place upward
- if math.floor(theta / (6.28318531/ numStripes) + (theta/swirlFactor)) % 2 == 0 then
- turtle.select(1)
- turtle.placeUp()
- if turtle.getItemCount() == 1 then
- for i=8,2,-1 do
- turtle.select(i)
- turtle.transferTo(1)
- end
- end
- turtle.select(1)
- while turtle.getItemCount() == 1 do
- print("Please reload")
- sleep(1)
- end
- else
- turtle.select(9)
- turtle.placeUp()
- if turtle.getItemCount() == 1 then
- for i=16,10,-1 do
- turtle.select(i)
- turtle.transferTo(9)
- end
- end
- turtle.select(9)
- while turtle.getItemCount() == 1 do
- print("Please reload")
- sleep(1)
- end
- end
- end
- MoveTo(0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement