Advertisement
Greyman27

chop_modded

Nov 21st, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.19 KB | None | 0 0
  1. --version:11/21/2024
  2.  
  3. os.loadAPI("grey_api/move.lua")
  4. os.loadAPI("grey_api/util.lua")
  5.  
  6. local seconds_to_wait = 60*20
  7. local wait_first = false
  8. local minimum_fuel_level = 100
  9. local log = "minecraft:oak_log"
  10. local fuel = "minecraft:charcoal"
  11. local number_of_trees = 8
  12. local sapling = "minecraft:oak_sapling"
  13. local unbreakables = {["minecraft:cobblestone"]=true,["minecraft:dirt"]=true,["minecraft:grass_block"]=true,["minecraft:chest"]=true}
  14. local fuels = {fuel,"minecraft:coal","minecraft:stick",log}
  15. local fuel_locations = {{0,2,0,2,fuel},{0,0,0,2,log}} --fuel location and log location
  16. local log_drop_off_height = 0
  17. local log_drop_off_direction = 2
  18. local fuel_pick_up_height = 2
  19. local fuel_pick_up_direction = 2
  20. local misc_drop_off_height = 1
  21. local misc_drop_off_direction = 2
  22. local sapling_drop_off_height = 3
  23. local sapling_drop_off_direction = 2
  24.  
  25. function refuel()
  26.     while turtle.getFuelLevel()<=minimum_fuel_level and util.fuel(1,fuels) do end
  27.     if turtle.getFuelLevel()<=0 then
  28.         print("out of fuel")
  29.     elseif turtle.getFuelLevel()<=minimum_fuel_level then
  30.         print("low on fuel")
  31.     end
  32. end
  33.  
  34. function inspect(dir)
  35.     local b = false
  36.     local block = nil
  37.     if dir=="down" then
  38.         b,block = turtle.inspectDown()
  39.     elseif dir=="up" then
  40.         b,block = turtle.inspectUp()
  41.     else
  42.         b,block = turtle.inspect()
  43.     end
  44.     return b, block
  45. end --end inspect(dir)
  46.  
  47. function dig_all(dir)
  48.     local max = 20
  49.     local current = 0
  50.     local b = false
  51.     local block = nil
  52.    
  53.     b,block = inspect(dir)
  54.     while current < max do
  55.         if dir=="up" then
  56.             turtle.digUp()
  57.         elseif dir=="down" then
  58.             turtle.digDown()
  59.         else
  60.             turtle.dig()
  61.         end
  62.         current = current + 1
  63.         b,block = inspect(dir)
  64.         if not b then
  65.             --print("dig_all returned true")
  66.             return true
  67.         end
  68.     end
  69.     --print("dig_all returned false")
  70.     return false
  71. end --end dig_all(dir)
  72.  
  73. function recalc_number_of_trees()
  74.     local x = move.get_x()
  75.     if x <= 0 then number_of_trees = 0 end
  76.     number_of_trees = math.ceil((x-1)/3)
  77.     if number_of_trees > 64 then print("Warning: number of trees > 64: "..number_of_trees)
  78.     elseif number_of_trees <= 0 then print("Warning: number of trees <= 0: "..number_of_trees) end
  79. end
  80.  
  81.  
  82. function chop()
  83.     local chopping = true
  84.     local b,block = false, nil
  85.     local i = 1
  86.     while true do
  87.         chopping = true
  88.         b,block = nil
  89.         print("Chopping...")
  90.         while chopping do
  91.             --find tree
  92.             refuel()
  93.             b,block = turtle.inspect()
  94.             while not b do
  95.                 if move.get_y() > 0 then
  96.                     move.go("down")
  97.                 end
  98.                 move.go()
  99.                 b,block = turtle.inspect()
  100.             end
  101.             if b and not unbreakables[block["name"]] then
  102.                --print("found block")
  103.                 if block["name"]==sapling then
  104.                     move.go("up")
  105.                     move.go("forward", 2)
  106.                     move.go("down", 1)
  107.                 else
  108.                     chopping = dig_all()
  109.                 end
  110.             else
  111.                 chopping = false
  112.             end
  113.         end --end while chopping
  114.            
  115.         move.face(2)
  116.         recalc_number_of_trees()
  117.         refuel()
  118.         print("replanting saplings")
  119.         b,block = turtle.inspect()
  120.         while not b or not unbreakables[block["name"]] do
  121.             --if in place for sapling
  122.             if move.get_x() % 3 == 1 and util.select_item(sapling) then
  123.                 move.face(0)
  124.                 turtle.place()
  125.                 move.face(2)
  126.             end
  127.            
  128.             if b and block["name"]==sapling then
  129.                 move.go("up", 1, true)
  130.                 move.go("forward", 2, true)
  131.                 move.go("down", 1, true)
  132.             elseif b then
  133.                 dig_all()
  134.             end
  135.             move.go()
  136.             b,block = turtle.inspect()
  137.         end
  138.        
  139.         --drop logs
  140.         move.goto(0,log_drop_off_height,0,log_drop_off_direction)
  141.         for i=1,16 do
  142.             if turtle.getItemCount(i)>0 and turtle.getItemDetail(i)["name"]==log then
  143.                 turtle.select(i)
  144.                 turtle.drop()
  145.             end
  146.         end
  147.        
  148.         --drop fuel
  149.         i = 1
  150.         while i <= #fuel_locations do
  151.             if util.select_item(fuel_locations[i][5]) then
  152.                 move.goto(fuel_locations[i][1],fuel_locations[i][2],fuel_locations[i][3],fuel_locations[i][4])
  153.             end
  154.             while util.select_item(fuel_locations[i][5]) do
  155.                 turtle.drop()
  156.             end
  157.            
  158.             i = i+1
  159.         end
  160.        
  161.         --drop saplings
  162.         move.goto(0,sapling_drop_off_height,0,sapling_drop_off_direction)
  163.         for i=1,16 do
  164.             if turtle.getItemCount(i)>0 and turtle.getItemDetail(i)["name"]==sapling then
  165.                 turtle.select(i)
  166.                 turtle.drop()
  167.             end
  168.         end
  169.        
  170.         --drop misc
  171.         move.goto(0,misc_drop_off_height,0,misc_drop_off_direction)
  172.         for i=1,16 do
  173.             if turtle.getItemCount(i)>0 then
  174.                 turtle.select(i)
  175.                 turtle.drop()
  176.             end
  177.         end
  178.        
  179.         --pick up fuel
  180.         local fuel_max = 64
  181.         local fuel_needed = fuel_max
  182.         i = 1
  183.         while fuel_needed > 0 and i <= #fuel_locations do
  184.             move.goto(fuel_locations[i][1],fuel_locations[i][2],fuel_locations[i][3],fuel_locations[i][4])
  185.             turtle.suck(fuel_needed)
  186.             fuel_needed = fuel_max - util.count_all_items()
  187.            
  188.             i = i+1
  189.         end
  190.         if fuel_needed > 0 then
  191.             print("Couldn't find max fuel stores")
  192.         end
  193.        
  194.         --pick up saplings
  195.         move.goto(0,sapling_drop_off_height,0,sapling_drop_off_direction)
  196.         turtle.suck(number_of_trees)
  197.        
  198.         --wait until net harvest
  199.         move.goto(0,0,0,0)
  200.         util.wait(seconds_to_wait)
  201.     end --end while true
  202. end
  203.  
  204. if wait_first then util.wait(seconds_to_wait) end
  205. chop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement