Skip to main content

Weed Defs

Based on game build 714014 | Last updated: 2026-03-07

Overview

weed_defs.lua defines a central configuration table WEED_DEFS that stores data and callback functions for all weed plant types in the game. Each weed (forgetmelots, tillweed, firenettle, ivy) has associated metadata such as growth time distribution, spread parameters, seed drop chance, nutrient/moisture consumption, and custom behavior hooks (e.g., OnMakeFullFn, ondigup, masterpostinit). It also automatically populates registry and UI configuration fields for each weed type, ensuring consistent integration with the farm/plant system.

Usage example

-- Access the configuration for a specific weed
local forgetmelots_def = WEED_DEFS.weed_forgetmelots
print(forgetmelots_def.product) -- "forgetmelots"

-- Use grow times to schedule growth in a custom plant
local grow_times = MakeGrowTimes(2 * TUNING.TOTAL_DAY_TIME, 3 * TUNING.TOTAL_DAY_TIME, true)
-- Then assign to a growable's stagedata.time function

Dependencies & tags

Components used: growable, burnable, health, combat, playerprox, timer Tags: Adds CLASSIFIED and weed_forgetmelots_respawner to respawner entities; dynamically adds/removes farm_plant_defender for ivy; sets custom trapdamage tag for firenettle.

Properties

PropertyTypeDefault ValueDescription
prefabstringnil (set in post-init loop)Prefab name (e.g., "weed_forgetmelots"), auto-assigned.
buildstring"weed_<name>"Animation/build bank name.
bankstring"weed_<name>"Animation bank name for this weed.
grow_timetableGenerated by MakeGrowTimesTable of min/max time ranges for each growth stage (small, med, full, bolting).
spreadtablenil or weed-specificSpread behavior configuration (e.g., stage, time_min, tilled_dist).
seed_weightnumberTUNING.SEED_CHANCE_*Weight used in seed drop probability.
productstring or nil"forgetmelots" etc.Name of the item produced when harvested (nil for ivy).
nutrient_consumptiontable{nutrient, nutrient, nutrient}Nutrient consumption values per growth stage.
moisturetable{drink_rate = drink_*}Moisture consumption configuration.
extra_tagstable{} or {"trapdamage"}Additional tags added to the weed instance.
prefab_depstable{}Prefabs to ensure are loaded before use (e.g., "firenettle_toxin").
plantregistryinfotableAuto-generatedData used by UI/registry to render plant growth stages.
plantregistrywidgetstring"widgets/redux/weedplantpage"Path to the UI widget for plant page.
stage_netvarfunctionnet_tinybyteNetwork replication type for stage.
moddedbooleannilSet to true when a new entry is added via __newindex.
sameweedtagstable{weed}Tags used to identify the same weed type (e.g., {weed_forgetmelots}).
ondigupfunctionnil (forgetmelots only)Callback when the weed is dug up; handles respawning logic.
OnMakeFullFnfunctionnil or weed-specificCallback when the weed reaches the full-grown stage.
masterpostinitfunctionnil (ivy only)Hook to register custom event listeners after full init.
OnTimerDoneFnfunctionnil (tillweed only)Callback for timer events (e.g., debris generation).

Main functions

MakeGrowTimes(full_grow_min, full_grow_max, bolting)

  • Description: Calculates relative growth durations for each stage (small, medium, full, optionally bolting) based on total min/max growth times. If bolting is true, all stages include a "bolting" phase after full.
  • Parameters:
    • full_grow_min (number) – Minimum total days for full growth.
    • full_grow_max (number) – Maximum total days for full growth.
    • bolting (boolean) – Whether to include a bolting stage.
  • Returns: Table { small = [min, max], med = [min, max], full = [min, max], bolting = [min, max] } or { small, med } if not bolting. Times are expressed in days.
  • Error states: None. Values are clamped to valid ranges via multiplication.

ForgetMeLotsSpreadChanceMult(inst, chance, luck)

  • Description: Modifies the respawning chance for forgetmelots based on player luck. Used during ondigup.
  • Parameters:
    • chance (number) – Base chance.
    • luck (number) – Player's luck value (negative or positive).
  • Returns: Modified chance (number). If luck < 0, chance increases; if luck > 0, chance decreases via a reciprocal formula.
  • Error states: Returns chance unchanged if luck == 0.

SpawnSnare(inst, x, z, r, num, target)

  • Description: Spawns ivy snare traps in a circle around a target. Used during the defend_farm_plant event.
  • Parameters:
    • inst (entity) – The ivy plant instance.
    • x/z (numbers) – Center coordinates for snare placement.
    • r (number) – Radius of the snare circle.
    • num (number) – Number of snares to spawn (6 or 12).
    • target (entity) – Target being snared.
  • Returns: Boolean – true if at least one snare was placed, otherwise false.
  • Error states: Skips placement if the world geometry (TheWorld.Map) deems the point impassable or near a hole.

Events & listeners

  • Listens to: defend_farm_plant (ivy only, via masterpostinit) – triggers snare deployment and damage logic.
  • Pushes: snared (ivy only, during dosnaredamage) – notifies entities they are snared with ANNOUNCE_SNARED_IVY localization key.