Cobble Generator
From ComputerCraft Wiki
Tutorial written by Temploit/NewFletcher.
Contents
Colors
Run Loop: while true do
If: if a=b then
Action: turtle.dig()
Var: a = turtle.getItemCount(1)
Print: Print("Cobble Farm")
For: for i=1,9 do
Image
Coding
First, you have to make a loop so the machine keeps running:
while true do 'Command end
Now, inside of the loop, you have to add something to detect the block:
while true do if turtle.detect() then 'Command end end
After that, the block must be mined:
while true do if turtle.detect() then turtle.dig() end end
This detects if a block is present, and then mines it. However, when all the 9 block spaces are filled with blocks (9*64=576 blocks), they must be dropped to collect new blocks:
while true do if turtle.detect() then turtle.dig() end itemcount = turtle.getItemCount(9) if itemcount == 64 then 'Drop all stacks end end
To drop all stacks, another loop must be added:
while true do if turtle.detect() then turtle.dig() end itemcount = turtle.getItemCount(9) if itemcount == 64 then for i=1,9 do 'Select each stack and then drops it end end end
To select each stack and drop it, a turtle.select() and a turtle.drop() must be added:
while true do if turtle.detect() then turtle.dig() end itemcount = turtle.getItemCount(9) if itemcount == 64 then for i=1,9 do turtle.select(i) turtle.drop() end turtle.select(1) end end
Advanced Generator
This is the generator I created (for use with (height:4 width:2) monitor):
while true do if turtle.detect() then turtle.dig() term.clear() term.setCursorPos(1,1) a = turtle.getItemCount(1) b = turtle.getItemCount(2) c = turtle.getItemCount(3) d = turtle.getItemCount(4) e = turtle.getItemCount(5) f = turtle.getItemCount(6) g = turtle.getItemCount(7) h = turtle.getItemCount(8) i = turtle.getItemCount(9) print("Row 1: " .. a .. " (" .. math.floor(((a/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 2: " .. b .. " (" .. math.floor(((b/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 3: " .. c .. " (" .. math.floor(((c/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 4: " .. d .. " (" .. math.floor(((d/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 5: " .. e .. " (" .. math.floor(((e/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 6: " .. f .. " (" .. math.floor(((f/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 7: " .. g .. " (" .. math.floor(((g/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 8: " .. h .. " (" .. math.floor(((h/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") print("Row 9: " .. i .. " (" .. math.floor(((i/(a+b+c+d+e+f+g+h+i))*100)) .. "%)") totalc = a+b+c+d+e+f+g+h+i print("Total: " .. totalc) print("-----------------") if a<10 then a = "0"..a end if b<10 then b = "0"..b end if c<10 then c = "0"..c end if d<10 then d = "0"..d end if e<10 then e = "0"..e end if f<10 then f = "0"..f end if g<10 then g = "0"..g end if h<10 then h = "0"..h end if i<10 then i = "0"..i end print(" ___ ___ ___ ") print("|" .. a .. " |" .. b .. " |" .. c .. " |") print("|___|___|___|") print("|" .. d .. " |" .. e .. " |" .. f .. " |") print("|---|---|---|") print("|" .. g .. " |" .. h .. " |" .. i .. " |") print("|___|___|___|") print(" ") print("-----------------") print("Cobble Farmer") print("By: NewFletcher") end totalcount = turtle.getItemCount(9) if totalcount == 64 then term.clear() term.setCursorPos(1,1) print("Dropping Stacks") print("...Please wait.") sleep(1) for i=1,9 do turtle.select(i) turtle.drop() end turtle.select(1) end end