Last active
December 12, 2015 02:28
-
-
Save nitehawk/4698815 to your computer and use it in GitHub Desktop.
ComputerCraft programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Dig out area to create room | |
-- Ensures there is floor, ceiling, walls for room | |
-- | |
-- Place turtle at floor level facing long ways on left wall | |
-- Turtle will dig out 'w' blocks, then turn right and dig 'l' blocks | |
-- | |
-- Note - for now, L will be treated as an even number | |
-- | |
-- Place ender chest in slot 1, filler blocks in slot 2 | |
-- | |
-- Globals | |
local ender=1 | |
local filler=2 | |
-- Get command line | |
local tArgs = { ... } | |
local fullw = tonumber(tArgs[1]) | |
local fulll = tonumber(tArgs[2]) | |
print("Time to build a room: "..fullw.." x "..fulll) | |
-- Status tracking vars | |
local curPass = 1 | |
local passL = fulll | |
function unloadInventory() | |
turtle.select(ender) | |
turtle.place() | |
for islot = 4, 16, 1 | |
do | |
turtle.select(islot) | |
turtle.drop() | |
end | |
turtle.select(ender) | |
turtle.dig() | |
end | |
-- Dig forward until no block is detected | |
function digGravel() | |
repeat | |
turtle.dig() | |
sleep(0.5) | |
until turtle.detect() == false | |
end | |
-- Dig up until no block is detected | |
function digGravelUp() | |
repeat | |
turtle.digUp() | |
sleep(0.5) | |
until turtle.detectUp() == false | |
end | |
-- Dig one pass | |
-- Check ceiling if curPass=1 | |
-- Check floor if curPass=3 | |
function digPass() | |
for iStep=1,fullw,1 | |
do | |
digGravel() | |
if curPass==1 then | |
-- Ceiling pass | |
if turtle.detectUp() == false then | |
turtle.select(filler) | |
turtle.placeUp() | |
end | |
turtle.digDown() | |
elseif curPass==2 then | |
-- Mid pass | |
digGravelUp() | |
turtle.digDown() | |
elseif curPass==3 then | |
-- Floor pass | |
if turtle.detectDown() == false then | |
turtle.select(filler) | |
turtle.placeDown() | |
end | |
digGravelUp() | |
end | |
turtle.forward() | |
end | |
end | |
-- fullDigPass - Complete a full pass of the room | |
function fullDigPass() | |
-- Assume we are in the starting square - position to dig | |
digGravel() | |
turtle.forward() | |
for i = 1, fulll, 2 do | |
digPass() | |
turtle.turnRight() | |
digGravel() | |
turtle.forward() | |
turtle.turnRight() | |
digPass() | |
turtle.turnLeft() | |
digGravel() | |
unloadInventory() | |
turtle.forward() | |
turtle.turnLeft() | |
end | |
-- Return to start | |
turtle.turnRight() | |
for i = 1, fulll, 1 do | |
turtle.forward() | |
end | |
turtle.turnLeft() | |
turtle.forward() | |
turtle.turnLeft() | |
turtle.turnLeft() | |
end | |
-- Empty room | |
-- Clear out entire room, fix floor/ceiling | |
function emptyRoom() | |
-- Move from floor to ceiling | |
for iHeight=1,6,1 do | |
digGravelUp() | |
turtle.up() | |
end | |
-- Do ceiling | |
print("Building ceiling") | |
curPass=1 | |
fullDigPass() | |
-- Do middle | |
print("Clearing out middle of room") | |
curPass=2 | |
fullDigPass() | |
-- Do floor | |
print("Building floor") | |
curPass=3 | |
fullDigPass() | |
end | |
-- Check and rebuild the walls of the room | |
-- Note: Currently this won't work properly | |
function doWalls() | |
end | |
-- main program segment | |
-- Empty out the room | |
emptyRoom() | |
doWalls() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Place turtle 3 blocks from fire in wrath forge | |
-- Place iron blocks in slot 16 | |
-- Turtle will advance into position and start placing iron blocks and picking up the dark iron blocks | |
-- when slot 16 is empty, turtle will backup one space to be picked up | |
turtle.forward() | |
while turtle.getItemCount(16) > 0 | |
do | |
turtle.select(16) | |
turtle.place() | |
sleep(2) | |
turtle.select(1) | |
turtle.dig() | |
end | |
turtle.back() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Dig a 3x3 tunnel for x blocks | |
-- Place turtle at left side of tunnel at middle | |
-- Place sorter ender chest in slot 1 | |
-- Place torches in slot 2 - autoplace torches every 4 blocks | |
-- Place filler blocks (cobble or similar) in slot 3 | |
-- Currently only used to place blocks for torches | |
-- | |
-- Note: bug with digging gravel can cause turtle to get lost. | |
-- Attempting to fix with longer delay after digging to check for block | |
local ender=1 | |
local torch=2 | |
local filler=3 | |
local placeTorchEvery=6 | |
-- Tracking variables | |
local torchBlock=0 | |
local advanceDir=1 | |
function unloadInventory() | |
turtle.select(ender) | |
turtle.place() | |
for islot = 4, 16, 1 | |
do | |
turtle.select(islot) | |
turtle.drop() | |
end | |
turtle.select(ender) | |
turtle.dig() | |
end | |
-- Place a torch every 4th block along the tunnel | |
function torchPlace() | |
torchBlock=torchBlock+1 | |
if torchBlock == placeTorchEvery | |
then | |
torchBlock = 0 | |
turtle.down() | |
if turtle.detectDown() == false | |
then | |
turtle.select(filler) | |
turtle.placeDown() | |
end | |
turtle.up() | |
turtle.select(torch) | |
turtle.placeDown() | |
end | |
end | |
-- Dig forward until no block is detected | |
function digGravel() | |
repeat | |
turtle.dig() | |
sleep(0.5) | |
until turtle.detect() == false | |
end | |
-- Dig up until no block is detected | |
function digGravelUp() | |
repeat | |
turtle.digUp() | |
sleep(0.5) | |
until turtle.detectUp() == false | |
end | |
-- Turtle should be in space 4 or space 6 pointing across the tunnel | |
function tunnelPass() | |
digGravel() | |
digGravelUp() | |
turtle.digDown() | |
-- Forward to space 5 | |
turtle.forward() | |
digGravel() | |
digGravelUp() | |
turtle.digDown() | |
-- Call every pass, places a torch when needed | |
torchPlace() | |
-- Forward to space 4 or space 6 | |
turtle.forward() | |
digGravelUp() | |
turtle.digDown() | |
end | |
-- Advance turtle forward to next part of tunnel | |
function advance() | |
-- advanceDir==1, turn left | |
-- advanceDir==2, turn right | |
if advanceDir==1 | |
then | |
advanceDir=2 | |
turtle.turnLeft() | |
digGravel() | |
turtle.forward() | |
turtle.turnLeft() | |
else | |
advanceDir=1 | |
turtle.turnRight() | |
digGravel() | |
unloadInventory() | |
turtle.forward() | |
turtle.turnRight() | |
end | |
end | |
-- Main program | |
local tArgs = { ... } | |
length = tonumber(tArgs[1]) | |
if length < 3 | |
then | |
print( "Clear it out yourself you lazy bum!" ) | |
exit() | |
end | |
turtle.turnRight() | |
while length > 0 | |
do | |
print( "Tunneling... " .. length .. " blocks remain..") | |
length = length - 1 | |
tunnelPass() | |
advance() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment