Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
-- 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
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
SwapEngine Bug [build 1.3]
13 min ago | 0.28 KB
December smells like money
CSS | 27 min ago | 0.28 KB
✅ Changelly.com Exploit
40 min ago | 0.28 KB
Trading method
CSS | 53 min ago | 0.28 KB
Untitled
C | 9 hours ago | 0.88 KB
acg
1 day ago | 0.05 KB
AI METHODS
2 days ago | 0.29 KB
Untitled
2 days ago | 0.29 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!