Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local length = 27
- local width = 27
- local seedType = "potato"
- local goods = "potato"
- local timeOut = 600
- local holding = 64
- local fuel = {"coal","log"}
- function forward()
- if not turtle.forward() then
- turtle.attack()
- turtle.dig()
- forward()
- end
- end
- function backward()
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- function isGrown()
- s,d = turtle.inspectDown()
- if s then
- if d.state.age == 7 then
- return 2
- else
- return 1
- end
- else
- return 0
- end
- end
- function selectSeed()
- for slot=1,16 do
- turtle.select(tonumber(slot))
- if turtle.getItemCount() ~= 0 then
- if turtle.getItemDetail().name == "minecraft:"..seedType then
- return
- end
- end
- end
- end
- function farmCrop()
- g = isGrown()
- if g==2 then
- turtle.digDown()
- selectSeed()
- turtle.placeDown()
- elseif g==0 then
- selectSeed()
- turtle.placeDown()
- end
- end
- function farmLine()
- farmCrop()
- for i=2,length do
- forward()
- farmCrop()
- end
- for i=2,length do
- backward()
- end
- end
- function farmDoubleLine()
- farmCrop()
- for i=2,length do
- forward()
- farmCrop()
- end
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- farmCrop()
- for i=2,length do
- backward()
- farmCrop()
- end
- end
- function farmAll()
- x = 1
- while true do
- if width-x == 0 then
- farmLine()
- x=x+1
- break
- else
- farmDoubleLine()
- x=x+2
- end
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- end
- turtle.turnLeft()
- for i=2,width do
- backward()
- end
- turtle.turnRight()
- end
- function selectGood()
- for slot=1,16 do
- turtle.select(slot)
- if turtle.getItemCount() ~= 0 then
- if turtle.getItemDetail().name == "minecraft:"..goods then
- return true
- end
- end
- end
- return false
- end
- function storeGoods()
- backward()
- h = 0
- while selectGood() do
- h = h + turtle.getItemCount()
- if h > holding then
- turtle.dropDown()
- end
- end
- print("goods stored")
- forward()
- end
- local fuelPerRotation = width*length + length +width +2
- function isFuel()
- if turtle.getItemCount() ~= 0 then
- item = turtle.getItemDetail().name
- for i=1,#fuel do
- if item == "minecraft:"..fuel[i] then
- return true
- end
- end
- end
- return false
- end
- function refuel()
- if turtle.getFuelLevel() > fuelPerRotation then
- return true
- end
- print("refueling")
- for slot=1,16 do
- turtle.select(slot)
- if isFuel() then
- c = turtle.getItemCount()
- for i=1,c do
- if turtle.getFuelLevel() > fuelPerRotation then
- return
- end
- turtle.refuel(1)
- end
- end
- end
- out = turtle.getFuelLevel() > fuelPerRotation
- return out
- end
- --MAINLOOP--
- while true do
- refuel()
- farmAll()
- storeGoods()
- print("waiting")
- sleep(timeOut)
- end
- print("FarmingProgram-Ended")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement