Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --version:11/21/2024
- os.loadAPI("grey_api/move.lua")
- os.loadAPI("grey_api/util.lua")
- local seconds_to_wait = 60*20
- local wait_first = false
- local minimum_fuel_level = 100
- local log = "minecraft:oak_log"
- local fuel = "minecraft:charcoal"
- local number_of_trees = 8
- local sapling = "minecraft:oak_sapling"
- local unbreakables = {["minecraft:cobblestone"]=true,["minecraft:dirt"]=true,["minecraft:grass_block"]=true,["minecraft:chest"]=true}
- local fuels = {fuel,"minecraft:coal","minecraft:stick",log}
- local fuel_locations = {{0,2,0,2,fuel},{0,0,0,2,log}} --fuel location and log location
- local log_drop_off_height = 0
- local log_drop_off_direction = 2
- local fuel_pick_up_height = 2
- local fuel_pick_up_direction = 2
- local misc_drop_off_height = 1
- local misc_drop_off_direction = 2
- local sapling_drop_off_height = 3
- local sapling_drop_off_direction = 2
- function refuel()
- while turtle.getFuelLevel()<=minimum_fuel_level and util.fuel(1,fuels) do end
- if turtle.getFuelLevel()<=0 then
- print("out of fuel")
- elseif turtle.getFuelLevel()<=minimum_fuel_level then
- print("low on fuel")
- end
- end
- function inspect(dir)
- local b = false
- local block = nil
- if dir=="down" then
- b,block = turtle.inspectDown()
- elseif dir=="up" then
- b,block = turtle.inspectUp()
- else
- b,block = turtle.inspect()
- end
- return b, block
- end --end inspect(dir)
- function dig_all(dir)
- local max = 20
- local current = 0
- local b = false
- local block = nil
- b,block = inspect(dir)
- while current < max do
- if dir=="up" then
- turtle.digUp()
- elseif dir=="down" then
- turtle.digDown()
- else
- turtle.dig()
- end
- current = current + 1
- b,block = inspect(dir)
- if not b then
- --print("dig_all returned true")
- return true
- end
- end
- --print("dig_all returned false")
- return false
- end --end dig_all(dir)
- function recalc_number_of_trees()
- local x = move.get_x()
- if x <= 0 then number_of_trees = 0 end
- number_of_trees = math.ceil((x-1)/3)
- if number_of_trees > 64 then print("Warning: number of trees > 64: "..number_of_trees)
- elseif number_of_trees <= 0 then print("Warning: number of trees <= 0: "..number_of_trees) end
- end
- function chop()
- local chopping = true
- local b,block = false, nil
- local i = 1
- while true do
- chopping = true
- b,block = nil
- print("Chopping...")
- while chopping do
- --find tree
- refuel()
- b,block = turtle.inspect()
- while not b do
- if move.get_y() > 0 then
- move.go("down")
- end
- move.go()
- b,block = turtle.inspect()
- end
- if b and not unbreakables[block["name"]] then
- --print("found block")
- if block["name"]==sapling then
- move.go("up")
- move.go("forward", 2)
- move.go("down", 1)
- else
- chopping = dig_all()
- end
- else
- chopping = false
- end
- end --end while chopping
- move.face(2)
- recalc_number_of_trees()
- refuel()
- print("replanting saplings")
- b,block = turtle.inspect()
- while not b or not unbreakables[block["name"]] do
- --if in place for sapling
- if move.get_x() % 3 == 1 and util.select_item(sapling) then
- move.face(0)
- turtle.place()
- move.face(2)
- end
- if b and block["name"]==sapling then
- move.go("up", 1, true)
- move.go("forward", 2, true)
- move.go("down", 1, true)
- elseif b then
- dig_all()
- end
- move.go()
- b,block = turtle.inspect()
- end
- --drop logs
- move.goto(0,log_drop_off_height,0,log_drop_off_direction)
- for i=1,16 do
- if turtle.getItemCount(i)>0 and turtle.getItemDetail(i)["name"]==log then
- turtle.select(i)
- turtle.drop()
- end
- end
- --drop fuel
- i = 1
- while i <= #fuel_locations do
- if util.select_item(fuel_locations[i][5]) then
- move.goto(fuel_locations[i][1],fuel_locations[i][2],fuel_locations[i][3],fuel_locations[i][4])
- end
- while util.select_item(fuel_locations[i][5]) do
- turtle.drop()
- end
- i = i+1
- end
- --drop saplings
- move.goto(0,sapling_drop_off_height,0,sapling_drop_off_direction)
- for i=1,16 do
- if turtle.getItemCount(i)>0 and turtle.getItemDetail(i)["name"]==sapling then
- turtle.select(i)
- turtle.drop()
- end
- end
- --drop misc
- move.goto(0,misc_drop_off_height,0,misc_drop_off_direction)
- for i=1,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- --pick up fuel
- local fuel_max = 64
- local fuel_needed = fuel_max
- i = 1
- while fuel_needed > 0 and i <= #fuel_locations do
- move.goto(fuel_locations[i][1],fuel_locations[i][2],fuel_locations[i][3],fuel_locations[i][4])
- turtle.suck(fuel_needed)
- fuel_needed = fuel_max - util.count_all_items()
- i = i+1
- end
- if fuel_needed > 0 then
- print("Couldn't find max fuel stores")
- end
- --pick up saplings
- move.goto(0,sapling_drop_off_height,0,sapling_drop_off_direction)
- turtle.suck(number_of_trees)
- --wait until net harvest
- move.goto(0,0,0,0)
- util.wait(seconds_to_wait)
- end --end while true
- end
- if wait_first then util.wait(seconds_to_wait) end
- chop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement