# Farm System

It controls crop behavior, XP gain, essence rewards, custom drops, evolution items and growth rendering.

The system is area-based, performance-safe and supports both client-side and server-side crop rendering.

***

## Farm Area

```yaml
farm:
  trigger: WHEAT
  area:
    world: ""
    min: [0, 0, 0]
    max: [0, 0, 0]
```

#### trigger

Defines the main crop type used inside the farm area.

#### area

Defines the rectangular region where special farm logic applies.

If empty → system behaves globally.

***

## Harvest Rules

```yaml
harvest:
  require-grown: true
```

If `true`, ageable crops must be fully grown before harvesting.

***

## Render Mode

```yaml
render-mode: SERVER
```

Available modes:

* `SERVER`
* `CLIENT`

This controls how crop breaking and regrowth are handled.

***

## SERVER Mode (Authoritative)

Default and safest option.

#### Behavior

* Blocks are physically modified on the server
* Real block data changes
* Uses region scheduler for growth
* Fully synchronized across all players
* No fake block states

#### Growth Logic

* Ageable crops replant at age 0
* Grow per stage with configurable tick delay
* Double-height plants restore properly
* Sugar cane restores correctly with height validation

#### Best For

* Competitive servers
* Boss damage systems
* Shared farming environments
* High player count farms

***

## CLIENT Mode (Visual-Only Masking)

Optimized personal rendering.

#### Behavior

* Real block is not removed
* Player receives fake block change
* Regrowth happens client-side only
* Other players see original block state
* Fully personal harvesting illusion

#### How It Works

* Uses `sendBlockChange`
* Registers fake harvest entries
* Schedules client-only restoration
* Does not modify world state

#### Options

```yaml
growth:
  enabled: true
  ticks-per-stage: "8-12"
  double-height-restore: "20"
  single-restore: "20"

client:
  keep-final-stage: true
```

* `ticks-per-stage` → random growth interval
* `double-height-restore` → restore delay
* `single-restore` → restore delay
* `keep-final-stage` → keep visually mature

#### Best For

* Personal farms
* Skyblock-style islands
* High-performance setups
* Visual-only crop systems

***

## Growth System

```yaml
growth:
  enabled: true
  ticks-per-stage: "8-12"
```

Supports:

* Fixed value: `10`
* Range: `"8-12"`

Each growth stage delay is randomly selected in range.

***

## Drop System

```yaml
drop-settings:
  straight-to-inventory: true
  drop-items-floor-if-full-inventory: false
```

#### straight-to-inventory

Directly inserts drops into player inventory.

#### drop-items-floor-if-full-inventory

If inventory full:

* true → drop on ground
* false → stop giving drops

Supports stacking and storage hooks.

***

## Harvest Rule Structure

```yaml
WHEAT:
  xp: "50-70"
  min-level: 2
  essence: 3
```

#### xp

* Single value
* Range `"min-max"`

#### min-level

Minimum Tycoon Hoe level required.

#### essence

Supports:

* Single value
* Range `"min-max"`

***

## Custom Drop Items

```yaml
drop:
  amount: 1-3
  material: "WHEAT"
  name: "Fresh Wheat"
  lore:
    - "Harvested with love"
```

Supports:

* Custom name
* Lore
* Enchantments
* Flags
* Unbreakable
* Custom model data
* Full ItemFactory integration

***

## Evolution Items

```yaml
evolution-item:
  material: "WHEAT"
  needed-amount: 5
  name: "Baked Wheat"
```

If player collects required amount → converts to evolution item.

Evolution can be placed inside:

* `drop.evolution-item`
* Or directly under rule

***

## XP & Essence Calculation Flow

Final gain includes:

* Base XP
* Enchant bonuses
* Prestige bonuses
* Armor boosters
* Pet boosts
* Power-up boosts

Formula pipeline:

```yaml
base → enchant → prestige → armor → pet → powerup
```

All boosts are additive before rounding.

***

## Rounding Modes

Crop yield boosters support:

* STOCHASTIC
* ROUND
* FLOOR
* CEIL

Configured under enchant settings.

***

## Boss Integration

Each crop break automatically notifies:

```java
BossManager.handleCropBreak()
```

Boss damage is directly tied to farm activity.

***

## Safety & Performance

* ConcurrentHashMap stacking buffers
* Essence batching (500ms window)
* XP batching (5s window)
* No sync database writes
* RegionScheduler for growth
* No heavy tick loops
* Fully event-driven

***

## Double Height Handling

Supported:

* Sugar Cane
* Sunflower
* Lilac
* Rose Bush
* Peony
* All Bisected blocks

Prevents bottom-half breaking exploits.
