Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Farm patern:
- chest
- seeds turtle seeds
- dirt seeds dirt
- dirt
- --]]
- function select_next_item(slot, item)
- local data
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and data.name == item then
- turtle.select(slot)
- return true
- end
- slot = slot + 1
- end
- return false
- end
- function repack_item(item)
- local slot = 1
- local data
- while slot < 16 do
- data = turtle.getItemDetail(slot)
- if not data or (data.name == item and data.count < 64) then
- if select_next_item(slot + 1, item) then
- turtle.transferTo(slot)
- data = turtle.getItemDetail(slot)
- else
- return true
- end
- end
- if data and ((data.name == item and data.count == 64) or data.name ~= item) then
- slot = slot + 1
- end
- end
- return true
- end
- function craft_bread()
- local slot = turtle.getSelectedSlot()
- print("Repacking seeds...")
- repack_item("minecraft:wheat_seeds")
- print("Cleaning seeds...")
- clean_seeds()
- print("Repacking wheat...")
- repack_item("minecraft:wheat")
- if turtle.craft() then
- while select_item("minecraft:bread") do
- turtle.dropUp()
- end
- end
- turtle.select(slot)
- end
- function clear_slot(slot)
- local i = turtle.getSelectedSlot()
- if turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- turtle.drop()
- turtle.select(i)
- end
- end
- function clean_seeds()
- local slot = 1
- local first = 0
- local data
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and data.name == "minecraft:wheat_seeds" then
- if first == 0 then
- first = slot
- else
- turtle.select(slot)
- turtle.drop()
- end
- end
- slot = slot + 1
- end
- if first >= 1 and first <= 16 then
- clear_slot(16)
- turtle.select(first)
- turtle.transferTo(16)
- end
- end
- function select_item(item)
- local slot = 1
- while slot <= 16 do
- local data = turtle.getItemDetail(slot)
- if data and data.name == item then
- turtle.select(slot)
- return true
- end
- slot = slot + 1
- end
- return false
- end
- function ble_mature()
- local success, data = turtle.inspectDown()
- if success and data.name == "minecraft:wheat" and data.metadata == 7 then
- return true
- else
- return false
- end
- end
- function select_or_wait_seeds()
- while not select_item("minecraft:wheat_seeds") do
- print("Waiting seeds... retrying in 10 seconds")
- sleep(10)
- end
- end
- function harvest_bottom()
- if ble_mature() then
- turtle.digDown()
- end
- if select_item("minecraft:wheat_seeds") then
- turtle.placeDown()
- end
- end
- function harvest_front()
- local success, data = turtle.inspect()
- if success and data.name == "minecraft:wheat" and data.metadata == 7 then
- turtle.dig()
- end
- if select_item("minecraft:wheat_seeds") then
- turtle.place()
- end
- end
- function select_fuel()
- local slot = 1
- local data = turtle.getItemDetail(slot)
- while slot <= 16 do
- if data and (data.name == "minecraft:lava_bucket" or data.name == "minecraft:coal" or data.name == "minecraft:planks" or data.name == "minecraft:log") then
- break
- end
- slot = slot + 1
- if slot <= 16 then
- turtle.select(slot)
- data = turtle.getItemDetail(slot)
- end
- end
- if (slot > 16) then
- return false
- end
- turtle.select(slot)
- return true
- end
- function check_fuel()
- if turtle.getFuelLevel() < 10 then
- select_fuel()
- while turtle.refuel(1) == false do
- print("Waiting fuel... retrying in 10 seconds")
- sleep(10)
- select_fuel()
- end
- end
- end
- function check_avance()
- local success = false
- check_fuel()
- while success == false do
- check_fuel()
- success = turtle.forward()
- end
- end
- function avance(i)
- local ii =0
- while ii < i do
- check_avance()
- ii = ii + 1
- end
- end
- function recule(i)
- turtle.turnLeft()
- turtle.turnLeft()
- avance(i)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function get_coords()
- local x, y, z = gps.locate(5)
- if not x then
- print("Failed to retreive coordonates. Retrying in 5 seconds")
- sleep(5)
- os.reboot()
- else
- return x, y, z
- end
- end
- function set_direction(x, z)
- local xn, yn, zn
- if turtle.detect() then
- check_fuel()
- while not turtle.back() do
- check_fuel()
- end
- xn, yn, zn = get_coords()
- if x > xn then turtle.turnRight()
- elseif x < xn then turtle.turnLeft()
- elseif z < zn then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- check_avance()
- xn, yn, zn = get_coords()
- if x < xn then turtle.turnRight()
- elseif x > xn then turtle.turnLeft()
- elseif z > zn then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- function absolute(nb)
- if nb >= 0 then
- return nb
- end
- return -nb
- end
- function goto_home(x, z)
- local xmin, xmax, zmin, zmax = -291,-299,547,558 --change this values to corners of your fields
- recule(absolute(z) - absolute(zmin))
- turtle.turnLeft()
- avance(absolute(x) - absolute(xmin))
- turtle.turnRight()
- end
- function drop_wheat_in_turtle()
- if select_item("minecraft:wheat") then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dropUp()
- end
- end
- function parse_field(x, z)
- local xmin, xmax, zmin, zmax = -291,-299,547,558 --change this values to corners of your fields
- while absolute(x) <= absolute(xmax) do
- harvest_bottom()
- check_avance()
- harvest_bottom()
- z = z + 1
- if z >= zmax then
- recule(absolute(absolute(z) - absolute(zmin)))
- turtle.turnRight()
- check_avance()
- turtle.turnLeft()
- z = zmin
- x = x - 1
- end
- end
- goto_home(x, z)
- end
- function number_fuel()
- local i, nb = 1, 0
- local data = turtle.getItemDetail(i)
- while i <= 16 do
- data = turtle.getItemDetail(i)
- if data and (data.name == "minecraft:lava_bucket" or data.name == "minecraft:coal" or data.name == "minecraft:planks" or data.name == "minecraft:log") then
- nb = nb + 1
- end
- i = i + 1
- end
- return nb
- end
- function select_empty()
- local i = 1
- local data = turtle.getItemDetail(i)
- while i <= 16 do
- data = turtle.getItemDetail(i)
- if not data then
- turtle.select(i)
- return true
- end
- i = i + 1
- end
- return false
- end
- function gather_fuel()
- turtle.turnLeft()
- select_empty()
- while not turtle.suck() do
- print("Waiting fuel in chest... Retrying in 20 secs")
- sleep(20)
- end
- turtle.turnRight()
- end
- while true do
- harvest_front()
- turtle.turnLeft()
- harvest_front()
- turtle.turnLeft()
- harvest_front()
- turtle.turnLeft()
- harvest_front()
- turtle.turnLeft()
- harvest_bottom()
- craft_bread()
- print("Job finished. Waiting growing...")
- sleep(150)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement