Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --By xXxMoNkEyMaNxXx
- --Designed for a 2xN melon farm
- --Put the turtle on the right ride facing the farm
- --Put a chest of fuel to the right of the turtle
- --Put a chest for melons behind the turtle
- local tick=os.clock
- local ceil=math.ceil
- local floor=math.floor
- local max=math.max
- local min=math.min
- local interval=2*60
- local efficiency=0.5 --wait for 50% of melons to grow before harvesting
- local probability=1/(1+floor(25/(2*0.75)))
- local wait=math.log(1-efficiency)/(20*math.log(1-probability*3/(16*16*16)))
- local farm_len=...
- local s=1
- turtle.select(s)
- local function unload()
- if turtle.detect() then
- for i=1,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- local function getRealFuel()
- local f=turtle.getFuelLevel()
- return type(f)=="number" and f or math.huge
- end
- local function fillTo(req,slot)
- turtle.select(slot)
- local ret
- local i=0
- local f_0=getRealFuel()
- print("Fuel: "..f_0)
- print("Required: "..req)
- if f_0<req then
- if turtle.detect() then
- print'Refuelling...'
- local t=1
- while turtle.getItemCount(t)>0 and t<=16 do
- t=t+1
- end
- if t<=16 and turtle.select(t) then
- while getRealFuel()<req and turtle.suck() do
- local f0=getRealFuel()
- local i0=turtle.getItemSpace(t)
- assert(turtle.refuel(1),"That's not fuel!")
- local f1=getRealFuel()
- local i1=turtle.getItemSpace(t)
- local df,di=f1-f0,i1-i0
- local rate=df/di
- local f_req=ceil((req-f1)/rate)
- local c=turtle.getItemCount(t)
- if c>0 then
- assert(turtle.refuel(min(max(0,f_req),c)),"That's not fuel!")
- end
- i=i+turtle.getItemSpace(t)-i0
- local c=turtle.getItemCount(t)
- if c>0 then
- if turtle.drop(c) then
- break
- else
- turtle.turnRight()
- turtle.turnRight()
- turtle.drop(c)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- end
- turtle.select(s)
- local f_1=getRealFuel()
- print("Gained "..f_1-f_0.." fuel from "..i.." fuel items.")
- ret=f_1>=req
- else
- print'Unable to refuel.\n(No room in the turtle)'
- ret=false
- end
- end
- turtle.select(slot)
- else
- ret=true
- end
- turtle.select(s)
- return ret
- end
- local unfirst=false
- turtle.turnRight()
- local runs=0
- local fuel=fillTo(2*(farm_len or 2^runs)+2,1)
- local start
- while fuel do
- turtle.turnLeft()
- --while farm_len and not turtle.detect() do sleep(1) end
- if unfirst then
- local delay=wait+start-tick()
- if delay>0 then
- local show_delay=floor(delay*10)/10
- print("Waiting "..show_delay.." second"..(show_delay==1 and "" or "s")..".")
- sleep(delay%interval)
- for d=floor(delay/interval),1,-1 do
- print("Harvesting in "..(d*interval/60).." min.")
- sleep(interval)
- end
- end
- else
- unfirst=true
- end
- start=tick()
- local distance=0
- while farm_len and distance<farm_len or turtle.detectDown() and distance+3<getRealFuel() do
- if turtle.getItemSpace(s)>0 then
- if turtle.detect() then
- turtle.dig()
- end
- if turtle.forward() then
- distance=distance+1
- end
- elseif s==16 then
- error'TOO MUCH WATERMELON FUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'
- unload(2)
- s=2
- turtle.select(2)
- else
- s=s+1
- turtle.select(s)
- end
- end
- if not turtle.detectDown() then
- farm_len=distance-1
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- local d=distance
- while d>0 do
- if turtle.getItemSpace(s)>0 then
- if turtle.detect() then
- turtle.dig()
- end
- if turtle.forward() then
- d=d-1
- end
- elseif s==16 then
- error'TOO MUCH WATERMELON FUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'
- unload(2)
- s=2
- turtle.select(2)
- else
- s=s+1
- turtle.select(s)
- end
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- unload()
- turtle.turnLeft()
- runs=runs+1
- if farm_len then
- fuel=fillTo(2*farm_len+2,1)
- else
- fuel=fillTo(2*2^runs+2,1)
- end
- end
- turtle.turnLeft()
- print'Out of fuel.'
Advertisement
Add Comment
Please, Sign In to add comment