Difference between revisions of "Cobble Generator"
(Added to the Tutorials category) |
m (→Advanced Generator) |
||
(11 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
== Colors == | == Colors == | ||
Run Loop: <span style="color:blue">while true do</span><br> | Run Loop: <span style="color:blue">while true do</span><br> | ||
− | If: <span style="color:green">if a=b then</span><br> | + | If: <span style="color:green">if a==b then</span><br> |
Action: <span style="color:red">turtle.dig()</span><br> | Action: <span style="color:red">turtle.dig()</span><br> | ||
Var: <span style="color:DarkViolet">a = turtle.getItemCount(1)</span><br> | Var: <span style="color:DarkViolet">a = turtle.getItemCount(1)</span><br> | ||
Print: <span style="color:OrangeRed">Print("Cobble Farm")</span><br> | Print: <span style="color:OrangeRed">Print("Cobble Farm")</span><br> | ||
− | For: <span style="color:DarkCyan">for i=1, | + | For: <span style="color:DarkCyan">for i=1,16 do</span><br> |
+ | |||
== Image == | == Image == | ||
[[File:SmallGen.png]] | [[File:SmallGen.png]] | ||
Line 29: | Line 28: | ||
<span style="color:blue">end</span> | <span style="color:blue">end</span> | ||
This detects if a block is present, and then mines it. | This detects if a block is present, and then mines it. | ||
− | However, when all the | + | However, when all the 16 block spaces are filled with blocks, they must be dropped to collect new blocks: |
<span style="color:blue">while true do</span> | <span style="color:blue">while true do</span> | ||
<span style="color:green">if turtle.detect() then</span> | <span style="color:green">if turtle.detect() then</span> | ||
<span style="color:red">turtle.dig()</span> | <span style="color:red">turtle.dig()</span> | ||
<span style="color:green">end</span> | <span style="color:green">end</span> | ||
− | <span style="color:DarkViolet">itemcount = turtle.getItemCount( | + | <span style="color:DarkViolet">itemcount = turtle.getItemCount(16)</span> |
<span style="color:green">if itemcount == 64 then</span> | <span style="color:green">if itemcount == 64 then</span> | ||
''''Drop all stacks | ''''Drop all stacks | ||
<span style="color:green">end</span> | <span style="color:green">end</span> | ||
<span style="color:blue">end</span> | <span style="color:blue">end</span> | ||
+ | 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: | To drop all stacks, another loop must be added: | ||
<span style="color:blue">while true do</span> | <span style="color:blue">while true do</span> | ||
Line 46: | Line 46: | ||
<span style="color:DarkViolet">itemcount = turtle.getItemCount(9)</span> | <span style="color:DarkViolet">itemcount = turtle.getItemCount(9)</span> | ||
<span style="color:green">if itemcount == 64 then</span> | <span style="color:green">if itemcount == 64 then</span> | ||
− | <span style="color:DarkCyan">for i=1, | + | <span style="color:DarkCyan">for i=1,16 do</span> |
''''Select each stack and then drops it | ''''Select each stack and then drops it | ||
<span style="color:DarkCyan">end</span> | <span style="color:DarkCyan">end</span> | ||
Line 56: | Line 56: | ||
<span style="color:red">turtle.dig()</span> | <span style="color:red">turtle.dig()</span> | ||
<span style="color:green">end</span> | <span style="color:green">end</span> | ||
− | <span style="color:DarkViolet">itemcount = turtle.getItemCount( | + | <span style="color:DarkViolet">itemcount = turtle.getItemCount(16)</span> |
<span style="color:green">if itemcount == 64 then</span> | <span style="color:green">if itemcount == 64 then</span> | ||
− | <span style="color:DarkCyan">for i=1, | + | <span style="color:DarkCyan">for i=1,16 do</span> |
<span style="color:red">turtle.select(i)<span> | <span style="color:red">turtle.select(i)<span> | ||
<span style="color:red">turtle.drop()<span> | <span style="color:red">turtle.drop()<span> | ||
Line 68: | Line 68: | ||
== Advanced Generator == | == Advanced Generator == | ||
This is the generator I created (for use with (height:4 width:2) monitor): | This is the generator I created (for use with (height:4 width:2) monitor): | ||
+ | |||
+ | function counter() | ||
+ | <span style="color:DarkViolet">local i = 0</span> | ||
+ | return function() i = i + 1 return i end | ||
+ | end | ||
+ | function modStr(num) | ||
+ | <span style="color:green">if num < 10 then</span> | ||
+ | return "0" .. num | ||
+ | <span style="color:green">else</span> | ||
+ | return num | ||
+ | <span style="color:green">end</span> | ||
+ | end | ||
<span style="color:blue">while true do</span> | <span style="color:blue">while true do</span> | ||
<span style="color:green">if turtle.detect() then</span> | <span style="color:green">if turtle.detect() then</span> | ||
Line 73: | Line 85: | ||
<span style="color:red">term.clear()</span> | <span style="color:red">term.clear()</span> | ||
<span style="color:red">term.setCursorPos(1,1)</span> | <span style="color:red">term.setCursorPos(1,1)</span> | ||
− | <span style="color:DarkViolet"> | + | <span style="color:DarkViolet">local total = 0</span> |
− | <span style="color: | + | <span style="color:DarkCyan">for i=1,16,1 do</span> |
− | + | <span style="color:DarkViolet">total = total + turtle.getItemCount(i)</span> | |
− | <span style="color: | + | <span style="color:DarkCyan">end</span> |
− | <span style="color: | + | <span style="color:DarkCyan">for i=1,16,1 do</span> |
− | + | <span style="color:OrangeRed">print("Row " .. i .. ": " .. turtle.getItemCount(i) .. " (" .. math.floor((turtle.getItemCount(i)/total)*100) .. "%)")</span> | |
− | + | <span style="color:DarkCyan">end</span> | |
− | + | <span style="color:OrangeRed">print("Total: " .. total)</span> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | <span style="color: | + | |
− | + | ||
− | + | ||
− | + | ||
− | <span style="color:OrangeRed">print("Total: " .. | + | |
<span style="color:OrangeRed">print("-----------------")</span> | <span style="color:OrangeRed">print("-----------------")</span> | ||
+ | <span style="color:DarkViolet">local iterator = counter()</span> | ||
<span style="color:OrangeRed">print(" ___ ___ ___ ")</span> | <span style="color:OrangeRed">print(" ___ ___ ___ ")</span> | ||
− | <span style="color:OrangeRed">print("| | + | <span style="color:OrangeRed">print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")</span> |
<span style="color:OrangeRed">print("|___|___|___|")</span> | <span style="color:OrangeRed">print("|___|___|___|")</span> | ||
− | <span style="color:OrangeRed">print("| | + | <span style="color:OrangeRed">print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")</span> |
<span style="color:OrangeRed">print("|---|---|---|")</span> | <span style="color:OrangeRed">print("|---|---|---|")</span> | ||
− | <span style="color:OrangeRed">print("| | + | <span style="color:OrangeRed">print("|" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |" .. modStr(turtle.getItemCount(iterator())) .. " |")</span> |
<span style="color:OrangeRed">print("|___|___|___|")</span> | <span style="color:OrangeRed">print("|___|___|___|")</span> | ||
<span style="color:OrangeRed">print(" ")</span> | <span style="color:OrangeRed">print(" ")</span> | ||
<span style="color:OrangeRed">print("-----------------")</span> | <span style="color:OrangeRed">print("-----------------")</span> | ||
<span style="color:OrangeRed">print("Cobble Farmer")</span> | <span style="color:OrangeRed">print("Cobble Farmer")</span> | ||
− | |||
<span style="color:green">end</span> | <span style="color:green">end</span> | ||
− | <span style="color:DarkViolet">totalcount = turtle.getItemCount( | + | <span style="color:DarkViolet">totalcount = turtle.getItemCount(16)</span> |
<span style="color:green">if totalcount == 64 then</span> | <span style="color:green">if totalcount == 64 then</span> | ||
<span style="color:red">term.clear()</span> | <span style="color:red">term.clear()</span> | ||
Line 113: | Line 113: | ||
<span style="color:OrangeRed">print("...Please wait.")</span> | <span style="color:OrangeRed">print("...Please wait.")</span> | ||
<span style="color:red">sleep(1)</span> | <span style="color:red">sleep(1)</span> | ||
− | <span style="color:DarkCyan">for i=1, | + | <span style="color:DarkCyan">for i=1,16 do</span> |
<span style="color:red">turtle.select(i)</span> | <span style="color:red">turtle.select(i)</span> | ||
<span style="color:red">turtle.drop()</span> | <span style="color:red">turtle.drop()</span> |
Latest revision as of 19:31, 26 January 2013
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
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