Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- build: Build predifined structures
- -- Rev 2.1
- args = {...}
- nArgs = #args
- version = "build: Rev 2.1"
- usage = "Usage: build <structure name>"
- -- Locations
- origin = {0, 0, 0}
- center = {0, 0, 15}
- -- length, width, xOffset, zOffset, yOffset
- base = {15, 15, 0, 0, 150}
- tower = {5, 5, 0, 0, 150}
- ladderChute = {1, 1, 0, -8, 0}
- drainFloor = {15, 15, 0, 0, 190}
- conveyors = {3, 3, 0, -1, 190}
- quicksand = {13, 13, 0, 0, 193}
- chamber = {15, 15, 0, 0, 190}
- roof = {15, 15, 0, 0, 198}
- -- Global Origin
- gX = 0
- gY = 0
- gZ = 0
- -- Base Origin
- bX = 5
- bY = 0
- bZ = 5
- -- Drain Origin
- dX = 0
- dY = 0
- dZ = 0
- -- Tower Origin
- tX = 0
- tY = 0
- tZ = 0
- -- Cobble Chest
- ccX = 0
- ccY = 0
- ccZ = 0
- -- Quicksand Chest
- qcX = -2
- qcY = 0
- qcZ = 0
- -- Slab Chest
- scX = -2
- scY = 0
- scZ = 0
- -- Conveyor Chest
- cvcX = -3
- cvcY = 0
- cvcZ = 0
- -- Ladder Chest
- lcX = -4
- lcY = 0
- lcZ = 0
- -- Torch Chest
- tcX = -5
- tcY = 0
- tcZ = 0
- x = gX
- y = gY
- z = gZ
- -- The following 'face' directions are relative to the starting position of the turtle in this program
- north = 0
- west = 1
- south = 2
- east = 3
- function goToStartPt(data)
- length = data[1]
- width = data[2]
- xOffset = data[3]
- zOffset = data[4]
- yOffset = data[5]
- print("l: ", length, ", w: ", width)
- if width > 1 then
- targetX = center[1] + ((width - 1) / 2) + xOffset
- else
- targetX = center[1] + xOffset
- end
- if length > 1 then
- targetZ = center[3] - ((length - 1) / 2) + zOffset
- else
- targetZ = center[3] + zOffset
- end
- targetY = center[2] + yOffset
- print("xOff: ", xOffset, ", zOff: ", zOffset, ", yOff: ", yOffset)
- print("center[2]: ", center[2], " tX: ", targetX, ", tY: ", targetY, ", tZ: ", targetZ)
- moveTo(targetX, targetY, targetZ)
- end
- function goToStructure(structure)
- local x = 0
- local y = 0
- local z = 0
- if structure == "origin" then
- x = origin[1]
- y = origin[2]
- z = origin[3]
- elseif structure == "tower" then
- x = tower[1]
- y = tower[2]
- z = tower[3]
- elseif structure == "base" then
- x = base[1]
- y = base[2]
- z = base[3]
- elseif structure == "ladderChute" then
- x = ladderChute[1]
- y = ladderChute[2]
- z = ladderChute[3]
- elseif structure == "drainFloor" then
- x = drainFloor[1]
- y = drainFloor[2]
- z = drainFloor[3]
- elseif structure == "conveyors" then
- x = conveyors[1]
- y = conveyors[2]
- z = conveyors[3]
- elseif structure == "quicksand" then
- x = quicksand[1]
- y = quicksand[2]
- z = quicksand[3]
- elseif structure == "chamber" then
- x = chamber[1]
- y = chamber[2]
- z = chamber[3]
- elseif structure == "roof" then
- x = roof[1]
- y = roof[2]
- z = roof[3]
- end
- moveTo(x, y, z)
- end
- function moveUp()
- for i=1,10 do -- Keep trying in case something is temporarily in the way
- if turtle.up() then
- y = y + 1
- break
- else
- sleep(2)
- end
- end
- end
- function moveDown()
- for i=1,10 do -- Keep trying in case something is temporarily in the way
- if turtle.down() then
- y = y - 1
- break
- else
- sleep(2)
- end
- end
- end
- function moveTo(X, Y, Z)
- print("moveTo(", X, ", ", Y, ", ", Z, ") y: ", y)
- if y == nil then print("y is nil") end
- if Y == nil then print("Y is nil") end
- if y ~= Y then
- if y < Y then
- while y < Y do
- moveUp()
- end
- else
- while y > Y do
- moveDown()
- end
- end
- end
- if x ~= X then
- if x < X then
- setFace(east)
- while x < X do
- go(1)
- end
- else
- setFace(west)
- while x > X do
- go(1)
- end
- end
- end
- if z ~= Z then
- if z < Z then
- setFace(north)
- while z < Z do
- go(1)
- end
- else
- setFace(south)
- while z > Z do
- go(1)
- end
- end
- end
- end
- function goToChest(chest)
- if chest == cobbleChest then
- moveTo(ccX, ccY, ccZ)
- elseif chest == quicksandChest then
- moveTo(qcX, qcY, qcZ)
- elseif chest == slabChest then
- moveTo(scX, scY, scZ)
- elseif chest == conveyorChest then
- moveTo(cvcX, cvcY, cvcZ)
- elseif chest == ladderChest then
- moveTo(lcX, lcY, lcZ)
- elseif chest == torchChest then
- moveTo(tcX, tcY, tcZ)
- end
- end
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function back(nBlocks)
- local failed = true
- for i=1,nBlocks do
- for j=1,10 do -- multiple tries in case something is temporarily in the way
- if turtle.back() then
- failed = false
- break
- else
- sleep(2)
- end
- end
- end
- if face == north then z = z - nBlocks end
- if face == south then z = z + nBlocks end
- if face == east then x = x - nBlocks end
- if face == west then x = x + nBlocks end
- end
- function go(nBlocks)
- local failed = true
- for i=1,nBlocks do
- for j=1,10 do -- multiple tries in case something is temporarily in the way
- if turtle.forward() then
- failed = false
- break
- else
- sleep(2)
- end
- end
- end
- if failed then
- return
- end
- if face == north then z = z + nBlocks end
- if face == south then z = z - nBlocks end
- if face == east then x = x + nBlocks end
- if face == west then x = x - nBlocks end
- end
- function left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function globalHome()
- print("globalHome...")
- moveTo(gX, gY, gZ)
- setFace(north)
- end
- function xzHome()
- local X = gX
- local Z = gZ
- if x ~= X then
- if x < X then
- setFace(east)
- while x < X do
- go(1)
- end
- else
- setFace(west)
- while x > X do
- go(1)
- end
- end
- end
- if z ~= Z then
- if z < Z then
- setFace(north)
- while z < Z do
- go(1)
- end
- else
- setFace(south)
- while z > Z do
- go(1)
- end
- end
- end
- end
- function zxHome()
- zHome()
- xHome()
- end
- function xHome()
- local X = gX
- if x ~= X then
- if x < X then
- setFace(east)
- while x < X do
- go(1)
- end
- else
- setFace(west)
- while x > X do
- go(1)
- end
- end
- end
- end
- function zHome()
- local Z = gZ
- if z ~= Z then
- if z < Z then
- setFace(north)
- while z < Z do
- go(1)
- end
- else
- setFace(south)
- while z > Z do
- go(1)
- end
- end
- end
- end
- function yHome()
- local Y = gY
- if y ~= Y then
- if y < Y then
- while y < Y do
- turtle.up()
- y = y + 1
- end
- else
- while y > Y do
- turtle.down()
- y = y - 1
- end
- end
- end
- end
- function grabStuff(stuffSlot)
- turtle.select(stuffSlot)
- turtle.suckDown()
- for i=5,16 do
- turtle.select(i)
- if not turtle.compareTo(stuffSlot) then
- turtle.dump()
- end
- turtle.suckDown()
- end
- turtle.select(stuffSlot)
- turtle.suckDown()
- end
- function dropStuff(stuffSlot)
- qty = turtle.getItemCount(stuffSlot) - 1
- turtle.dropDown(qty)
- for i=5,16 do
- turtle.select(i)
- if (turtle.compareTo(stuffSlot)) then
- turtle.dropDown()
- end
- end
- end
- function grabCobble()
- turtle.select(cobbleSlot)
- for i=5,16 do
- turtle.suckDown()
- qty = turtle.getItemCount(cobbleSlot) - 1
- turtle.transferTo(i, qty)
- end
- end
- function dropCobble()
- qty = turtle.getItemCount(cobbleSlot) - 1
- turtle.dropDown(qty)
- for i=5,16 do
- turtle.select(i)
- if (turtle.compareTo(cobbleSlot)) then
- turtle.dropDown()
- end
- end
- end
- function floorHole(length, width)
- for i = 1,width do
- for j = 1,length do
- turtle.digDown()
- if j < length then
- turtle.forward()
- if face == north then
- z = z + 1
- elseif face == south then
- z = z - 1
- end
- end
- end
- if i < width then
- if face == north then
- left()
- turtle.forward()
- x = x - 1
- left()
- elseif face == south then
- right()
- turtle.forward()
- x = x - 1
- right()
- end
- end
- end
- end
- function nextSpot()
- end
- function sprinkleTorches(length, width, interval)
- turtle.up()
- y = y + 1
- turtle.select(16)
- lengthSpan = length - (2 * interval) - 1
- widthSpan = width - (2 * interval) - 1
- left()
- for i = 1,interval do
- go(1)
- end
- right()
- for i = 1,interval do
- go(1)
- end
- turtle.placeDown()
- for i = 1,lengthSpan do
- go(1)
- end
- turtle.placeDown()
- left()
- for i = 1,widthSpan do
- go(1)
- end
- turtle.placeDown()
- left()
- for i = 1,lengthSpan do
- go(1)
- end
- turtle.placeDown()
- left()
- for i = 1,widthSpan + interval do
- go(1)
- end
- right()
- for i = 1,lengthSpan + interval do
- go(1)
- end
- turtle.down()
- y = y - 1
- end
- function sprinkleSurface(length, width, interval)
- totalPlaced = 0
- turtle.up()
- y = y + 1
- turtle.select(16)
- for i = 1,width do
- for j = 1,length do
- if j < length then
- if (i % interval == 0 and j % interval == 0) then
- turtle.placeDown()
- end
- turtle.forward()
- totalPlaced = totalPlaced + 1
- if face == north then
- z = z + 1
- elseif face == south then
- z = z - 1
- end
- end
- end
- if i < width then
- if face == north then
- left()
- while i % interval ~= 0 do
- turtle.forward()
- x = x - 1
- i = i + 1
- end
- left()
- elseif face == south then
- right()
- while i % interval ~= 0 do
- turtle.forward()
- x = x - 1
- i = i + 1
- end
- right()
- end
- end
- end
- end
- function load(chest, startSlot, endSlot)
- goToChest(chest)
- for slot=startSlot, endSlot do
- turtle.select(slot)
- turtle.suckDown()
- end
- end
- function dump(chest, startSlot, endSlot)
- goToChest(chest)
- for slot=startSlot, endSlot do
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- saveX = 0
- saveY = 0
- saveZ = 0
- saveFace = 0
- function saveXYZ()
- saveX = x
- saveY = y
- saveZ = z
- saveFace = face
- print("Saved xyz as ", saveX, ", ", saveY, ", ", saveZ, ", face: ", saveFace)
- end
- function restoreXYZ()
- x = saveX
- y = saveY
- z = saveZ
- face = saveFace
- print("Restored xyz as ", x, ", ", y, ", ", z, ", face: ", face)
- end
- function run(script)
- saveXYZ()
- shell.run(script)
- restoreXYZ()
- end
- cobbleChest = 1
- quicksandChest = 2
- conveyorChest = 3
- ladderChest = 4
- torchChest = 5
- slabChest = 2
- cobbleSlot = 1
- quicksandSlot = 2
- conveyorSlot = 3
- torchSlot = 3
- --grabStuff(cobbleSlot)
- --sleep(3)
- --dropStuff(cobbleSlot)
- -- BUILD SKYSCRAPER QUICKSAND MOB TRAP
- function buildSandTrap()
- load(cobbleChest, 1, 8)
- load(torchChest, 16, 16)
- goToStartPt(base)
- run("floor 15 15")
- print("Base completed")
- setFace(north)
- sprinkleTorches(15, 15, 3)
- xzHome()
- yHome()
- dump(cobbleChest, 1, 8)
- dump(torchChest, 16, 16)
- load(cobbleChest, 1, 13)
- load(ladderChest, 14, 16)
- globalHome()
- goToStartPt(ladderChute)
- setFace(north)
- run("chute -150 true")
- z = z - 1 -- The 'chute' program finishes one block back from start
- print("Ladder chute completed")
- dump(cobbleChest, 1, 13)
- dump(ladderChest, 14, 16)
- load(cobbleChest, 1, 16)
- globalHome()
- goToStartPt(tower)
- run("walls 5 5 40")
- z = z - 1 -- The 'walls' program finishes one block back from start
- print("Tower completed")
- xzHome()
- print("xzHome completed")
- yHome()
- dump(cobbleChest, 1, 16)
- load(cobbleChest, 1, 8)
- goToStartPt(drainFloor)
- run("floor 15 15")
- left()
- for i = 1,6 do
- go(1)
- end
- right()
- for i = 1,6 do
- go(1)
- end
- floorHole(3, 3)
- xzHome()
- yHome()
- xzHome()
- dump(cobbleChest, 1, 8)
- load(conveyorChest, 1, 3)
- goToStartPt(conveyors)
- run("fabdrain")
- y = y + 1 -- The 'fabdrain' program finishes one block up from start
- xzHome()
- yHome()
- dump(conveyorChest, 1, 3)
- load(quicksandChest, 1, 3)
- goToStartPt(quicksand)
- run("floor 13 13")
- xzHome()
- yHome()
- dump(quicksandChest, 1, 3)
- load(cobbleChest, 1, 12)
- goToStartPt(chamber)
- run("walls 15 15 7")
- z = z - 1 -- The 'walls' program finishes one block back from start
- xzHome()
- yHome()
- dump(cobbleChest, 1, 12)
- load(cobbleChest, 1, 8)
- load(torchChest, 16, 16)
- goToStartPt(roof)
- run("floor 15 15")
- setFace(north)
- sprinkleTorches(15, 15, 3)
- xzHome()
- yHome()
- dump(cobbleChest, 1, 8)
- dump(torchChest, 16, 16)
- globalHome()
- end
- torchSlot = 16
- function goXZ(startFace, newX, newZ)
- setFace(startFace)
- if face == east then
- while x > newX do
- go(1)
- end
- elseif face == west then
- while x < newX do
- go(1)
- end
- else
- end
- if face == north then
- while z < newZ do
- go(1)
- end
- elseif face == south then
- while z > newZ do
- go(1)
- end
- else
- end
- end
- function goZX(startFace, newX, newZ)
- setFace(startFace)
- if face == north then
- while z < newZ do
- go(1)
- end
- elseif face == south then
- while z > newZ do
- go(1)
- end
- else
- end
- if face == east then
- while x > newX do
- go(1)
- end
- elseif face == west then
- while x < newX do
- go(1)
- end
- else
- end
- end
- function layTorches(distance, spacing)
- turtle.select(torchSlot)
- for i=1,distance do
- if i % spacing == 0 then
- turtle.placeDown()
- end
- if i < distance then
- go(1)
- end
- end
- end
- function lightPlatform()
- goToStartPt(platform)
- turtle.up()
- y = y + 1
- turtle.select(torchSlot)
- setFace(west)
- go(3)
- setFace(north)
- back(1)
- layTorches(platform[2], 4)
- setFace(west)
- go(5)
- setFace(south)
- back(2)
- layTorches(11, 4)
- turtle.placeDown()
- setFace(west)
- go(2)
- setFace(south)
- go(8)
- setFace(east)
- go(1)
- turtle.placeDown()
- go(2)
- turtle.placeDown()
- -- setFace(south)
- -- go(1)
- setFace(west)
- go(5)
- setFace(north)
- layTorches(17, 4)
- setFace(west)
- go(4)
- setFace(south)
- back(2)
- layTorches(17, 4)
- end
- function buildMobGrinder()
- center = {-6, 0, 20}
- -- length, width, xOffset, zOffset, yOffset
- base = {21, 23, 0, 0, 160}
- platform = {17, 17, 0, -2, base[5]-40}
- torch1 = {9, 9, 0, 0, base[5]+1}
- torch2 = {17, 17, 0, 0, base[5]+1}
- dropTower = {3, 3, 0, 0, platform[5]}
- ladderChute1 = {1, 1, 0, -11, 0}
- ladderChute2 = {1, 1, -6, 0, platform[5]}
- dropChute = {1, 1, 0, -6, platform[5]}
- torch3 = {9, 15, -3, -5, platform[5]+1}
- floorA = {13, 7, 4, 0, base[5]+4}
- wallA = {1, 5, 0, 0, floorA[5]}
- trapWallsA = {13, 7, 4, 0, floorA[5]}
- trapRoofA = {13, 7, 4, 0, floorA[5] + 4}
- trapSlabsA = {13, 7, 4, 0, trapRoofA[5] + 1}
- floorB = {13, 7, -4, 0, base[5] + 4}
- wallB = {1, 5, -4, 0, floorB[5]}
- trapWallsB = {13, 7, -4, 0, floorB[5]}
- trapRoofB = {13, 7, -4, 0, floorB[5] + 4}
- trapSlabsB = {13, 7, -4, 0, trapRoofB[5] + 1}
- drainFloor = {15, 15, 0, 0, 190}
- conveyors = {3, 3, 0, -1, 190}
- quicksand = {13, 13, 0, 0, 193}
- chamber = {15, 15, 0, 0, 190}
- roof = {15, 15, 0, 0, 198}
- -- Begin the build
- -- LADDER CHUTE FROM GROUND TO PLATFORM
- load(cobbleChest, 1,12)
- load(ladderChest, 14, 16)
- goToStartPt(ladderChute1)
- run("chute " .. -platform[5] .. " true")
- z = z - 1 -- The 'chute' program finishes one block back from start
- globalHome()
- dump(ladderChest, 14, 16)
- dump(cobbleChest, 1, 12)
- -- PLATFORM
- setFace(north)
- load(cobbleChest, 1, 12)
- load(torchChest, 16, 16)
- goToStartPt(platform)
- run("floor " .. platform[1] .. " " .. platform[2])
- -- TORCHES ON PLATFORM
- lightPlatform()
- zxHome()
- yHome()
- dump(torchChest, 16, 16)
- dump(cobbleChest, 1, 12)
- -- DROP CHUTE
- load(cobbleChest, 1, 12)
- load(ladderChest, 14, 16)
- goToStartPt(dropChute)
- setFace(north)
- height = platform[5] - base[5]
- run("chute " .. height .. " false") -- No ladders needed in drop chute
- z = z - 1 -- The 'chute' program finishes one block back from start
- -- LADDER CHUTE FROM PLATFORM TO BASE
- goToStartPt(ladderChute2)
- setFace(west)
- height = platform[5] - base[5]
- run("chute " .. height .. " true")
- x = x + 1 -- The 'chute' program finishes one block back from start
- zxHome()
- dump(ladderChest, 15, 16)
- dump(cobbleChest, 1, 12)
- -- BASE
- load(cobbleChest, 1, 12)
- load(torchChest, 16, 16)
- goToStartPt(base)
- setFace(north)
- run("floor " .. base[1] .. " " .. base[2])
- -- TORCHES ON BASE
- moveTo(center[1], torch1[5], center[3])
- turtle.select(16)
- turtle.placeDown()
- goToStartPt(torch1)
- setFace(north)
- run("sprinkle " .. torch1[1] .. " " .. torch1[2])
- goToStartPt(torch2)
- setFace(north)
- run("sprinkle " .. torch2[1] .. " " .. torch2[2])
- goToStartPt(floorB)
- run("floor " .. floorB[1] .. " " .. floorB[2])
- goToStartPt(floorA)
- setFace(north)
- run("floor " .. floorA[1] .. " " .. floorA[2])
- zxHome()
- yHome()
- dump(cobbleChest, 1, 12)
- dump(torchChest, 16, 16)
- load(cobbleChest, 1, 16)
- goToStartPt(wallB)
- setFace(west)
- run("wall 5 3")
- x = x + 1 -- The 'wall' program finishes one block back from start
- goToStartPt(wallA)
- setFace(east)
- run("wall 5 3")
- x = x - 1 -- The 'wall' program finishes one block back from start
- setFace(south)
- go(6)
- goToStartPt(trapWallsB)
- setFace(north)
- run("walls " .. trapWallsB[1] .. " " .. trapWallsB[2] .. " " .. 3)
- z = z - 1 -- The 'walls' program finishes one block back from start
- setFace(south)
- go(1)
- xHome()
- goToStartPt(trapWallsA)
- setFace(north)
- run("walls " .. trapWallsA[1] .. " " .. trapWallsA[2] .. " " .. 3)
- z = z - 1 -- The 'walls' program finishes one block back from start
- goToStartPt(trapRoofB)
- setFace(north)
- run("floor " .. trapRoofB[1] .. " " .. trapRoofB[2])
- goToStartPt(trapRoofA)
- setFace(north)
- run("floor " .. trapRoofA[1] .. " " .. trapRoofA[2])
- zxHome()
- yHome()
- dump(cobbleChest, 1, 16)
- load(slabChest, 1, 3)
- goToStartPt(trapSlabsB)
- setFace(north)
- run("floor " .. trapSlabsB[1] .. " " .. trapSlabsB[2])
- goToStartPt(trapSlabsA)
- setFace(north)
- run("floor " .. trapSlabsA[1] .. " " .. trapSlabsA[2])
- zxHome()
- setFace(north)
- yHome()
- dump(slabChest, 1, 3)
- globalHome()
- end
- function buildWaterHut()
- --[[
- for i=1,6 do
- turtle.down()
- end
- run("floor 5 5")
- run("walls 5 5 3")
- for i=1,4 do
- turtle.up()
- end
- go(1)
- run("floor 5 5")
- --]]
- while turtle.down() do
- y = y - 1
- end
- height = y + 1
- run("chute " .. height)
- back(1)
- yHome()
- end
- -- MAIN PROGRAM
- if nArgs ~= 1 then
- print(usage)
- return
- end
- face = north
- if args[1] == "sandtrap" then
- buildSandTrap()
- elseif args[1] == "mobgrinder" then
- buildMobGrinder()
- elseif args[1] == "waterhut" then
- buildWaterHut()
- else
- print("Unknown structure: \"", args[1], "\"")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement