11 template <
bool NeedsLightToGrow>
42 if (!NeedsLightToGrow)
51 if (Blocklight > Light)
61 else if ((Blocklight < 9) && (SkyLight < 9))
102 for (
int x = -1; x < 2; ++x)
104 for (
int z = -1; z < 2; ++z)
106 float Adjustment = 0.0f;
127 if ((x != 0) || (z != 0))
132 Chance += Adjustment;
135 return FloorC(24.0f / Chance) + 1;
148 auto Action =
CanGrow(a_Chunk, a_RelPos);
153 if (
Grow(a_Chunk, a_RelPos) == 0)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const
Checks whether the block has an effect on growing the plant.
virtual int Grow(cChunk &a_Chunk, Vector3i a_RelPos, int a_NumStages=1) const
Grows this block, if it supports growing, by the specified amount of stages (at most).
static const cBlockHandler & For(BLOCKTYPE a_BlockType)
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
const BLOCKTYPE m_BlockType
Base class for plants that use light values to decide whether to grow or not.
virtual int GetGrowthChance(cChunk &a_Chunk, Vector3i a_RelPos) const
Generates an int value between 4 and 25 based on surrounding blocks that affect how quickly the plant...
static PlantAction HasEnoughLight(cChunk &a_Chunk, Vector3i a_RelPos)
Checks whether there is enough light for the plant to grow.
virtual PlantAction CanGrow(cChunk &a_Chunk, Vector3i a_RelPos) const
Checks whether a plant can grow grow, based on what is returned from cBlockPlant::HasEnoughLight and ...
PlantAction
The action the plant can take on an update.
virtual void OnUpdate(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_PluginInterface, cChunk &a_Chunk, const Vector3i a_RelPos) const override
Called when the block gets ticked either by a random tick or by a queued tick.
virtual void BearFruit(cChunk &a_Chunk, const Vector3i a_StemRelPos) const
Grows the final produce next to the stem at the specified position.
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld.
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
NIBBLETYPE GetBlockLight(Vector3i a_RelPos) const
Get the level of artificial light illuminating the block (0 - 15)
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
NIBBLETYPE GetSkyLight(Vector3i a_RelPos) const
Get the level of sky light illuminating the block (0 - 15) independent of daytime.
NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const
Light alterations based on time.
bool UnboundedRelGetBlock(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in ...