Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- This script farms potatoes (other crops if you modify singleHarvest()) in the pattern of
- -- a Hilbert curve of the second order.
- --
- -- It looks like this:
- -- x: air with water for the farm undearneath
- -- <: the starting position of the turtle (facing into the cobblestone)
- -- C: a block of cobblestone as a marker for when the turtle is done with one round
- -- : farmblock
- --
- -- xxxx xxxx
- -- x x x x
- -- x x x x
- -- x xxxx x
- -- x x
- -- x x
- -- xxxx xxxx
- -- x x
- -- x x
- --C<xxx xxxx
- --
- local function isBlock(block)
- local found_block, block_data = turtle.inspect();
- if found_block then
- if block_data["name"] == block then
- return true;
- end
- end
- return false;
- end
- local function tableContains(table, needle)
- for key, value in pairs(table) do
- if key == needle then
- return true;
- end
- end
- return false;
- end
- local function isCrop()
- local found_block, block_data = turtle.inspect();
- if found_block then
- if tableContains(block_data["tags"], "minecraft:crops") then
- return true;
- end
- end
- return false;
- end
- local function isGrown()
- local found_block, block_data = turtle.inspect();
- if found_block then
- if tableContains(block_data["tags"], "minecraft:crops") then
- if block_data["state"]["age"] == 7 then
- return true;
- end
- end
- end
- return false;
- end
- local function itemIndex(item_name)
- for i = 1, 16, 1 do
- local details = turtle.getItemDetail(i)
- if details ~= nil then
- if details["name"] == item_name then
- return i
- end
- end
- end
- return 1 -- FIXME not great, since this is an invalid return
- end
- local function harvestSingle()
- turtle.suck()
- if isGrown() then
- turtle.dig()
- turtle.select(itemIndex("minecraft:potato"))
- turtle.place();
- end
- end
- local function moveRight()
- harvestSingle();
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- local function forwardTurnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- local function firstHalfSmallLoop()
- for i = 1, 3, 1 do
- moveRight()
- end
- for i = 1, 2, 1 do
- forwardTurnLeft()
- for j = 1, 2, 1 do
- moveRight()
- end
- end
- turtle.turnRight()
- end
- local function firstHalflongStretchA()
- for i = 1, 6, 1 do
- moveRight()
- end
- turtle.turnRight()
- for i = 1, 3, 1 do
- moveRight()
- end
- turtle.turnRight()
- end
- local function firstHalflongStretchB()
- for i = 1, 3, 1 do
- moveRight()
- end
- turtle.turnRight()
- for i = 1, 6, 1 do
- moveRight()
- end
- turtle.turnRight()
- end
- local function firstHalf()
- firstHalfSmallLoop()
- firstHalflongStretchA()
- firstHalfSmallLoop()
- firstHalflongStretchB()
- firstHalfSmallLoop()
- end
- local function secondHalfShortLoop()
- for i = 1, 2, 1 do
- turtle.turnRight()
- for j = 1, 3, 1 do
- moveRight()
- end
- end
- end
- local function secondHalfLongStretchA()
- forwardTurnLeft()
- for i = 1, 5, 1 do
- moveRight()
- end
- for i = 1, 2, 1 do
- forwardTurnLeft()
- for j = 1, 2, 1 do
- moveRight()
- end
- end
- end
- local function secondHalfLongStretchB()
- forwardTurnLeft()
- for i = 1, 2, 1 do
- moveRight()
- end
- forwardTurnLeft()
- for i = 1, 5, 1 do
- moveRight()
- end
- forwardTurnLeft()
- for i = 1, 2, 1 do
- moveRight()
- end
- end
- local function secondHalf()
- secondHalfShortLoop()
- turtle.turnRight()
- for i = 1, 3, 1 do
- moveRight()
- end
- secondHalfLongStretchA()
- secondHalfShortLoop()
- secondHalfLongStretchB()
- secondHalfShortLoop()
- end
- local function harvest()
- term.setCursorPos(1, 4)
- term.write("Harvesting...")
- firstHalf()
- secondHalf()
- turtle.turnRight() -- Turn back to the starting block
- end
- local function printSleep(number)
- local seconds_remaining = number
- while seconds_remaining > 0 do
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write("Sleeping for " .. seconds_remaining .. "...")
- sleep(5)
- seconds_remaining = seconds_remaining - 5
- end
- term.setCursorPos(1, 2)
- term.write("Done sleeping.")
- end
- local function main()
- while true do
- term.clear()
- if isBlock("minecraft:cobblestone") then
- turtle.turnRight();
- harvest();
- end
- printSleep(60)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement