Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Created by Wizard_Alfren--
- --Created on 12 April 2020--
- --Current as of 16 April 2020--
- --This Lua script is for a Farming Turtle--
- --1. Turtle must be 1 block off the ground--
- --2. Turtle will start the farm on the 1st block at ground level in front if it--
- --3. A storage/chest needs to be placed behind the turtle to store the harvest--
- --4. Remember to clear the area of grass/objects--
- --5a. You will be asked for the dimensions of the farm and then the type of seeds to plant--
- --5b. Example: Width: 9 Length: 18 --
- --5c. The turtle's route is (length: 18) forward, and (Width: 9) rows to the right--
- --5d. This script is able to use 1 of 3 types of seeds. (minecraft:wheat_seeds, minecraft:carrot, minecraft:potatoe)--
- --6. Seeds can be placed in the top row of the turtle's inventory (slots 1,2,3,4)--
- --7a. Fuel can be placed in the bottom row of the turtle's inventory (slots 13,14,15,16)--
- --7b. The accepted fuel types are minecraft:coal, railcraft:fuel_coke, ic2:coke--
- function GO()
- term.clear()
- term.setCursorPos(1,1)
- if RUNS == 1 then
- Startup1()
- end
- turtle.forward()
- A = 1
- T = 0
- while T < Width do
- if turtle.getFuelLevel() < 300 then
- FuelCheck()
- end
- term.clear()
- term.setCursorPos(1,4)
- print('Harvesting Row:',T)
- for ii = 1, Length - 1 do
- if Seed_Count < 1 then
- SeedCheck()
- end
- for iii = 0, 1 do
- term.setCursorPos(1,3)
- term.clearLine()
- print('Fuel Level:',turtle.getFuelLevel())
- term.setCursorPos(1,5)
- term.clearLine()
- print('Block:',ii)
- plantORharvest()
- SeedQuantityCheck()
- end
- turtle.forward()
- plantORharvest()
- turtle.suckDown()
- end
- if T < Width - 1 then
- if A == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- A = 3
- end
- if A == 2 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- A = 1
- end
- if A == 3 then
- A = 2
- end
- end
- T = T + 1
- end
- ReturnToStart()
- DepositeItems()
- Reset()
- RUNS = RUNS + 1
- GO()
- end
- ---------------------------------------
- function Startup1()
- term.clear()
- term.setCursorPos(1,1)
- print('SEEDS: Top 4 slots.\nFUEL: Bottom 4 slots.\n')
- print('1. Start me 1 block off the ground.\n The farm starts in front of me.\n')
- print('2. Place a chest behind me so I can\n store the harvest.\n')
- print('3. Don\'t forget to clear the land.\n')
- print('Press ENTER to continue..')
- io.read()
- Startup2()
- end
- ---------------------------------------
- function Startup2()
- term.clear()
- term.setCursorPos(1,1)
- print('---Farm Size Options---\nType farm dimensions and press ENTER\n')
- print('Length (forward) x Width (Right)')
- print('Example: 18x9\n\nWidth: ')
- Width_Input = io.read()
- Width_Input = tonumber(Width_Input)
- print('\nLength:')
- Length_Input = io.read()
- Length_Input = tonumber(Length_Input)
- -- logic --
- if type(Width_Input) == 'number' and type(Length_Input) == 'number' then
- Width = Width_Input
- Length = Length_Input
- else
- print('\n\n\nUm.. try again..')
- sleep(2)
- Startup2()
- end
- Startup3()
- end
- ---------------------------------------
- function Startup3()
- term.clear()
- term.setCursorPos(1,1)
- print('---Plant Options---\nSelect (1, 2, or 3) and press ENTER\n')
- print('1: Wheat\n2: Potatoes\n3: Carrots\n\n')
- PLANT_NAME = io.read()
- -- logic --
- if PLANT_NAME == '1' then
- PLANT = 'minecraft:wheat'
- PLANT_TEXT = 'Wheat'
- PLANT_SEED = 'minecraft:wheat_seeds'
- elseif PLANT_NAME == '2' then
- PLANT = 'minecraft:potatoe_seeds'
- PLANT_TEXT = 'Potatoes'
- PLANT_SEED = 'minecraft:potato'
- elseif PLANT_NAME == '3' then
- PLANT = 'minecraft:carrots'
- PLANT_TEXT = 'Carrot'
- PLANT_SEED = 'minecraft:carrot'
- else
- print('\n\n\nPlease Try Again..')
- sleep(2)
- Startup3()
- end
- term.clear()
- term.setCursorPos(1,6)
- print(Width_Input..'x'..Length_Input,PLANT_TEXT,'farm!\n\nHere We Go!')
- sleep(2)
- SeedCheck()
- end
- ---------------------------------------
- function SeedQuantityCheck()
- Seed_Slot_Count = {turtle.getItemCount(1),turtle.getItemCount(2),turtle.getItemCount(3),turtle.getItemCount(4)}
- Seed_Count = 0
- for S = 1, 4 do
- if Seed_Slot_Count[S] > 0 then
- if turtle.getItemDetail(S).name == PLANT_SEED then
- turtle.select(S)
- Seed_Count = Seed_Count + Seed_Slot_Count[S]
- S = S + 1
- end
- end
- if Seed_Slot_Count[S] > 0 then
- break
- end
- end
- end
- ---------------------------------------
- function SeedCheck()
- SeedQuantityCheck()
- if Seed_Count < 1 then
- while Seed_Count < 1 do
- SeedQuantityCheck()
- if Seed_Count > 0 then
- else
- term.clear()
- term.setCursorPos(1,5)
- print('Detecting seeds..\n\nSeed count:',Seed_Count,'\n\nWaiting for more seeds..')
- sleep(1)
- end
- end
- else
- term.clear()
- term.setCursorPos(1,5)
- end
- end
- ---------------------------------------
- function FuelCheck()
- Fuel_Slot_Count = {turtle.getItemCount(13),turtle.getItemCount(14),turtle.getItemCount(15),turtle.getItemCount(16)}
- Fuel_Count = 0
- for f = 1, 4 do
- if Fuel_Slot_Count[f] > 0 then
- Temp = turtle.getItemDetail(12+f).name
- if Temp == Fuel_Types[1] or Temp == Fuel_Types[2] or Temp == Fuel_Types[3] then
- Fuel_Count = Fuel_Count + Fuel_Slot_Count[f]
- term.clear()
- term.setCursorPos(1,1)
- print('Total Fuel Item(s):',Fuel_Count)
- end
- end
- f = f + 1
- end
- term.clear()
- term.setCursorPos(1,1)
- if Fuel_Count > 0 then
- for F = 1, 4 do
- while turtle.getFuelLevel() < 300 do
- if Fuel_Slot_Count[F] > 0 then
- Temp = turtle.getItemDetail(F+12).name
- if Temp == Fuel_Types[1] or Temp == Fuel_Types[2] or Temp == Fuel_Types[3] then
- turtle.select(F+12)
- turtle.refuel(2)
- end
- end
- end
- if turtle.getFuelLevel() > 300 then
- break
- end
- end
- else
- term.setCursorPos(1,5)
- term.clearLine()
- print("Waiting for fuel... Slot(s) 13-16\n(Coal, Charcoal, Coal Coke)")
- sleep(1)
- end
- SeedQuantityCheck()
- end
- ---------------------------------------
- function plantORharvest()
- local success, inspectDown = turtle.inspectDown()
- if success then
- if inspectDown.name == PLANT and inspectDown.state.age == 7 then
- turtle.placeDown()
- turtle.placeDown()
- turtle.suckDown()
- turtle.suckDown()
- end
- elseif not success then
- turtle.digDown()
- Seed_Count = Seed_Count - 1
- turtle.placeDown()
- turtle.placeDown()
- turtle.suckDown()
- turtle.suckDown()
- end
- end
- ---------------------------------------
- function ReturnToStart()
- if (Width % 2) == 1 then
- turtle.turnRight()
- turtle.turnRight()
- for Z = 1, Length do
- turtle.forward()
- end
- turtle.turnRight()
- for Z = 1, Width - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- else
- turtle.forward()
- turtle.turnRight()
- for Z = 1, Width - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- ---------------------------------------
- function DepositeItems()
- II = 1
- while II ~= 17 do
- if turtle.getItemCount(II) > 0 then
- II_name = turtle.getItemDetail(II).name
- if II_name ~= PLANT_SEED and II_name ~= Fuel_Types[1] and II_name ~= Fuel_Types[2] and II_name ~= Fuel_Types[3] then
- turtle.select(II)
- turtle.drop()
- elseif II > 4 and II < 13 then
- turtle.select(II)
- turtle.drop()
- end
- end
- II = II + 1
- end
- end
- ---------------------------------------
- function Reset()
- turtle.turnRight()
- turtle.turnRight()
- term.clear()
- term.setCursorPos(1,1)
- print("Sleeping for 30 mins...\nFuel Level:",turtle.getFuelLevel(),"\n\nI've gone out",RUNS,"times!")
- sleep(1800)
- end
- ---------------------------------------
- Fuel_Types = {'minecraft:coal','railcraft:fuel_coke','ic2:coke'}
- RUNS = 1
- GO()
Add Comment
Please, Sign In to add comment