Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Script Created by CEEBS
- YouTube: https://www.youtube.com/channel/UCQvB8QBknoS1jYgwpYGQrQg
- Twitter: https://twitter.com/OnlyCeebs
- Really appreciate all the support you have given me, so thank you!
- ]]--
- -- Apply constraints
- local FARM_HEIGHT = 7
- local TREE_SPACING = 4
- local TREES_PER_ROW = 4
- local ROWS = 4
- local TIME_BEFORE_SWEEP = 120
- local TIME_BEFORE_NEXT_LOOP = 240
- local INVENTORY_SIZE = 16
- local REFUEL_AMOUNT = 600
- -- Items
- local CHEST = "minecraft:chest"
- local APPLE = "minecraft:apple"
- local STICK = "minecraft:stick"
- local ACCEPTED_FUELS = {
- "minecraft:coal_block",
- "minecraft:charcoal",
- "minecraft:coal"
- }
- local LOGS = {
- "minecraft:oak_log",
- "minecraft:spruce_log",
- "minecraft:birch_log",
- "minecraft:jungle_log",
- "minecraft:acacia_log",
- "minecraft:dark_oak_log",
- }
- local SAPLINGS = {
- "minecraft:oak_sapling",
- "minecraft:spruce_sapling",
- "minecraft:birch_sapling",
- "minecraft:jungle_sapling",
- "minecraft:acacia_sapling",
- "minecraft:dark_oak_sapling",
- }
- -- Movement helper functions
- local function moveForward(times)
- for i = 1, times do
- turtle.forward()
- turtle.suck()
- end
- end
- local function turnLeft(times)
- for i = 1, times do
- turtle.turnLeft()
- end
- end
- local function turnRight(times)
- for i = 1, times do
- turtle.turnRight()
- end
- end
- -- Inventory Sorting
- local function inventorySort()
- -- Group items together
- for j = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(j)
- if currentItem ~= nil then
- turtle.select(j)
- for k = j, INVENTORY_SIZE do
- if turtle.compareTo(k) then
- turtle.select(k)
- turtle.transferTo(j)
- turtle.select(j)
- end
- end
- end
- end
- end
- -- Find items in the turtles inventory and place
- local function findAndPlace(item)
- local success, data, err = turtle.inspect()
- if success then
- if data.name == CHEST then
- -- Find and deposit
- for i = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- if currentItem.name == item then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- end
- end
- local function findAndPlaceAll(items)
- local success, data, err = turtle.inspect()
- if success then
- if data.name == CHEST then
- for i = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- for j = 1, #items do
- if currentItem.name == items[j] then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- end
- end
- end
- -- Refuel
- local function refuel()
- local refuel_successful = false
- for i = 1, INVENTORY_SIZE do
- local current_item = turtle.getItemDetail(i)
- if current_item ~= nil then
- for x = 1, #ACCEPTED_FUELS do
- if current_item.name == ACCEPTED_FUELS[x] then
- turtle.select(i)
- if turtle.refuel() then
- refuel_successful = true
- end
- end
- end
- end
- end
- return refuel_successful
- end
- -- Replant our trees
- local function replant()
- for i = 1, INVENTORY_SIZE do
- local current_item = turtle.getItemDetail(i)
- if current_item ~= nil then
- for x = 1, #SAPLINGS do
- if current_item.name == SAPLINGS[x] then
- turtle.select(i)
- turtle.place()
- end
- end
- end
- end
- end
- -- Chop chop
- local function chop()
- -- Loop through the height of the tree
- for i = 1, FARM_HEIGHT do
- -- Check the block infront of the turtle
- local success, data, err = turtle.inspect()
- -- Block found
- if success then
- local isLog = false
- -- Loop through our defined log table
- for j = 1, #LOGS do
- if data.name == LOGS[j] then
- isLog = true
- break
- end
- end
- -- Check to see if we did indeed find a log, if so - chop
- if isLog then
- turtle.dig()
- else
- -- If the turtle is on the ground level
- if i == 1 then
- return
- end
- end
- else
- -- If the turtle is on the ground level
- if i == 1 then
- replant()
- return
- end
- end
- -- Move the turtle
- if i ~= FARM_HEIGHT then
- while not turtle.up() do
- turtle.digUp()
- end
- end
- end
- -- Decend back down to the ground
- for i = 1, FARM_HEIGHT do
- turtle.down()
- end
- replant()
- end
- -- Sweeping
- local function sweep()
- local spaceBetween = TREE_SPACING - 1
- local rowsWithBuffer = ROWS + 1
- turnLeft(1)
- moveForward(TREE_SPACING)
- turnRight(1)
- for i = 1, rowsWithBuffer do
- for j = 1, spaceBetween do
- moveForward(TREE_SPACING * 4)
- if i % 2 == 0 then
- if j % 2 == 0 then
- turnRight(1)
- moveForward(1)
- if j ~= spaceBetween then
- turnRight(1)
- else
- moveForward(1)
- end
- else
- turnLeft(1)
- moveForward(1)
- if j ~= spaceBetween then
- turnLeft(1)
- else
- moveForward(1)
- end
- end
- else
- if j % 2 == 0 then
- turnLeft(1)
- moveForward(1)
- if j ~= spaceBetween then
- turnLeft(1)
- else
- moveForward(1)
- end
- else
- turnRight(1)
- moveForward(1)
- if j ~= spaceBetween then
- turnRight(1)
- else
- moveForward(1)
- end
- end
- end
- end
- if i ~= rowsWithBuffer then
- if i % 2 == 0 then
- turnLeft(1)
- else
- turnRight(1)
- end
- else
- if i % 2 == 0 then
- -- Handle the case for the turtle finishing on an even amount of sweeps.
- else
- turnRight(1)
- moveForward(TREE_SPACING * 4)
- turnRight(1)
- moveForward(TREE_SPACING * 4)
- turnRight(1)
- end
- end
- end
- end
- -- Deposit items in chests
- local function deposit()
- -- Depoist apples
- turnLeft(1)
- moveForward(3)
- turnLeft(1)
- findAndPlace(APPLE)
- -- Deposit sticks
- turnLeft(1)
- moveForward(1)
- turnRight(1)
- findAndPlace(STICK)
- -- Deposit saplings
- turnLeft(1)
- moveForward(1)
- turnRight(1)
- findAndPlaceAll(SAPLINGS)
- -- Get a stack off saplings for replanting
- turtle.suck()
- -- Deposit logs
- turnLeft(1)
- moveForward(1)
- turnRight(1)
- findAndPlaceAll(LOGS)
- turnLeft(2)
- end
- -- Felling sequence
- local function fellingSequence()
- moveForward(TREE_SPACING - 1)
- -- Loops through the number of rows
- for i = 1, ROWS do
- -- Loop through the number of trees per row
- for j = 1, TREES_PER_ROW do
- -- If the current row is even then - else
- if i % 2 == 0 then
- turnRight(1)
- chop()
- turnLeft(1)
- else
- turnLeft(1)
- chop()
- turnRight(1)
- end
- -- Move between trees
- if j ~= TREES_PER_ROW then
- moveForward(TREE_SPACING)
- end
- end
- -- Are we on the last row?
- if i ~= ROWS then
- -- Is the current row even?
- if i % 2 == 0 then
- moveForward(1)
- turnLeft(1)
- moveForward(TREE_SPACING)
- turnLeft(1)
- moveForward(1)
- else
- moveForward(1)
- turnRight(1)
- moveForward(TREE_SPACING)
- turnRight(1)
- moveForward(1)
- end
- else
- -- Return to starting position
- if i % 2 == 0 then
- moveForward(TREE_SPACING - 1)
- turnRight(1)
- moveForward(TREE_SPACING * (ROWS - 1))
- turnRight(1)
- else
- -- Handle the case of an odd amount of rows
- moveForward(1)
- turnRight(1)
- moveForward(2)
- turnRight(1)
- moveForward(TREE_SPACING * 4)
- turnRight(1)
- moveForward(TREE_SPACING * (ROWS - 1))
- turnRight(1)
- end
- end
- end
- inventorySort()
- sleep(TIME_BEFORE_SWEEP)
- sweep()
- deposit()
- end
- -- Main Loop
- while true do
- if turtle.getFuelLevel() < REFUEL_AMOUNT then
- if not refuel() then
- print("Not enough fuel, terminating...")
- return
- end
- end
- fellingSequence()
- sleep(TIME_BEFORE_NEXT_LOOP)
- end
Advertisement
Add Comment
Please, Sign In to add comment