Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local coalSide = "left"
- local saplingSide = "right"
- -- More Settings
- local fuelSlot = 15
- local saplingSlot = 16
- local travelDistance = 16
- local dirtQuantity = 4
- -- Directionality Stuff
- local facing = 2
- local function getFacing(f)
- if f == nil then f = facing end
- if f == 0 then return "north" end
- if f == 1 then return "east" end
- if f == 2 then return "south" end
- return "west"
- end
- local function getDirectionForSide(side)
- local offset = 0
- if side == "right" then offset = 1 end
- if side == "back" then offset = 2 end
- if side == "left" then offset = 3 end
- local f = facing + offset
- if f > 4 then f = f - 4 end
- return getFacing(f)
- end
- local function turnLeft(count)
- if count == nil then count = 1 end
- for i=1,count do
- if turtle.turnLeft() then
- facing = facing - 1
- if facing < 1 then facing = facing + 4 end
- end
- end
- return facing
- end
- local function turnRight(count)
- if count == nil then count = 1 end
- for i=1,count do
- if turtle.turnRight() then
- facing = facing + 1
- if facing > 4 then facing = facing - 4 end
- end
- end
- return facing
- end
- local function forward(count)
- if count == nil then count = 1 end
- for i=1,count do
- if not turtle.forward() then
- error("Could not move.")
- end
- end
- end
- local function up(count)
- if count == nil then count = 1 end
- for i=1,count do
- if not turtle.up() then
- error("Could not move.")
- end
- end
- end
- local function down(count)
- if count == nil then count = 1 end
- for i=1,count do
- if not turtle.down() then
- error("Could not move.")
- end
- end
- end
- local function getOpposite(side)
- if side == "north" then return "south" end
- if side == "east" then return "west" end
- if side == "south" then return "north" end
- if side == "west" then return "east" end
- if side == "up" then return "down" end
- return "up"
- end
- local select = turtle.select
- local placeDown = turtle.placeDown
- -- Inventory Management
- local function getFromContainer(side, slot, quantity)
- peripheral.call(side, "pushItem", getOpposite(getDirectionForSide(side)), 1, quantity, slot)
- end
- local function getFuel()
- print("Checking fuel...")
- if turtle.getFuelLevel() < travelDistance then
- print("Refueling.")
- getFromContainer(coalSide, fuelSlot, 1)
- select(fuelSlot)
- turtle.refuel(1)
- select(1)
- end
- end
- local function getSapling()
- print("Checking saplings...")
- local count = turtle.getItemCount(saplingSlot)
- if count < 4 then
- print("Getting saplings.")
- getFromContainer(saplingSide, saplingSlot, 4-count)
- end
- end
- -- Plant Saplings
- local function plant()
- print("Planting...")
- turnRight(2)
- forward(4)
- -- Place Dirt
- select(1)
- placeDown()
- forward()
- placeDown()
- turnRight()
- forward()
- placeDown()
- turnRight()
- forward()
- placeDown()
- -- Place Saplings
- select(saplingSlot)
- turnRight(2)
- up()
- placeDown()
- forward()
- placeDown()
- turnLeft()
- forward()
- placeDown()
- turnLeft()
- forward()
- placeDown()
- -- Return to Start
- forward(4)
- down()
- select(1)
- end
- -- The Loop
- print("Getting started...")
- while true do
- print("Waiting for inventory event...")
- local event, p1 = os.pullEvent("turtle_inventory")
- if turtle.getItemCount(1) == dirtQuantity then
- print("Found a tree! Sleeping...")
- -- Time to Harvest
- sleep(15)
- -- Now, Work
- getFuel()
- getSapling()
- plant()
- else
- print("Not what we wanted.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement