diff options
author | 12xx12 <44411062+12xx12@users.noreply.github.com> | 2020-10-08 21:13:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 21:13:44 +0200 |
commit | 3381c0f6d6671a485283c889b036c0a431e2a2b9 (patch) | |
tree | bf32b4d9c8d8e6c4c8d232ca6ad16975ee6d17c6 /src/Blocks | |
parent | Fix cmake not adding Werror on clang, and _lots_ of warnings (#4963) (diff) | |
download | cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.gz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.bz2 cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.lz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.xz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.zst cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockBed.cpp | 4 | ||||
-rw-r--r-- | src/Blocks/BlockBed.h | 3 | ||||
-rw-r--r-- | src/Blocks/BlockBigFlower.h | 8 | ||||
-rw-r--r-- | src/Blocks/BlockCake.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockDoor.cpp | 8 | ||||
-rw-r--r-- | src/Blocks/BlockDoor.h | 3 | ||||
-rw-r--r-- | src/Blocks/BlockFence.h | 5 | ||||
-rw-r--r-- | src/Blocks/BlockHandler.h | 19 | ||||
-rw-r--r-- | src/Blocks/BlockIce.h | 7 | ||||
-rw-r--r-- | src/Blocks/BlockMobSpawner.h | 22 | ||||
-rw-r--r-- | src/Blocks/BlockOre.h | 33 | ||||
-rw-r--r-- | src/Blocks/BlockPiston.cpp | 10 | ||||
-rw-r--r-- | src/Blocks/BlockPiston.h | 6 | ||||
-rw-r--r-- | src/Blocks/BlockRail.h | 5 | ||||
-rw-r--r-- | src/Blocks/ChunkInterface.cpp | 4 | ||||
-rw-r--r-- | src/Blocks/ChunkInterface.h | 2 |
16 files changed, 87 insertions, 54 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index fb6bb29c7..58ff720c8 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -18,9 +18,11 @@ void cBlockBedHandler::OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, const Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const { + UNUSED(a_Digger); auto Direction = MetaDataToDirection(a_OldBlockMeta & 0x03); if ((a_OldBlockMeta & 0x08) != 0) { diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index eb36ede5c..266fa7d69 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -57,7 +57,8 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, const Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override; virtual bool OnUse( diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index e6e7f58fa..c3adf8dc7 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -115,8 +115,14 @@ private: - virtual void OnBroken(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, const Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta) const override + virtual void OnBroken( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, + const Vector3i a_BlockPos, + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger + ) const override { + UNUSED(a_Digger); if ((a_OldBlockMeta & 0x8) != 0) { // Was upper part of flower diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h index b67da5222..b93814955 100644 --- a/src/Blocks/BlockCake.h +++ b/src/Blocks/BlockCake.h @@ -36,7 +36,7 @@ private: a_Player.GetStatManager().AddValue(Statistic::EatCakeSlice); if (Meta >= 5) { - a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockPos); + a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockPos, &a_Player); } else { diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index fbd236b1d..d97bd9696 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -7,8 +7,14 @@ -void cBlockDoorHandler::OnBroken(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta) const +void cBlockDoorHandler::OnBroken( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, + Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, + NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger +) const { + UNUSED(a_Digger); // A part of the multiblock door was broken; the relevant half will drop any pickups as required. // All that is left to do is to delete the other half of the multiblock. diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 097bdba40..56493321f 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -142,7 +142,8 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override; virtual bool OnUse( diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h index c6cad0198..cc4f35fea 100644 --- a/src/Blocks/BlockFence.h +++ b/src/Blocks/BlockFence.h @@ -156,9 +156,11 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { + UNUSED(a_Digger); // Destroy any leash knot tied to the fence: auto leashKnot = cLeashKnot::FindKnotAtPos(a_WorldInterface, a_BlockPos); if (leashKnot != nullptr) @@ -166,7 +168,6 @@ private: leashKnot->SetShouldSelfDestroy(); } } - }; diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 13c3a84af..772536003 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -73,24 +73,15 @@ public: cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange ) const {} - /** Called just after the player breaks the block. + /** Called after a block gets broken (replaced with air), by natural means. The block is already dug up in the world, the original block type and meta is passed in a_OldBlockType and a_OldBlockMeta. - By default does nothing special, descendants may provide further behavior. */ - virtual void OnPlayerBrokeBlock( - cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - cPlayer & a_Player, - Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) const {} - - /** Called after a block gets broken (replaced with air), either by player or by natural means. - If by player, it is called before the OnPlayerBrokeBlock() callback. - The block is already dug up in the world, the original block type and meta is passed in a_OldBlockType and a_OldBlockMeta. - By default notifies all direct neighbors via their OnNeighborChanged() callbacks. */ + By default notifies all direct neighbors via their OnNeighborChanged() callbacks. + You can determine what kind of entity broke the block (e.g. player) by checking a_Digger! */ virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const {} /** Called when a direct neighbor of this block has been changed. diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index c61abef57..8ff6415fb 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -81,7 +81,8 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { // If there's a solid block or a liquid underneath, convert to water, rather than air @@ -97,6 +98,10 @@ private: } } + + + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override { UNUSED(a_Meta); diff --git a/src/Blocks/BlockMobSpawner.h b/src/Blocks/BlockMobSpawner.h index a002a4eb9..27d3d61de 100644 --- a/src/Blocks/BlockMobSpawner.h +++ b/src/Blocks/BlockMobSpawner.h @@ -54,21 +54,27 @@ private: - virtual void OnPlayerBrokeBlock( + virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - cPlayer & a_Player, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { - auto handler = a_Player.GetEquippedItem().GetHandler(); - if (!a_Player.IsGameModeSurvival() || !handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER)) + if (!a_Digger->IsPlayer()) + { + return; + } + + const auto Player = static_cast<const cPlayer *>(a_Digger); + auto Handler = Player->GetEquippedItem().GetHandler(); + if (!Player->IsGameModeSurvival() || !Handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER)) { return; } - auto & random = GetRandomProvider(); - int reward = 15 + random.RandInt(14) + random.RandInt(14); - a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, reward); + auto & Random = GetRandomProvider(); + int Reward = 15 + Random.RandInt(14) + Random.RandInt(14); + a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, Reward); } } ; diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h index 023e149d9..6d6c2a097 100644 --- a/src/Blocks/BlockOre.h +++ b/src/Blocks/BlockOre.h @@ -64,26 +64,33 @@ private: - virtual void OnPlayerBrokeBlock( + virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - cPlayer & a_Player, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + Vector3i a_BlockPos, + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { - if (!a_Player.IsGameModeSurvival()) + if (!a_Digger->IsPlayer()) + { + return; + } + + const auto Player = static_cast<const cPlayer *>(a_Digger); + if (!Player->IsGameModeSurvival()) { // Don't drop XP unless the player is in survival mode. return; } - if (a_Player.GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0) + if (Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0) { // Don't drop XP when the ore is mined with the Silk Touch enchantment return; } - auto & random = GetRandomProvider(); - int reward = 0; + auto & Random = GetRandomProvider(); + int Reward = 0; switch (a_OldBlockType) { @@ -91,36 +98,36 @@ private: case E_BLOCK_LAPIS_ORE: { // Lapis and nether quartz get 2 - 5 experience - reward = random.RandInt(2, 5); + Reward = Random.RandInt(2, 5); break; } case E_BLOCK_REDSTONE_ORE: case E_BLOCK_REDSTONE_ORE_GLOWING: { // Redstone gets 1 - 5 experience - reward = random.RandInt(1, 5); + Reward = Random.RandInt(1, 5); break; } case E_BLOCK_DIAMOND_ORE: case E_BLOCK_EMERALD_ORE: { // Diamond and emerald get 3 - 7 experience - reward = random.RandInt(3, 7); + Reward = Random.RandInt(3, 7); break; } case E_BLOCK_COAL_ORE: { // Coal gets 0 - 2 experience - reward = random.RandInt(2); + Reward = Random.RandInt(2); break; } default: break; } - if (reward > 0) + if (Reward > 0) { - a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, reward); + a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, Reward); } } } ; diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 7e6ff5e3f..20863cdf3 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -289,9 +289,11 @@ bool cBlockPistonHandler::CanPushBlock( void cBlockPistonHandler::OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const { + UNUSED(a_Digger); if (!IsExtended(a_OldBlockMeta)) { return; @@ -301,7 +303,7 @@ void cBlockPistonHandler::OnBroken( if ( cChunkDef::IsValidHeight(Extension.y) && (a_ChunkInterface.GetBlock(Extension) == E_BLOCK_PISTON_EXTENSION) - ) + ) { // If the piston is extended, destroy the extension as well: a_ChunkInterface.SetBlock(Extension, E_BLOCK_AIR, 0); @@ -318,9 +320,11 @@ void cBlockPistonHandler::OnBroken( void cBlockPistonHeadHandler::OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const { + UNUSED(a_Digger); const auto Base = a_BlockPos - cBlockPistonHandler::MetadataToOffset(a_OldBlockMeta); if (!cChunkDef::IsValidHeight(Base.y)) { diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index fd8f3fe8a..2c3ee4f6a 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -128,7 +128,8 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override; /** Moves a list of blocks in a specific direction */ @@ -156,7 +157,8 @@ public: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override; virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index af85e0afc..7c147d48a 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -77,10 +77,11 @@ private: virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { - Super::OnBroken(a_ChunkInterface, a_WorldInterface, a_BlockPos, a_OldBlockType, a_OldBlockMeta); + Super::OnBroken(a_ChunkInterface, a_WorldInterface, a_BlockPos, a_OldBlockType, a_OldBlockMeta, a_Digger); // Alert diagonal rails: NeighborChanged(a_ChunkInterface, a_BlockPos + Vector3i( 1, 1, 0), BLOCK_FACE_NONE); diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp index 3af085c2a..37ed70615 100644 --- a/src/Blocks/ChunkInterface.cpp +++ b/src/Blocks/ChunkInterface.cpp @@ -101,7 +101,7 @@ bool cChunkInterface::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a -bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos) +bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, cEntity * a_Digger) { BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; @@ -112,7 +112,7 @@ bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, Vector3i a_Bl return false; } - cBlockHandler::For(BlockType).OnBroken(*this, a_WorldInterface, a_BlockPos, BlockType, BlockMeta); + cBlockHandler::For(BlockType).OnBroken(*this, a_WorldInterface, a_BlockPos, BlockType, BlockMeta, a_Digger); return true; } diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index a8ebb7a41..a8fcd6187 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -69,7 +69,7 @@ public: virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override; - bool DigBlock(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos); + bool DigBlock(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, cEntity * a_Digger); /** Digs the block and spawns the relevant pickups, as if a_Digger used a_Tool to dig the block. */ void DropBlockAsPickups(Vector3i a_BlockPos, const cEntity * a_Digger = nullptr, const cItem * a_Tool = nullptr); |