diff options
author | worktycho <work.tycho@gmail.com> | 2013-12-09 18:51:12 +0100 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2013-12-09 18:51:12 +0100 |
commit | 843605d59ebc128be0a578dc6f45ef8c05da6e79 (patch) | |
tree | 3ffebc6ba27baf7a9e1d4bc51501ffeea9b14226 /src/Blocks/BlockCactus.h | |
parent | merged makefile changes (diff) | |
parent | Fix Undefined behavior at Bindings/LuaWindow line 32 (diff) | |
download | cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.gz cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.bz2 cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.lz cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.xz cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.zst cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.zip |
Diffstat (limited to 'src/Blocks/BlockCactus.h')
-rw-r--r-- | src/Blocks/BlockCactus.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h new file mode 100644 index 000000000..7a9088178 --- /dev/null +++ b/src/Blocks/BlockCactus.h @@ -0,0 +1,82 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockCactusHandler : + public cBlockHandler +{ +public: + cBlockCactusHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Reset meta to 0 + a_Pickups.push_back(cItem(m_BlockType, 1, 0)); + } + + + virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + if (a_RelY <= 0) + { + return false; + } + BLOCKTYPE Surface = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); + if ((Surface != E_BLOCK_SAND) && (Surface != E_BLOCK_CACTUS)) + { + // Cactus can only be placed on sand and itself + return false; + } + + // Check surroundings. Cacti may ONLY be surrounded by air + static const struct + { + int x, z; + } Coords[] = + { + {-1, 0}, + { 1, 0}, + { 0, -1}, + { 0, 1}, + } ; + for (int i = 0; i < ARRAYCOUNT(Coords); i++) + { + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + if ( + a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) && + (BlockType != E_BLOCK_AIR) + ) + { + return false; + } + } // for i - Coords[] + + return true; + } + + + void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + { + a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1); + } + + + virtual const char * GetStepSound(void) override + { + return "step.cloth"; + } +} ; + + + + |