Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wheat Harvester + Instant Replanter Turtle
- -- For ComputerCraft / CC:Tweaked
- --
- -- Setup:
- -- Turtle starts 1 block above the wheat crop space.
- -- Turtle faces forward down the first row.
- -- Chest is directly behind the turtle's starting position.
- -- Infinite fuel is enabled.
- --
- -- New boundary rule:
- -- Air below = valid farm space.
- -- Wheat below = valid farm space.
- -- Cobblestone/slabs below = ignored water cover.
- -- Any other detected block below = border/barrier/end of row.
- --------------------------------------------------
- -- CONFIG
- --------------------------------------------------
- local CHECK_DELAY = 60
- local SEEDS_TO_KEEP = 64
- local CHEST_PULL_ATTEMPTS = 8
- local ENABLE_CHEST_SEED_PULL = true
- local PLANT_EMPTY_SPOTS = true
- --------------------------------------------------
- -- POSITION TRACKING
- --------------------------------------------------
- -- x = sideways from start
- -- y = forward/back from start
- -- dir:
- -- 0 = starting forward
- -- 1 = right
- -- 2 = backward
- -- 3 = left
- local x, y, dir = 0, 0, 0
- --------------------------------------------------
- -- BASIC HELPERS
- --------------------------------------------------
- local function log(msg)
- print("[WheatBot] " .. msg)
- end
- local function updateForward()
- if dir == 0 then
- y = y + 1
- elseif dir == 1 then
- x = x + 1
- elseif dir == 2 then
- y = y - 1
- elseif dir == 3 then
- x = x - 1
- end
- end
- local function updateBack()
- if dir == 0 then
- y = y - 1
- elseif dir == 1 then
- x = x - 1
- elseif dir == 2 then
- y = y + 1
- elseif dir == 3 then
- x = x + 1
- end
- end
- local function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- local function turnLeft()
- turtle.turnLeft()
- dir = (dir + 3) % 4
- end
- local function face(targetDir)
- while dir ~= targetDir do
- turnRight()
- end
- end
- local function forward()
- while not turtle.forward() do
- -- Do not put your border wall at turtle height,
- -- or the turtle will try to dig it.
- turtle.dig()
- sleep(0.25)
- end
- updateForward()
- end
- local function back()
- while not turtle.back() do
- turnRight()
- turnRight()
- turtle.dig()
- turnRight()
- turnRight()
- sleep(0.25)
- end
- updateBack()
- end
- local function goTo(targetX, targetY)
- if x < targetX then
- face(1)
- while x < targetX do
- forward()
- end
- elseif x > targetX then
- face(3)
- while x > targetX do
- forward()
- end
- end
- if y < targetY then
- face(0)
- while y < targetY do
- forward()
- end
- elseif y > targetY then
- face(2)
- while y > targetY do
- forward()
- end
- end
- end
- local function goHome()
- goTo(0, 0)
- face(0)
- end
- local function returnTo(savedX, savedY, savedDir)
- goTo(savedX, savedY)
- face(savedDir)
- end
- --------------------------------------------------
- -- BLOCK / ITEM CHECKS
- --------------------------------------------------
- local function isWheatBlock(name)
- return name == "minecraft:wheat"
- end
- local function isFarmlandBlock(name)
- return name == "minecraft:farmland"
- end
- local function isSeedItem(name)
- return name == "minecraft:wheat_seeds" or name == "minecraft:seeds"
- end
- local function isIgnoredWaterCoverBlock(data)
- if not data then
- return false
- end
- local name = data.name
- if name == "minecraft:cobblestone" then
- return true
- end
- if name == "minecraft:cobblestone_slab" then
- return true
- end
- -- Minecraft 1.12.2 often reports cobblestone slabs as minecraft:stone_slab.
- if name == "minecraft:stone_slab" then
- return true
- end
- if name == "minecraft:stone_slab2" then
- return true
- end
- return false
- end
- local function getBlockDown()
- local ok, data = turtle.inspectDown()
- if not ok then
- return nil
- end
- return data
- end
- -- This is the main new rule.
- -- nil/air below is allowed.
- -- wheat is allowed.
- -- farmland is allowed, just in case your turtle sees it directly.
- -- cobble/slabs are allowed as pass-through water covers.
- -- anything else is treated as a border/end marker.
- local function isBoundaryBlockBelow()
- local data = getBlockDown()
- -- Air below means crop space is empty.
- -- This should NOT trigger a turn anymore.
- if not data then
- return false
- end
- if isWheatBlock(data.name) then
- return false
- end
- if isFarmlandBlock(data.name) then
- return false
- end
- if isIgnoredWaterCoverBlock(data) then
- return false
- end
- return true
- end
- local function isWaterCoverBelow()
- local data = getBlockDown()
- return isIgnoredWaterCoverBlock(data)
- end
- local function isWheatBelow()
- local data = getBlockDown()
- if not data then
- return false
- end
- return isWheatBlock(data.name)
- end
- local function isPlantableFarmSpace()
- local data = getBlockDown()
- -- Empty air below turtle usually means empty crop space above farmland.
- if not data then
- return true
- end
- -- If it sees farmland directly, try planting too.
- if isFarmlandBlock(data.name) then
- return true
- end
- return false
- end
- local function wheatIsReady()
- local data = getBlockDown()
- if not data then
- return false
- end
- if not isWheatBlock(data.name) then
- return false
- end
- if data.state and data.state.age ~= nil then
- return tonumber(data.state.age) >= 7
- end
- return false
- end
- --------------------------------------------------
- -- INVENTORY HELPERS
- --------------------------------------------------
- local function countEmptySlots()
- local empty = 0
- for slot = 1, 16 do
- if turtle.getItemCount(slot) == 0 then
- empty = empty + 1
- end
- end
- return empty
- end
- local function countSeeds()
- local total = 0
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and isSeedItem(item.name) then
- total = total + turtle.getItemCount(slot)
- end
- end
- return total
- end
- local function selectSeedSlot()
- local currentSlot = turtle.getSelectedSlot()
- local currentItem = turtle.getItemDetail(currentSlot)
- if currentItem and isSeedItem(currentItem.name) and turtle.getItemCount(currentSlot) > 0 then
- return true
- end
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and isSeedItem(item.name) and turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- return true
- end
- end
- return false
- end
- local function hasUsefulFreeSpace()
- return countEmptySlots() > 0
- end
- --------------------------------------------------
- -- CHEST HELPERS
- --------------------------------------------------
- local function faceChest()
- goHome()
- face(2)
- end
- local function pullFromChest()
- faceChest()
- for i = 1, CHEST_PULL_ATTEMPTS do
- if countEmptySlots() <= 0 then
- break
- end
- turtle.suck()
- sleep(0.1)
- end
- face(0)
- end
- local function depositItems()
- goHome()
- face(2)
- local seedsLeftToKeep = SEEDS_TO_KEEP
- for slot = 1, 16 do
- turtle.select(slot)
- local item = turtle.getItemDetail(slot)
- if item then
- if isSeedItem(item.name) then
- local count = turtle.getItemCount(slot)
- if seedsLeftToKeep > 0 then
- if count <= seedsLeftToKeep then
- seedsLeftToKeep = seedsLeftToKeep - count
- else
- local amountToDrop = count - seedsLeftToKeep
- turtle.drop(amountToDrop)
- seedsLeftToKeep = 0
- end
- else
- turtle.drop()
- end
- else
- turtle.drop()
- end
- end
- end
- face(0)
- turtle.select(1)
- end
- local function depositButKeepSeeds()
- depositItems()
- end
- local function restockSeedsAndReturn(savedX, savedY, savedDir)
- if not ENABLE_CHEST_SEED_PULL then
- return false
- end
- log("No seeds in inventory. Returning to chest for seeds.")
- pullFromChest()
- if countSeeds() <= 0 then
- log("No seeds found in chest.")
- depositButKeepSeeds()
- returnTo(savedX, savedY, savedDir)
- return false
- end
- depositButKeepSeeds()
- returnTo(savedX, savedY, savedDir)
- return countSeeds() > 0
- end
- --------------------------------------------------
- -- SEED PLANTING
- --------------------------------------------------
- local function placeSeedDown()
- if not selectSeedSlot() then
- return false
- end
- if turtle.placeDown() then
- sleep(0.1)
- return true
- end
- -- Try every seed stack if the first one fails.
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and isSeedItem(item.name) and turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- if turtle.placeDown() then
- sleep(0.1)
- return true
- end
- end
- end
- return false
- end
- local function ensureSeedsAtCurrentPosition()
- if countSeeds() > 0 then
- return true
- end
- local savedX = x
- local savedY = y
- local savedDir = dir
- return restockSeedsAndReturn(savedX, savedY, savedDir)
- end
- local function plantEmptySpotIfNeeded()
- if not PLANT_EMPTY_SPOTS then
- return false
- end
- if isBoundaryBlockBelow() then
- return false
- end
- if isWaterCoverBelow() then
- return false
- end
- if isWheatBelow() then
- return false
- end
- if not isPlantableFarmSpace() then
- return false
- end
- if not ensureSeedsAtCurrentPosition() then
- return false
- end
- if placeSeedDown() then
- log("Planted empty spot.")
- return true
- end
- return false
- end
- --------------------------------------------------
- -- FARM ACTIONS
- --------------------------------------------------
- local function harvestAndReplantIfReady()
- if not wheatIsReady() then
- return false
- end
- if not ensureSeedsAtCurrentPosition() then
- log("Skipping harvest because no seeds are available.")
- return false
- end
- turtle.digDown()
- sleep(0.2)
- if placeSeedDown() then
- log("Harvested and replanted.")
- else
- log("Harvested, but failed to replant.")
- end
- return true
- end
- --------------------------------------------------
- -- INVENTORY FULL PROTECTION
- --------------------------------------------------
- local function handleInventoryIfFull()
- if hasUsefulFreeSpace() then
- return
- end
- log("Inventory full. Returning home to deposit.")
- local savedX = x
- local savedY = y
- local savedDir = dir
- depositButKeepSeeds()
- log("Returning to previous farm position.")
- returnTo(savedX, savedY, savedDir)
- end
- --------------------------------------------------
- -- FIELD SCANNING
- --------------------------------------------------
- local function tryMoveToNextRow(turnRightNext)
- if turnRightNext then
- turnRight()
- forward()
- if isBoundaryBlockBelow() then
- back()
- turnLeft()
- return false
- end
- turnRight()
- return true
- else
- turnLeft()
- forward()
- if isBoundaryBlockBelow() then
- back()
- turnRight()
- return false
- end
- turnLeft()
- return true
- end
- end
- local function scanAndHarvest()
- local checkedCells = 0
- local harvested = 0
- local planted = 0
- local turnRightNext = true
- log("Starting farm scan...")
- while true do
- if isBoundaryBlockBelow() then
- break
- end
- handleInventoryIfFull()
- if isWaterCoverBelow() then
- -- Cobble/slab water cover. Skip it.
- elseif isWheatBelow() then
- checkedCells = checkedCells + 1
- if harvestAndReplantIfReady() then
- harvested = harvested + 1
- end
- else
- checkedCells = checkedCells + 1
- if plantEmptySpotIfNeeded() then
- planted = planted + 1
- end
- end
- forward()
- if isBoundaryBlockBelow() then
- back()
- local movedToNextRow = tryMoveToNextRow(turnRightNext)
- if not movedToNextRow then
- break
- end
- turnRightNext = not turnRightNext
- end
- end
- log("Farm scan complete.")
- log("Checked farm cells: " .. tostring(checkedCells))
- log("Wheat harvested: " .. tostring(harvested))
- log("Empty spots planted: " .. tostring(planted))
- return checkedCells, harvested, planted
- end
- --------------------------------------------------
- -- MAIN CYCLE
- --------------------------------------------------
- local function runFarmCycle()
- local checkedCells, harvested, planted = scanAndHarvest()
- if checkedCells == 0 then
- log("No farm path detected. Make sure border blocks are only around the outside.")
- goHome()
- return false
- end
- goHome()
- depositItems()
- if harvested == 0 then
- log("No mature wheat found this cycle.")
- end
- log("Cycle complete. Waiting for wheat to grow again.")
- return true
- end
- --------------------------------------------------
- -- START
- --------------------------------------------------
- log("Wheat farm turtle started.")
- log("Start above first crop space.")
- log("Chest must be directly behind starting position.")
- log("Infinite fuel mode enabled.")
- log("Air below is treated as valid farm space.")
- log("Any non-cobble/slab/non-wheat block below is treated as a border.")
- while true do
- local success = runFarmCycle()
- if not success then
- log("Issue detected. Retrying soon.")
- sleep(30)
- else
- sleep(CHECK_DELAY)
- end
- end
Advertisement
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=jzxvqlbehn
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment