Alkerss

TreeFarm + Charcoal Use

Jul 16th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 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.turnLeft()
  60.     turtle.turnLeft()
  61.     turtle.select(1)
  62.     turtle.suck(64)
  63.     turtle.refuel(64)
  64.     turtle.turnLeft()
  65.     turtle.turnLeft()
  66.     turtle.up()
  67.     turtle.turnLeft()
  68.     turtle.select(16) -- Careful!
  69.     Tile()
  70.     --TODO: Reful me, feed me, master! (CHECK)
  71.    
  72.     for i=1,z do
  73.         for j=1,x do Tile() end
  74.  
  75.         if i < z then
  76.             if i%2 == 0 then turtle.turnLeft() else turtle.turnRight() end
  77.             Tile()
  78.             if i%2 == 0 then turtle.turnLeft() else turtle.turnRight() end
  79.         else
  80.             Tile()
  81.             if i%2 == 1 then turtle.turnLeft() else turtle.turnRight() end
  82.             for j=1,z-1 do Tile() end      
  83.         end
  84.     end
  85.  
  86.     turtle.down()
  87.     turtle.turnLeft()
  88.     turtle.turnLeft()
  89.     for i=1,15 do
  90.         turtle.select(i)
  91.         turtle.dropDown()
  92.     end
  93.     turtle.select(16)
  94.     term.clear()
  95.     print("Finished, Master, chopped ", CounterTrees, " trees :)")
  96.     statsCountTrees[table.maxn(statsCountTrees)+1] = CounterTrees
  97.     CounterTrees = 0
  98.     do
  99.         local sum = 0
  100.         local avg = 0
  101.         for i,v in ipairs(statsCountTrees) do sum = sum + v end
  102.         avg = sum / table.maxn(statsCountTrees)
  103.         print("Statistics for you:")
  104.         print("Total: ",sum)
  105.         print("Average: ",avg)
  106.         print("Fuel: ",turtle.getFuelLevel())
  107.     end
  108.     --print("")
  109.    
  110.     --print("Press anything to pause me in next 10sec...")
  111.     --os.timer(10)
  112.     --local event, param = os.pullEvent()
  113.     --if param < "timer" then
  114.         --print("Paused!!! Press anything to continue...")
  115.         --os.pullEvent()
  116.     --end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment