Alkerss

TreeFarm

May 26th, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. -- Request for Project: Always revert back to previous selected slot after changing it
  2.  
  3. x=14
  4. z=16
  5. CounterTrees = 0
  6.  
  7. function hugoCutTree()
  8.     CounterTrees = CounterTrees + 1
  9.     turtle.dig()
  10.     turtle.forward()
  11.     turtle.digDown()
  12.     PlaceDownSafe(1)
  13.     local counter = 0
  14.     while turtle.detectUp() do
  15.         turtle.digUp()
  16.         if turtle.up() then counter = counter + 1 end
  17.     end
  18.     while counter > 0 do
  19.         turtle.digDown()
  20.         if turtle.down() then counter = counter - 1 end
  21.     end
  22.     PlaceDownSafe(1)
  23. end
  24.  
  25. function PlaceDownSafe( Min )
  26.     if turtle.getItemCount( 16 ) > Min then
  27.         turtle.placeDown()
  28.         return true
  29.     else
  30.         return false
  31.     end
  32. end
  33.  
  34. function TreeTile()
  35.         turtle.forward()
  36.         turtle.suckDown()
  37. end
  38. function CobbleTile()
  39.     if turtle.detect() then hugoCutTree() else turtle.forward(); PlaceDownSafe(1) end
  40.     turtle.suckDown()
  41. end
  42.  
  43. function Tile()
  44.     if TileSwitch == true then
  45.         TreeTile()
  46.         TileSwitch = false
  47.     else
  48.         CobbleTile()
  49.         TileSwitch = true
  50.     end
  51. end
  52.  
  53. while true do
  54.     --print("Let me chop chop trees!")
  55.     --os.pullEvent("char")
  56.     --print("CHOP CHOP nom nom nom....")
  57.     TileSwitch = false
  58.     statsCountTrees = {}
  59.     turtle.up()
  60.     turtle.turnLeft()
  61.     turtle.select(16) -- Careful!
  62.     Tile()
  63.     --TODO: Reful me, feed me, master!
  64.    
  65.     for i=1,z do
  66.         for j=1,x do Tile() end
  67.  
  68.         if i < z then
  69.             if i%2 == 0 then turtle.turnLeft() else turtle.turnRight() end
  70.             Tile()
  71.             if i%2 == 0 then turtle.turnLeft() else turtle.turnRight() end
  72.         else
  73.             Tile()
  74.             if i%2 == 1 then turtle.turnLeft() else turtle.turnRight() end
  75.             for j=1,z-1 do Tile() end      
  76.         end
  77.     end
  78.  
  79.     turtle.down()
  80.     turtle.turnLeft()
  81.     turtle.turnLeft()
  82.     for i=1,15 do
  83.         turtle.select(i)
  84.         turtle.dropDown()
  85.     end
  86.     turtle.select(16)
  87.     term.clear()
  88.     print("Finished, Master, chopped ", CounterTrees, " trees :)")
  89.     statsCountTrees[table.maxn(statsCountTrees)+1] = CounterTrees
  90.     CounterTrees = 0
  91.     do
  92.         local sum = 0
  93.         local avg = 0
  94.         for i,v in ipairs(statsCountTrees) do sum = sum + v end
  95.         avg = sum / table.maxn(statsCountTrees)
  96.         print("Statistics for you:")
  97.         print("Total: ",sum)
  98.         print("Average: ",avg)
  99.     end
  100.     --print("")
  101.    
  102.     --print("Press anything to pause me in next 10sec...")
  103.     --os.timer(10)
  104.     --local event, param = os.pullEvent()
  105.     --if param < "timer" then
  106.         --print("Paused!!! Press anything to continue...")
  107.         --os.pullEvent()
  108.     --end
  109. end
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. function ReadChest( _Side, ... )
  117. end
Advertisement
Add Comment
Please, Sign In to add comment