diff options
Diffstat (limited to 'src/Blocks')
-rw-r--r-- | src/Blocks/BlockBed.cpp | 25 | ||||
-rw-r--r-- | src/Blocks/BlockCauldron.h | 24 | ||||
-rw-r--r-- | src/Blocks/BlockHandler.cpp | 4 | ||||
-rw-r--r-- | src/Blocks/BlockLeaves.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockNewLeaves.h | 42 |
5 files changed, 81 insertions, 16 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index a6f3c36b6..3dad4feba 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,20 +63,29 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x8) + if (Meta & 0x4) { - // Is pillow - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_Player->SendMessageFailure("This bed is occupied."); } else { - // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (Meta & 0x8) { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + // Is pillow + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } + else + { + // Is foot end + Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + { + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + } + } + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); } + } else { a_Player->SendMessageFailure("You can only sleep at night"); } @@ -86,3 +95,5 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface + + diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index 09d5c3cbb..2e1032d2b 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -21,24 +21,30 @@ public: a_Pickups.push_back(cItem(E_ITEM_CAULDRON, 1, 0)); } - void OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - char Meta = a_ChunkInterface->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ ); - switch( a_Player->GetEquippedItem().m_ItemType ) + char Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + switch (a_Player->GetEquippedItem().m_ItemType) { case E_ITEM_WATER_BUCKET: { - a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, 3 ); - a_Player->GetInventory().RemoveOneEquippedItem(); - cItem NewItem(E_ITEM_BUCKET, 1); - a_Player->GetInventory().AddItem(NewItem); + if (Meta < 3) + { + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 3); + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + cItem NewItem(E_ITEM_BUCKET, 1); + a_Player->GetInventory().AddItem(NewItem); + } + } break; } case E_ITEM_GLASS_BOTTLE: { - if( Meta > 0 ) + if (Meta > 0) { - a_ChunkInterface->SetBlockMeta( a_BlockX, a_BlockY, a_BlockZ, --Meta); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, --Meta); a_Player->GetInventory().RemoveOneEquippedItem(); cItem NewItem(E_ITEM_POTIONS, 1, 0); a_Player->GetInventory().AddItem(NewItem); diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 09a1244ea..834727c9a 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -39,6 +39,7 @@ #include "BlockIce.h" #include "BlockLadder.h" #include "BlockLeaves.h" +#include "BlockNewLeaves.h" #include "BlockLever.h" #include "BlockMelon.h" #include "BlockMushroom.h" @@ -108,6 +109,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) switch(a_BlockType) { // Block handlers, alphabetically sorted: + case E_BLOCK_ACACIA_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType); case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); @@ -126,6 +128,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_COBBLESTONE_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_COBWEB: return new cBlockCobWebHandler (a_BlockType); case E_BLOCK_CROPS: return new cBlockCropsHandler (a_BlockType); + case E_BLOCK_DARK_OAK_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_DEAD_BUSH: return new cBlockDeadBushHandler (a_BlockType); case E_BLOCK_DETECTOR_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_DIAMOND_ORE: return new cBlockOreHandler (a_BlockType); @@ -169,6 +172,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType); + case E_BLOCK_NEW_LEAVES: return new cBlockNewLeavesHandler (a_BlockType); case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index ad6e440e2..7b8f0b378 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -139,6 +139,8 @@ bool HasNearLog(cBlockArea & a_Area, int a_BlockX, int a_BlockY, int a_BlockZ) { switch (Types[i]) { + case E_BLOCK_NEW_LEAVES: + case E_BLOCK_NEW_LOG: case E_BLOCK_LEAVES: case E_BLOCK_LOG: { diff --git a/src/Blocks/BlockNewLeaves.h b/src/Blocks/BlockNewLeaves.h new file mode 100644 index 000000000..5a267e8c6 --- /dev/null +++ b/src/Blocks/BlockNewLeaves.h @@ -0,0 +1,42 @@ +#pragma once +#include "BlockHandler.h" +#include "BlockLeaves.h" +#include "../World.h" + + + + + + +class cBlockNewLeavesHandler : + public cBlockLeavesHandler +{ +public: + cBlockNewLeavesHandler(BLOCKTYPE a_BlockType) + : cBlockLeavesHandler(a_BlockType) + { + } + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + MTRand rand; + + // Only the first 2 bits contain the display information, the others are for growing + if (rand.randInt(5) == 0) + { + a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, (a_BlockMeta & 3) + 4)); + } + } + + + void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ); + } +} ; + + + + + |