diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-12-01 18:10:37 +0100 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-12-01 18:10:37 +0100 |
commit | 8e753fa590c60b357b10e013a4224381f8e2f6ea (patch) | |
tree | c735a1829518eb4f3d0137f78ff6c52eb535f9cd /src/Blocks | |
parent | Updated core (diff) | |
download | cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar.gz cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar.bz2 cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar.lz cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar.xz cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.tar.zst cuberite-8e753fa590c60b357b10e013a4224381f8e2f6ea.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockCocoaPod.h | 96 | ||||
-rw-r--r-- | src/Blocks/BlockHandler.cpp | 2 | ||||
-rw-r--r-- | src/Blocks/CMakeLists.txt | 1 |
3 files changed, 99 insertions, 0 deletions
diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h new file mode 100644 index 000000000..9e1d64cc6 --- /dev/null +++ b/src/Blocks/BlockCocoaPod.h @@ -0,0 +1,96 @@ +#pragma once + +#include "BlockHandler.h" +#include "../FastRandom.h" + + + + + +class cBlockCocoaPodHandler : + public cBlockHandler +{ +public: + cBlockCocoaPodHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + eBlockFace BlockFace = MetaToBlockFace(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockFace, true); + + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + a_Chunk.UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta); + + return ((BlockType == E_BLOCK_LOG) && ((BlockMeta & 0x3) == E_META_LOG_JUNGLE)); + } + + + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + { + cFastRandom Random; + + if (Random.NextInt(5) == 0) + { + NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); + NIBBLETYPE TypeMeta = Meta & 0x03; + int GrowState = (Meta & 0x12) >> 2; + + if (GrowState < 2) + { + ++GrowState; + a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, (NIBBLETYPE) (GrowState << 2 | TypeMeta)); + } + } + } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + int GrowState = (a_BlockMeta & 0x12) >> 2; + a_Pickups.Add(E_ITEM_DYE, ((GrowState >= 2) ? 3 : 1), E_META_DYE_BROWN); + } + + + static eBlockFace MetaToBlockFace(NIBBLETYPE a_Meta) + { + switch (a_Meta & 0x3) + { + case 0: return BLOCK_FACE_ZM; + case 1: return BLOCK_FACE_XP; + case 2: return BLOCK_FACE_ZP; + case 3: return BLOCK_FACE_XM; + default: + { + ASSERT(!"Bad meta"); + return BLOCK_FACE_NONE; + } + } + } + + + static NIBBLETYPE BlockFaceToMeta(eBlockFace a_BlockFace) + { + switch (a_BlockFace) + { + case BLOCK_FACE_ZM: return 0; + case BLOCK_FACE_XM: return 3; + case BLOCK_FACE_XP: return 1; + case BLOCK_FACE_ZP: return 2; + default: + { + ASSERT(!"Unknown face"); + return 0; + } + } + } + +} ; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 60f13a747..d532aa1dc 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -17,6 +17,7 @@ #include "BlockChest.h" #include "BlockCloth.h" #include "BlockCobWeb.h" +#include "BlockCocoaPod.h" #include "BlockCommandBlock.h" #include "BlockComparator.h" #include "BlockCrops.h" @@ -198,6 +199,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType); case E_BLOCK_CHEST: return new cBlockChestHandler (a_BlockType); case E_BLOCK_COAL_ORE: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_COCOA_POD: return new cBlockCocoaPodHandler (a_BlockType); case E_BLOCK_COMMAND_BLOCK: return new cBlockCommandBlockHandler (a_BlockType); case E_BLOCK_ACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); case E_BLOCK_COBBLESTONE: return new cBlockStoneHandler (a_BlockType); diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index eed949aab..ed3e321d4 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -24,6 +24,7 @@ SET (HDRS BlockChest.h BlockCloth.h BlockCobWeb.h + BlockCocoaPod.h BlockCommandBlock.h BlockComparator.h BlockCrops.h |