Skip to content

Add AutoFarm module - #6692

Open
JeffreyHamilton6399 wants to merge 1 commit into
MeteorDevelopment:masterfrom
JeffreyHamilton6399:auto-farm-module
Open

JeffreyHamilton6399 wants to merge 1 commit into
MeteorDevelopment:masterfrom
JeffreyHamilton6399:auto-farm-module

Conversation

@JeffreyHamilton6399

Copy link
Copy Markdown

Type of change

  • New feature

Description

Adds a new AutoFarm module to the World category that automatically harvests and replants crops around the player.

Supported crops:

  • Farmland crops (wheat, carrots, potatoes, beetroot) - only broken when fully grown (CropBlock#isMaxAge), then automatically replanted from seeds in the hotbar
  • Nether wart - harvested at max age, replanted on soul sand
  • Cocoa beans - harvested at max age
  • Pumpkins and melons - harvested when present (they only appear once fully grown), no replanting needed since the stems regrow them
  • Sugar cane and cactus - the column is harvested while preserving the base block, so they regrow on their own
  • Sweet berry bushes - harvested by interacting with the bush at max age, so the bush itself is never destroyed

Implementation details:

  • One action per tick, using the same BlockUtils / Rotations / InvUtils helpers as the other automation modules (AutoBreed, AutoShearer, VeinMiner)
  • Harvested crop positions are queued and replanted with the matching seed item; pumpkin/melon stems and sugar cane/cactus bases are intentionally not replanted as they regrow by themselves
  • Replanting happens before harvesting each tick so freed farmland is used again as soon as possible
  • Configurable crop whitelist, range and rotations
  • 100% original code, written against the existing module API

This differs from #6417 (BetterFarming) in that it fully automates harvesting rather than assisting manual farming, so the two are complementary.

Related issues

Related to #6104 (Nuker breaking unripe wheat) - AutoFarm only breaks crops that are fully grown.

How Has This Been Tested?

Compiles successfully against master (26.2). Module logic (maturity checks via block state properties, replant rules per crop type, one-action-per-tick pacing) was written against vanilla mechanics and the patterns used by the existing automation modules. In-game verification was not possible on my setup, so reviewer testing is welcome.

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

Automatically harvests and replants crops around the player.

- Harvests farmland crops, nether wart, cocoa, pumpkins, melons,
  sugar cane, cactus and sweet berry bushes when they are fully grown
- Replants harvested crops from seeds in the hotbar, one action per tick
- Crop types, range and rotations are configurable
@machiecodes

Copy link
Copy Markdown
Contributor

Several issues as I'm testing here:

  • You should use mc.player.blockInteractionRange() instead of a range setting, honestly the other utility modules should be updated to do this as well, as 4.5 is no longer the default interaction range
  • With sugarcane and cacti it just breaks the bottom block, destroying the whole plant
  • It seems to sometimes fail to replant crops like wheat and carrots, this seems more common the further the plant is from the player so I'm assuming this is tied to the interaction range

It also doesn't account for kelp or bamboo, which would probably be expected from a farming module.

I would also add that the sorting to determine what crop it will harvest seems unintuitive, I would make it closest-first, optionally with a setting like in Nuker to change how it sorts if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants