Contents
The Farmer Was Replaced challenges players to optimize farming with clever automation, and mastering script codes can dramatically speed up progress. Whether managing hay, wood, or carrot farms, these scripted approaches offer powerful ways to automate planting, harvesting, and resource management, helping players overcome common hurdles in the game.
The Farmer Was Replaced Codes
Below is a collection of carefully crafted scripts designed to help unlock achievements and automate key farming processes in The Farmer Was Replaced. These scripts cover a range of polyculture and single-drone setups tailored for different farm types.
Hay Farm
Polyculture with Multiple Drones
# Hay farm with polyculture and multiple drones
clear()
world_size = get_world_size()
change_hat(Hats.Brown_Hat)
companion_mapping = {}
hay_mapping = {}
def track_companion(curr_x, curr_y):
global companion_mapping
global hay_mapping
result = get_companion()
if result is None:
return False
target_entity, (target_x, target_y) = result
if (target_x, target_y) not in companion_mapping:
companion_mapping[(target_x, target_y)] = target_entity
hay_mapping[(curr_x, curr_y)] = (target_x, target_y)
return True
return False
def drone_hay_task():
global world_size
global companion_mapping
global hay_mapping
while True:
for j in range(world_size):
curr_x = get_pos_x()
curr_y = get_pos_y()
harvest()
if get_ground_type() == Grounds.Soil:
till()
if (curr_x, curr_y) in companion_mapping:
target_entity = companion_mapping[(curr_x, curr_y)]
if target_entity == Entities.Carrot:
if get_ground_type() != Grounds.Soil:
till()
plant(Entities.Carrot)
elif target_entity != Entities.Grass:
plant(target_entity)
else:
if (curr_x, curr_y) in hay_mapping:
companion_pos = hay_mapping.pop((curr_x, curr_y))
if companion_pos in companion_mapping:
companion_mapping.pop(companion_pos)
track_companion(curr_x, curr_y)
move(North)
NUM_DRONES_TO_SPAWN = world_size - 1
for i in range(NUM_DRONES_TO_SPAWN):
while num_drones() >= max_drones():
pass
spawn_drone(drone_hay_task)
move(East)
drone_hay_task()
Single Drone (Leaderboard)
# Hay farm with only one drone (for leaderboard maybe)
companion_mapping = {}
hay_mapping = {}
def track_companion():
global companion_mapping
global hay_mapping
target_entity, (target_x, target_y) = get_companion()
while target_entity == Entities.Carrot and num_items(Items.Wood) < 1:
harvest()
target_entity, (target_x, target_y) = get_companion()
if (target_x, target_y) not in companion_mapping:
companion_mapping[(target_x, target_y)] = target_entity
hay_mapping[(x_curr, y_curr)] = (target_x, target_y)
while True:
if num_items(Items.Hay) >= 1000000000000:
break
x_curr = get_pos_x()
y_curr = get_pos_y()
if get_entity_type() == Entities.Grass:
if can_harvest():
harvest()
if (x_curr, y_curr) in hay_mapping:
companion_pos = hay_mapping.pop((x_curr, y_curr))
companion_mapping.pop(companion_pos)
if (x_curr, y_curr) in companion_mapping:
target_entity = companion_mapping[(x_curr, y_curr)]
if target_entity not in [Entities.Bush, Entities.Tree]:
till()
plant(target_entity)
else:
track_companion()
else:
if (x_curr, y_curr) not in companion_mapping:
if get_ground_type() != Grounds.Grassland:
till()
else:
harvest()
track_companion()
if y_curr == get_world_size() - 1:
move(East)
move(North)
Wood Farm
Polyculture with Multiple Drones
# Wood farm with polyculture and multiple drones
clear()
world_size = get_world_size()
change_hat(Hats.Brown_Hat)
companion_mapping = {}
tree_mapping = {}
def tree_tile(curr_x, curr_y):
return curr_x % 2 == curr_y % 2
def track_companion(curr_x, curr_y):
global companion_mapping
global tree_mapping
result = get_companion()
if result is None:
return False
target_entity, (target_x, target_y) = result
if (target_x, target_y) not in companion_mapping:
companion_mapping[(target_x, target_y)] = target_entity
tree_mapping[(curr_x, curr_y)] = (target_x, target_y)
return True
return False
def drone_tree_task():
global world_size
global companion_mapping
global tree_mapping
while True:
for j in range(world_size):
curr_x = get_pos_x()
curr_y = get_pos_y()
if tree_tile(curr_x, curr_y):
if can_harvest():
harvest()
plant(Entities.Tree)
if (curr_x, curr_y) in tree_mapping:
companion_pos = tree_mapping.pop((curr_x, curr_y))
if companion_pos in companion_mapping:
companion_mapping.pop(companion_pos)
track_companion(curr_x, curr_y)
if get_water() < 0.40:
use_item(Items.Water)
elif (curr_x, curr_y) in companion_mapping:
target_entity = companion_mapping[(curr_x, curr_y)]
harvest()
if target_entity == Entities.Grass:
if get_ground_type() != Grounds.Grassland:
till()
elif target_entity == Entities.Carrot:
if get_ground_type() != Grounds.Soil:
till()
plant(target_entity)
else:
harvest()
plant(Entities.Bush)
move(North)
NUM_DRONES_TO_SPAWN = 31
for i in range(NUM_DRONES_TO_SPAWN):
while num_drones() >= max_drones():
pass
spawn_drone(drone_tree_task)
move(East)
drone_tree_task()
Polyculture with Single Drone
# Wood farm with polyculture and only one drone
world_size = get_world_size()
target_num = 10000000000
companion_mapping = {}
tree_mapping = {}
def track_companion(curr_x, curr_y):
global companion_mapping
global hay_mapping
target_entity, (target_x, target_y) = get_companion()
if not tree_tile(target_x, target_y) and (target_x, target_y) not in companion_mapping:
companion_mapping[(target_x, target_y)] = target_entity
tree_mapping[(curr_x, curr_y)] = (target_x, target_y)
return True
return False
def tree_tile(curr_x, curr_y):
return curr_x % 2 == curr_y % 2
while True:
curr_x = get_pos_x()
curr_y = get_pos_y()
if tree_tile(curr_x, curr_y):
if (curr_x, curr_y) in tree_mapping:
while not can_harvest():
use_item(Items.Fertilizer)
harvest()
plant(Entities.Tree)
if (curr_x, curr_y) in tree_mapping:
companion_pos = tree_mapping.pop((curr_x, curr_y))
companion_mapping.pop(companion_pos)
if track_companion(curr_x, curr_y) and get_water() < 0.10:
use_item(Items.Water)
elif (curr_x, curr_y) in companion_mapping:
target_entity = companion_mapping[(curr_x, curr_y)]
harvest()
if target_entity == Entities.Grass:
if get_ground_type() != Grounds.Grassland:
till()
elif target_entity == Entities.Carrot and get_ground_type() != Grounds.Soil:
till()
plant(target_entity)
else:
plant(target_entity)
else:
harvest()
plant(Entities.Bush)
if num_items(Items.Wood) >= target_num:
break
move(North)
curr_y = get_pos_y()
if curr_y == world_size - 1:
move(East)
Carrot Farm
Polyculture with Multiple Drones
# Carrot farm with polyculture and multiple drones
clear()
world_size = get_world_size()
change_hat(Hats.Brown_Hat)
companion_mapping = {}
carrot_mapping = {}
def track_companion(curr_x, curr_y):
global companion_mapping
global carrot_mapping
result = get_companion()
if result is None:
return False
target_entity, (target_x, target_y) = result
if (target_x, target_y) not in companion_mapping:
companion_mapping[(target_x, target_y)] = target_entity
carrot_mapping[(curr_x, curr_y)] = (target_x, target_y)
return True
return False
def prepare_and_plant(entity_type):
if entity_type in (Entities.Carrot, Entities.Bush, Entities.Tree) and get_ground_type() != Grounds.Soil:
till()
plant(entity_type)
def drone_carrot_task():
global world_size
global companion_mapping
global carrot_mapping
while True:
for j in range(world_size):
curr_x = get_pos_x()
curr_y = get_pos_y()
harvest()
if (curr_x, curr_y) in companion_mapping:
target_entity = companion_mapping[(curr_x, curr_y)]
prepare_and_plant(target_entity)
if target_entity == Entities.Carrot and get_water() < 0.10:
use_item(Items.Water)
elif (curr_x, curr_y) in carrot_mapping:
prepare_and_plant(Entities.Carrot)
if get_water() < 0.10:
use_item(Items.Water)
companion_pos = carrot_mapping.pop((curr_x, curr_y))
if companion_pos in companion_mapping:
companion_mapping.pop(companion_pos)
track_companion(curr_x, curr_y)
else:
prepare_and_plant(Entities.Carrot)
if get_water() < 0.10:
use_item(Items.Water)
track_companion(curr_x, curr_y)
move(North)
NUM_DRONES_TO_SPAWN = world_size - 1
for i in range(NUM_DRONES_TO_SPAWN):
while num_drones() >= max_drones():
pass
spawn_drone(drone_carrot_task)
move(East)
drone_carrot_task()
