diff options
author | Mattes D <github@xoft.cz> | 2019-10-16 10:06:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 10:06:34 +0200 |
commit | 221cc4ec5cb6301743e947eaabed3fecedba796f (patch) | |
tree | 4e44c8bb7523e5d1d04468fc906ae24674c10abc /src/Blocks/BlockPlant.h | |
parent | Fixed crash in hopper while pulling items from blockentity above itself (#4412) (diff) | |
download | cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.gz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.bz2 cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.lz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.xz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.zst cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.zip |
Diffstat (limited to 'src/Blocks/BlockPlant.h')
-rw-r--r-- | src/Blocks/BlockPlant.h | 80 |
1 files changed, 48 insertions, 32 deletions
diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h index bab34f798..02092fc38 100644 --- a/src/Blocks/BlockPlant.h +++ b/src/Blocks/BlockPlant.h @@ -1,25 +1,30 @@ -// BlockPlant.h - -// Base class for any growing block - +#pragma once +#include "BlockHandler.h" -#pragma once -#include "BlockHandler.h" -class cBlockPlant : public cBlockHandler +/** Base class for plants that use light values to decide whether to grow or not. */ +template <bool NeedsLightToGrow> +class cBlockPlant: + public cBlockHandler { - typedef cBlockHandler Super; - bool m_NeedLightToGrow; + using super = cBlockHandler; + public: - cBlockPlant(BLOCKTYPE a_BlockType, bool a_LightToGrow) - : Super(a_BlockType), m_NeedLightToGrow(a_LightToGrow){} + + cBlockPlant(BLOCKTYPE a_BlockType): + super(a_BlockType) + { + } + protected: + + /** The action the plant can take on an update. */ enum PlantAction { paDeath, @@ -27,6 +32,10 @@ protected: paStay }; + + + + /** 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. @@ -37,34 +46,37 @@ protected: { // If the plant requires light to grow, check to see if there is enough light // Otherwise, return true - if (m_NeedLightToGrow) + if (!NeedsLightToGrow) { - NIBBLETYPE Blocklight = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ); - NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ); - NIBBLETYPE Light = a_Chunk.GetTimeAlteredLight(SkyLight); - - // If the amount of light provided by blocks is greater than the sky light, use it instead - if (Blocklight > Light) - { - Light = Blocklight; - } + return paGrowth; + } + NIBBLETYPE Blocklight = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ); + NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ); + NIBBLETYPE Light = a_Chunk.GetTimeAlteredLight(SkyLight); - // Based on light levels, decide between growth, stay and death: - if (Light > 8) - { - return paGrowth; - } - else if ((Blocklight < 9) && (SkyLight < 9)) - { - return paDeath; - } + // If the amount of light provided by blocks is greater than the sky light, use it instead + if (Blocklight > Light) + { + Light = Blocklight; + } - return paStay; + // Based on light levels, decide between growth, stay and death: + if (Light > 8) + { + return paGrowth; + } + else if ((Blocklight < 9) && (SkyLight < 9)) + { + return paDeath; } - return paGrowth; + return paStay; } + + + + /** 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. @@ -84,6 +96,10 @@ protected: return Action; } + + + + /** Generates a 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 */ virtual int GetGrowthChance(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) |