Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- JC magical crops farming script for 7x7 areas
- farmsize = 7
- requiredFuel = 64 --how much fuel you need for a run 7x7+7x2 plus some extra
- inverted = false --if you want to start on the right corner instead
- fullyGrown = 7 --the meta data value when the plant is fully grown
- cropType = "magicalcrops"
- seedType = "MinicioSee"
- function getFreeSlot()
- local cacheSlot = turtle.getSelectedSlot() --so we can jump back to it afterwards
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemDetail() == nil then
- print("GetFreeSlot Returned " .. i)
- turtle.select(cacheSlot)
- return i
- end
- end
- turtle.select(cacheSlot)
- return false
- end
- function getSeeds()
- turtle.select(1)
- if turtle.getItemDetail() ~= nil then
- if string.find(turtle.getItemDetail().name, seedType) then
- return
- else
- local slo = getFreeSlot()
- turtle.select(1)
- print("moving " .. turtle.getSelectedSlot() .. "to:" .. slo)
- turtle.transferTo(tonumber(slo))
- end
- end
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemDetail() ~= nil then
- print(turtle.getItemDetail().name)
- if string.find(turtle.getItemDetail().name, seedType) then
- turtle.transferTo(1)
- turtle.select(1)
- break
- end
- end
- end
- turtle.select(1)
- end
- function checkDig()
- found, data = turtle.inspectDown()
- if found then
- if string.find(data.name, cropType) then --if its the right kind of plant
- if data.metadata == fullyGrown then --if it's fully grown
- turtle.digDown() --dig it up
- getSeeds()
- turtle.placeDown()
- end
- --if its the right kind of crop but its not fully grown then dont do anything
- else
- --if its not the right kind of plant
- turtle.digDown()
- getSeeds()
- turtle.placeDown()
- end
- else
- --if there is nothing under us
- turtle.digDown()
- getSeeds()
- turtle.placeDown()
- end
- end
- function moveAndHarvest(num)
- for i=1,num do
- checkDig()
- turtle.forward()
- checkDig()
- end
- end
- function rightTurn()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- function leftTurn()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- function run(lenght)
- local switch = true
- for i=1,lenght do
- moveAndHarvest(lenght-1)
- if i == lenght then break end --dont countinu after this point if its the last row
- if switch then
- if inverted then
- leftTurn()
- else
- rightTurn()
- end
- switch = false
- else
- if inverted then
- rightTurn()
- else
- leftTurn()
- end
- switch = true
- end
- end
- if switch then
- turtle.turnRight()
- turtle.turnRight()
- for i=1,lenght-1 do
- turtle.forward()
- end
- end
- if inverted then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for i=1,lenght-1 do
- turtle.forward()
- end
- if inverted then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function dumpThings()
- for i=2,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- function reFuel()
- turtle.select(16)
- turtle.suckUp()
- turtle.refuel()
- turtle.select(1)
- end
- if turtle.getFuelLevel() < requiredFuel then
- print("trying to refuel")
- reFuel()
- end
- if turtle.getFuelLevel() > requiredFuel then
- print("Starting")
- while turtle.getFuelLevel() > requiredFuel do
- getSeeds()
- turtle.forward()
- run(farmsize)
- turtle.back()
- dumpThings()
- print("Current Fuel:" .. turtle.getFuelLevel())
- if turtle.getFuelLevel() < requiredFuel then
- print("Trying to refuel")
- reFuel()
- end
- end
- print("ran out of fuel")
- else
- print("I dont have enough fuel")
- print("I need: " .. tostring(requiredFuel))
- print("I have: " .. tostring(turtle.getFuelLevel()))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement