Cobble Generator

From ComputerCraft Wiki
Jump to: navigation, search

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,16 do

Image

SmallGen.png

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 16 block spaces are filled with blocks, they must be dropped to collect new blocks:

while true do
 if turtle.detect() then
  turtle.dig()
 end
 itemcount = turtle.getItemCount(16)
 if itemcount == 64 then
 'Drop all stacks
 end
end

Not that it may not be a good idea to drop all stacks on the ground. 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,16 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(16)
 if itemcount == 64 then
  for i=1,16 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):

function counter()
 local i = 0
 return function() i = i + 1 return i end
end
function modStr(num)
 if num < 10 then
   return "0" .. num
 else
   return num
 end
end
while true do
 if turtle.detect() then
  turtle.dig()
  term.clear()
  term.setCursorPos(1,1)
  local total = 0
  for i=1,16,1 do
   total = total + turtle.getItemCount(i)
  end
  for i=1,16,1 do
   print("Row " .. i .. ": " .. turtle.getItemCount(i) .. " (" .. math.floor((turtle.getItemCount(i)/total)*100) .. "%)")
  end
  print("Total: " .. total)
  print("-----------------")
  local iterator = counter()
  print(" ___ ___ ___ ")
  print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")
  print("|___|___|___|")
  print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")
  print("|---|---|---|")
  print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")
  print("|___|___|___|")
  print(" ")
  print("-----------------")
  print("Cobble Farmer")
 end
 totalcount = turtle.getItemCount(16)
 if totalcount == 64 then
  term.clear()
  term.setCursorPos(1,1)
  print("Dropping Stacks")
  print("...Please wait.")
  sleep(1)
  for i=1,16 do
   turtle.select(i)
   turtle.drop()
  end
  turtle.select(1)
 end
end

Images:
MyCob.png

MyGen.png

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox