Skip to content

Make grass grow back ​

Give a style regrows to set how many seconds after it was burnt, cut or crushed it starts growing back by itself, and grows for how long that takes. Call regrow to bring grass back yourself.

ts
// in src/rules.ts
import { defineCellLayer } from '@v12-engine/engine'

export const grass = defineCellLayer({
	id: 'grass',
	name: 'Grass',
	// 60 seconds after it is ruined it starts to come back, and it is whole 20 seconds later
	values: [{ value: 1, name: 'Meadow', foliage: { flammable: 0.6, regrows: 60, grows: 20 } }]
})

Done: burnt or cut meadow rises from the ground a minute later and stands whole after another twenty seconds. It hides and burns again as soon as it starts growing.

Grow it back from code or a spell ​

ts
import { type AbilityDef, regrow, type World } from '@v12-engine/engine'

// at once
export const restore = (world: World): number[] => regrow(world, 'grass', { kind: 'circle', x: 20, z: 20, radius: 6 })
// over 8 seconds, by a druid's spell
export const bloom: AbilityDef = { id: 'bloom', name: 'Bloom', target: 'point', range: 8, cooldown: 30, effects: [{ type: 'foliage', act: 'regrow', over: 8, radius: 5 }] }

Hear it grow back ​

ts
import { defineListener, foliageRegrown } from '@v12-engine/engine'

export const regrown = defineListener({
	event: foliageRegrown,
	id: 'mygame.regrown',
	run(world, { cells, by }) {
		world.log.info('grass', 'grass grew back', { cells: cells.length, by })
	}
})

In the editor ​

  1. Under a style's Gameplay, set Grows back after (s) (leave it empty for never) and Grows back over (s).
  2. In Play here, the Cheats panel's Grass › Regrow brush grows grass back in the running game.

Reference ​

Field or callDefaultWhat it does
regrowsneverSeconds after it was ruined or burnt out that it starts growing; false for never
grows10Seconds it takes once it starts by itself
regrow(world, layer, where, { over, by })at onceStarts growing now over over seconds; whatever was waiting to regrow by itself waits no more
foliageRegrownAn event as cells stand whole again

Growing grass is state growing. Timers are saved with the world. At most 1,024 cells of a layer finish growing in a tick; the rest follow over the next ticks. A screen that first sees a cell while it is growing shows it half grown.