Cuberite
A lightweight, fast and extensible game server for Minecraft
Protected Types | Protected Member Functions | Static Protected Member Functions | Private Types | Private Member Functions | List of all members
cBlockPlant< NeedsLightToGrow > Class Template Reference

Base class for plants that use light values to decide whether to grow or not. More...

#include <BlockPlant.h>

Inheritance diagram for cBlockPlant< NeedsLightToGrow >:
Inheritance graph
[legend]
Collaboration diagram for cBlockPlant< NeedsLightToGrow >:
Collaboration graph
[legend]

Protected Types

enum  PlantAction { paDeath , paGrowth , paStay }
 The action the plant can take on an update. More...
 

Protected Member Functions

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 a random check based on what is returned from cBlockPlant::GetGrowthChance. More...
 
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 grows. More...
 
 ~cBlockPlant ()=default
 
- Protected Member Functions inherited from cBlockHandler
 ~cBlockHandler ()=default
 

Static Protected Member Functions

static PlantAction HasEnoughLight (cChunk &a_Chunk, Vector3i a_RelPos)
 Checks whether there is enough light for the plant to grow. More...
 

Private Types

using Super = cBlockHandler
 

Private Member Functions

virtual void BearFruit (cChunk &a_Chunk, const Vector3i a_StemRelPos) const
 Grows the final produce next to the stem at the specified position. More...
 
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. More...
 

Additional Inherited Members

- Public Member Functions inherited from cBlockHandler
virtual bool CanBeAt (const cChunk &a_Chunk, Vector3i a_Position, NIBBLETYPE a_Meta) const
 Checks if the block can stay at the specified relative coords in the chunk. More...
 
virtual bool CanSustainPlant (BLOCKTYPE a_Plant) const
 Checks whether the block has an effect on growing the plant. More...
 
constexpr cBlockHandler (BLOCKTYPE a_BlockType)
 
void Check (cChunkInterface &ChunkInterface, cBlockPluginInterface &a_PluginInterface, Vector3i a_RelPos, cChunk &a_Chunk) const
 Called when one of the neighbors gets set; equivalent to MC block update. More...
 
virtual cItems ConvertToPickups (NIBBLETYPE a_BlockMeta, const cItem *a_Tool=nullptr) const
 Returns the pickups that would result if the block was mined by a_Digger using a_Tool. More...
 
virtual bool DoesIgnoreBuildCollision (const cWorld &a_World, const cItem &a_HeldItem, Vector3i a_Position, NIBBLETYPE a_Meta, eBlockFace a_ClickedBlockFace, bool a_ClickedDirectly) const
 Checks if the player can build "inside" this block. More...
 
virtual ColourID GetMapBaseColourID (NIBBLETYPE a_Meta) const
 Returns the base colour ID of the block, as will be represented on a map, as per documentation: https://minecraft.wiki/w/Map_item_format. More...
 
virtual cBoundingBox GetPlacementCollisionBox (BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const
 Returns the relative bounding box that must be entity-free in order for the block to be placed. More...
 
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). More...
 
virtual bool IsInsideBlock (const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const
 Tests if a_RelPosition is inside the block, where a_RelPosition is relative to the origin of the block. More...
 
virtual bool IsUseable (void) const
 Called to check whether this block supports a rclk action. More...
 
virtual NIBBLETYPE MetaMirrorXY (NIBBLETYPE a_Meta) const
 Mirrors a given block meta around the XY plane. More...
 
virtual NIBBLETYPE MetaMirrorXZ (NIBBLETYPE a_Meta) const
 Mirros a given block meta around the XZ plane. More...
 
virtual NIBBLETYPE MetaMirrorYZ (NIBBLETYPE a_Meta) const
 Mirros a given block meta around the YZ plane. More...
 
virtual NIBBLETYPE MetaRotateCCW (NIBBLETYPE a_Meta) const
 Rotates a given block meta counter-clockwise. More...
 
virtual NIBBLETYPE MetaRotateCW (NIBBLETYPE a_Meta) const
 Rotates a given block meta clockwise. More...
 
virtual void OnBroken (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, const cEntity *a_Digger) const
 Called after a block gets broken (replaced with air), by natural means. More...
 
virtual void OnCancelRightClick (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const
 Called when a right click to this block is cancelled. More...
 
virtual void OnDigging (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos) const
 Called when the player starts digging the block. More...
 
virtual void OnNeighborChanged (cChunkInterface &a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const
 Called when a direct neighbor of this block has been changed. More...
 
virtual void OnPlaced (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const
 Called by cWorld::SetBlock() after the block has been set. More...
 
virtual bool OnUse (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const
 Called when the user right clicks the block and the block is useable. More...
 
- Static Public Member Functions inherited from cBlockHandler
static const cBlockHandlerFor (BLOCKTYPE a_BlockType)
 
static char FortuneDiscreteRandom (char a_MinDrop, char a_DefaultMax, unsigned char a_BonusMax, char a_DropCap=25)
 Returns a random number of drops taking into account fortune. More...
 
static void NeighborChanged (cChunkInterface &a_ChunkInterface, Vector3i a_NeighborPos, eBlockFace a_WhichNeighbor)
 Notifies the specified neighbor that the current block has changed. More...
 
static unsigned char ToolFortuneLevel (const cItem *a_Tool)
 Returns the fortune level of a tool, if it is a valid tool. More...
 
static bool ToolHasSilkTouch (const cItem *a_Tool)
 Returns true if the specified tool is valid and has a non-zero silk-touch enchantment. More...
 
- Protected Attributes inherited from cBlockHandler
const BLOCKTYPE m_BlockType
 

Detailed Description

template<bool NeedsLightToGrow>
class cBlockPlant< NeedsLightToGrow >

Base class for plants that use light values to decide whether to grow or not.

On block update, the plant decides whether to grow, die or stay as-is, based on the CanGrow() overridable method result.

Definition at line 12 of file BlockPlant.h.

Member Typedef Documentation

◆ Super

template<bool NeedsLightToGrow>
using cBlockPlant< NeedsLightToGrow >::Super = cBlockHandler
private

Definition at line 15 of file BlockPlant.h.

Member Enumeration Documentation

◆ PlantAction

template<bool NeedsLightToGrow>
enum cBlockPlant::PlantAction
protected

The action the plant can take on an update.

Enumerator
paDeath 
paGrowth 
paStay 

Definition at line 26 of file BlockPlant.h.

Constructor & Destructor Documentation

◆ ~cBlockPlant()

template<bool NeedsLightToGrow>
cBlockPlant< NeedsLightToGrow >::~cBlockPlant ( )
protecteddefault

Member Function Documentation

◆ BearFruit()

template<bool NeedsLightToGrow>
virtual void cBlockPlant< NeedsLightToGrow >::BearFruit ( cChunk a_Chunk,
const Vector3i  a_StemRelPos 
) const
inlineprivatevirtual

Grows the final produce next to the stem at the specified position.

Reimplemented in cBlockStemsHandler< ProduceBlockType, StemPickupType >.

Definition at line 169 of file BlockPlant.h.

◆ CanGrow()

template<bool NeedsLightToGrow>
virtual PlantAction cBlockPlant< NeedsLightToGrow >::CanGrow ( cChunk a_Chunk,
Vector3i  a_RelPos 
) const
inlineprotectedvirtual

Checks whether a plant can grow grow, based on what is returned from cBlockPlant::HasEnoughLight and a random check based on what is returned from cBlockPlant::GetGrowthChance.

Can return three values. paGrowth when the conditions are right for the plant to grow. paStay when the conditions are not quite right. paDeath is returned when there isn't enough light for the plant to survive. Plants that don't require light will never have a paDeath returned

Reimplemented in cBlockSugarCaneHandler, and cBlockCactusHandler.

Definition at line 81 of file BlockPlant.h.

◆ GetGrowthChance()

template<bool NeedsLightToGrow>
virtual int cBlockPlant< NeedsLightToGrow >::GetGrowthChance ( cChunk a_Chunk,
Vector3i  a_RelPos 
) const
inlineprotectedvirtual

Generates an int value between 4 and 25 based on surrounding blocks that affect how quickly the plant grows.

The higher the value, the less likely the plant is to grow

Definition at line 98 of file BlockPlant.h.

◆ HasEnoughLight()

template<bool NeedsLightToGrow>
static PlantAction cBlockPlant< NeedsLightToGrow >::HasEnoughLight ( cChunk a_Chunk,
Vector3i  a_RelPos 
)
inlinestaticprotected

Checks whether there is enough light for the plant to grow.

If the plant doesn't require light to grow, then it returns paGrowth. If the plant requires light to grow and there is enough light, it returns paGrowth. If the plant requires light to grow and there isn't enough light, it returns paStay. If the plant requires light to grow and there is too little light, it returns paDeath.

Definition at line 38 of file BlockPlant.h.

◆ OnUpdate()

template<bool NeedsLightToGrow>
virtual void cBlockPlant< NeedsLightToGrow >::OnUpdate ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
cBlockPluginInterface a_BlockPluginInterface,
cChunk a_Chunk,
const Vector3i  a_RelPos 
) const
inlineoverrideprivatevirtual

Called when the block gets ticked either by a random tick or by a queued tick.

Note that the coords in a_RelPos are chunk-relative!

Reimplemented from cBlockHandler.

Definition at line 140 of file BlockPlant.h.


The documentation for this class was generated from the following file: