Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --tArgs = width, height, depth (x,y,z) dimensions of requested CPU cluster
- local tArgs = {...}
- if not tArgs[1] or not tArgs[2] or not tArgs[3] then error("All dimensions must be specified! Example: build 2 3 2")
- local cX, cY, cZ = tArgs[1],tArgs[2],tArgs[3] --Get dimensions of the CPU cluster to build
- --Smartly(TM) get a disk from a surrounding disk drive
- local function diskSearch()
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == "computercraft:disk" then --Look for a disk
- print("Found a disk in inventory, slot "..i)
- print("Looking for a drive in inventory...")
- for k = 1, 16 do
- local data2 = turtle.getItemDetail(k)
- if data2 then
- if data2.name == "computercraft:disk_drive" then --look for a disk drive
- print("Found a disk drive in inventory, slot "..k)
- return
- end
- elseif k == 16 then
- error("Missing disk drive")
- end
- end
- end
- elseif i == 16 then
- error("Missing disk")
- end
- end
- end
- --Looks for the given item name as a string and returns true,slotNumber if found, else returns false,nil
- local function findItem(itemName)
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == itemName then
- turtle.select(i)
- return true, i, data
- end
- elseif i == 16 then
- return false, nil
- end
- end
- end
- local function findBlock(blockName,face)
- face = face or "front"
- local data
- if face == "up" then
- data = turtle.inspectUp()
- elseif face == "front" then
- data = turtle.inspect()
- elseif face == "down" then
- data = turtle.inspectDown()
- else
- error("Face wasn't caught in case checkers")
- end
- if data then
- if data.name == blockName then
- return true
- end
- end
- return false
- end
- --Make sure there are enough turtles
- local tC = 0 --total turtle count
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == "computercraft:turtle_advanced" then
- tC = tC + data.count
- end
- end
- end
- local totalT = tArgs[1]*tArgs[2]*tArgs[3]
- if tC < totalT then error("I only have "..tC.." turtles! I need at least "..totalT) end
- --call turn() to turn the turtle. automatically switches turn direction after it's been called.
- local turnDir = turtle.turnRight
- local function turn()
- turnDir()
- turtle.forward()
- turnDir()
- turnDir = turnDir == turtle.turnRight and turtle.turnLeft or turtle.turnRight
- end
- --Main loop
- diskSearch()
- turtle.up()
- turtle.forward()
- for y = 1, cY do
- for x = 1, cX do
- for z = 1, cZ do
- turtle.forward()
- local bool,slot = findItem("computercraft:disk_drive")
- if not bool then
- error("I can't find a disk drive")
- end
- turtle.select(slot)
- turtle.placeDown()
- bool,slot = findItem("computercraft:disk")
- if not bool then
- error("I can't find a disk")
- end
- turtle.select(slot)
- turtle.dropDown()
- turtle.back()
- bool,slot = findItem("computercraft:turtle_advanced")
- if not bool then
- error("I can't find any turtles")
- end
- turtle.select(slot)
- turtle.placeDown()
- turtle.forward()
- turtle.digDown()
- end
- turn()
- turtle.forward()
- end
- turtle.up()
- turnDir()
- turnDir()
- turn()
- end
- turtle.back()
- turtle.back()
- for i = 1, cY+1 do
- turtle.down()
- end
- print("CPU cluster complete.")
- print("Total CPUs: "..totalT)
- print("dimensions:")
- print(cX.."x"..cY.."x"..cZ)
Add Comment
Please, Sign In to add comment