diff options
Diffstat (limited to '')
-rw-r--r-- | src/BlockEntities/MobSpawnerEntity.cpp | 21 | ||||
-rw-r--r-- | src/Blocks/BlockInfested.h | 39 | ||||
-rw-r--r-- | src/Generating/FinishGen.cpp | 2 | ||||
-rw-r--r-- | src/Physics/Explodinator.cpp | 10 | ||||
-rw-r--r-- | src/Protocol/Packetizer.h | 4 | ||||
-rw-r--r-- | src/UI/SlotArea.cpp | 19 |
6 files changed, 47 insertions, 48 deletions
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 8095fc12b..78312edb1 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -137,14 +137,15 @@ void cMobSpawnerEntity::SpawnEntity(void) return; } - bool EntitiesSpawned = m_World->DoWithChunk(GetChunkX(), GetChunkZ(), [&](cChunk & a_Chunk) + bool EntitiesSpawned = m_World->DoWithChunk(GetChunkX(), GetChunkZ(), [this, NearbyEntities](cChunk & a_Chunk) { auto & Random = GetRandomProvider(); + auto EntitySpawnTally = NearbyEntities; bool HaveSpawnedEntity = false; for (short I = 0; I < m_SpawnCount; I++) { - if (NearbyEntities >= m_MaxNearbyEntities) + if (EntitySpawnTally >= m_MaxNearbyEntities) { break; } @@ -177,7 +178,7 @@ void cMobSpawnerEntity::SpawnEntity(void) { HaveSpawnedEntity = true; m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_MOBSPAWN, AbsPos, 0); - NearbyEntities++; + EntitySpawnTally++; } } } @@ -199,7 +200,7 @@ int cMobSpawnerEntity::GetNearbyPlayersNum(void) { int NumPlayers = 0; - auto Callback = [&] (cEntity & a_Entity) + auto Callback = [this, &NumPlayers](cEntity & a_Entity) { if (!a_Entity.IsPlayer()) { @@ -212,8 +213,7 @@ int cMobSpawnerEntity::GetNearbyPlayersNum(void) return false; }; - auto PlayerBoundingBox = cBoundingBox(Vector3d(m_Pos.x, m_Pos.y - m_RequiredPlayerRange, m_Pos.z), m_RequiredPlayerRange, m_RequiredPlayerRange * 2); - + const cBoundingBox PlayerBoundingBox(Vector3d(m_Pos.x, m_Pos.y - m_RequiredPlayerRange, m_Pos.z), m_RequiredPlayerRange, m_RequiredPlayerRange * 2); m_World->ForEachEntityInBox(PlayerBoundingBox, Callback); return NumPlayers; @@ -227,7 +227,7 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) { int NumEntities = 0; - auto Callback = [&] (cEntity & a_Entity) + auto Callback = [this, &NumEntities](cEntity & a_Entity) { if (!a_Entity.IsMob()) { @@ -242,13 +242,8 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) return false; }; - auto EntityBoundingBox = cBoundingBox(Vector3d(m_Pos.x, m_Pos.y - 4, m_Pos.z), m_SpawnRange, 8); - + const cBoundingBox EntityBoundingBox(Vector3d(m_Pos.x, m_Pos.y - 4, m_Pos.z), m_SpawnRange, 8); m_World->ForEachEntityInBox(EntityBoundingBox, Callback); return NumEntities; } - - - - diff --git a/src/Blocks/BlockInfested.h b/src/Blocks/BlockInfested.h index d2b634dd0..89948f077 100644 --- a/src/Blocks/BlockInfested.h +++ b/src/Blocks/BlockInfested.h @@ -1,9 +1,13 @@ // BlockInfested.h +// Declares the cBlockInfestedHandler class representing the handler for Silverfish blocks (Mojang calls them Monster Eggs) + #include "../Entities/Player.h" -/* This Block Handler describes the blocks spawning silver fishes. Mojang calls them monster egg */ + + + class cBlockInfestedHandler final: public cBlockHandler @@ -14,17 +18,17 @@ public: using Super::Super; +private: + static void SpawnSilverfish(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos) { - auto Pos = Vector3f(a_BlockPos.x - 0.5f, a_BlockPos.y - 0.5f, a_BlockPos.z - 0.5f); // TODO: only display animation if the difficulty allows mob spawns - Add when difficulty is implemented - // Spawn Silverfish - a_WorldInterface.SpawnMob(Pos.x, Pos.y, Pos.z, mtSilverfish, false); - // Play particle - a_WorldInterface.GetBroadcastManager().BroadcastParticleEffect("explode", Pos, Vector3f(), 0.1f, 50); + + const auto Position = Vector3f(a_BlockPos.x + 0.5f, a_BlockPos.y, a_BlockPos.z + 0.5f); + a_WorldInterface.SpawnMob(Position.x, Position.y, Position.z, mtSilverfish, false); + a_WorldInterface.GetBroadcastManager().BroadcastParticleEffect("explode", Position, Vector3f(), 0.1f, 50); } -private: virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { @@ -34,31 +38,29 @@ private: { if (ToolHasSilkTouch(a_Tool)) { - return cItem(E_BLOCK_STONE); + return { E_BLOCK_STONE }; } else { - return cItem(E_BLOCK_COBBLESTONE); + return { E_BLOCK_COBBLESTONE }; } } - case E_META_SILVERFISH_EGG_COBBLESTONE: return cItem(E_BLOCK_COBBLESTONE); - case E_META_SILVERFISH_EGG_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS); + case E_META_SILVERFISH_EGG_COBBLESTONE: return { E_BLOCK_COBBLESTONE }; + case E_META_SILVERFISH_EGG_STONE_BRICK: return { E_BLOCK_STONE_BRICKS }; case E_META_SILVERFISH_EGG_MOSSY_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_MOSSY); case E_META_SILVERFISH_EGG_CRACKED_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_CRACKED); case E_META_SILVERFISH_EGG_CHISELED_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_ORNAMENT); } + return {}; } - - - virtual void OnBroken( - cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, - const cEntity * a_Digger + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, + Vector3i a_BlockPos, + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { if (a_Digger != nullptr) @@ -85,4 +87,3 @@ private: return 11; } } ; - diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 5f8099922..10bd4eac9 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1892,7 +1892,7 @@ void cFinishGenOreNests::GenerateOre( !IsBiomeMountain(BiomeSampleTwo) && !IsBiomeMountain(BiomeSampleThree) && !IsBiomeMountain(BiomeSampleFour) - ) + ) { return; } diff --git a/src/Physics/Explodinator.cpp b/src/Physics/Explodinator.cpp index 59da02119..e12b9bd60 100644 --- a/src/Physics/Explodinator.cpp +++ b/src/Physics/Explodinator.cpp @@ -16,11 +16,11 @@ namespace Explodinator { - const auto StepUnit = 0.3f; - const auto KnockbackFactor = 25U; - const auto StepAttenuation = 0.225f; - const auto TraceCubeSideLength = 16U; - const auto BoundingBoxStepUnit = 0.5; + static const auto StepUnit = 0.3f; + static const auto KnockbackFactor = 25U; + static const auto StepAttenuation = 0.225f; + static const auto TraceCubeSideLength = 16U; + static const auto BoundingBoxStepUnit = 0.5; /** Converts an absolute floating-point Position into a Chunk-relative one. */ static Vector3f AbsoluteToRelative(const Vector3f a_Position, const cChunkCoords a_ChunkPosition) diff --git a/src/Protocol/Packetizer.h b/src/Protocol/Packetizer.h index b2f2b11f4..4ece6e4fa 100644 --- a/src/Protocol/Packetizer.h +++ b/src/Protocol/Packetizer.h @@ -134,9 +134,9 @@ public: /** Writes the specified block position as a single encoded 64-bit BigEndian integer. The three coordinates are written in XYZ order. */ - inline void WriteXYZPosition64(const Vector3i & a_Pos) + inline void WriteXYZPosition64(const Vector3i a_Position) { - VERIFY(m_Out.WriteXYZPosition64(a_Pos.x, a_Pos.y, a_Pos.z)); + VERIFY(m_Out.WriteXYZPosition64(a_Position.x, a_Position.y, a_Position.z)); } /** Writes the specified block position as a single encoded 64-bit BigEndian integer. diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index c15a34714..98782800b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1130,7 +1130,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) const cItem Target(*GetSlot(0, a_Player)); const cItem Sacrifice(*GetSlot(1, a_Player)); - // Output initialised as copy of target + // Output initialised as copy of target. cItem Output(Target); if (Target.IsEmpty()) @@ -1148,9 +1148,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) int NeedExp = 0; if (!Sacrifice.IsEmpty()) { - bool IsEnchantBook = (Sacrifice.m_ItemType == E_ITEM_ENCHANTED_BOOK); - RepairCost += Sacrifice.m_RepairCost; + // Can we repair with sacrifce material? if (Target.IsDamageable() && cItemHandler::GetItemHandler(Target)->CanRepairWithRawMaterial(Sacrifice.m_ItemType)) { @@ -1166,8 +1165,9 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) return; } - int NumItemsConsumed = 0; - // Repair until out of materials, or fully repaired + char NumItemsConsumed = 0; + + // Repair until out of materials, or fully repaired: while ((DamageDiff > 0) && (NumItemsConsumed < Sacrifice.m_ItemCount)) { Output.m_ItemDamage -= DamageDiff; @@ -1176,10 +1176,12 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) ++NumItemsConsumed; } - m_StackSizeToBeUsedInRepair = static_cast<char>(NumItemsConsumed); + m_StackSizeToBeUsedInRepair = NumItemsConsumed; } else // Combining tools / armour { + const bool IsEnchantBook = (Sacrifice.m_ItemType == E_ITEM_ENCHANTED_BOOK); + // No result if we can't combine the items if (!IsEnchantBook && (!Target.IsSameType(Sacrifice) || !Target.IsDamageable())) { @@ -1197,7 +1199,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) // Durability = MaxDamage - m_ItemDamage = how far from broken const short TargetDurability = Target.GetMaxDamage() - Target.m_ItemDamage; const short SacrificeDurability = Sacrifice.GetMaxDamage() - Sacrifice.m_ItemDamage; - // How much durability to repair by: + + // How much durability to repair by. const short RepairDurability = SacrificeDurability + Target.GetMaxDamage() * 12 / 100; // Don't give item a negative damage: @@ -1270,7 +1273,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) Output.m_RepairCost = RepairCost; } - // If after everything, output will be the same then no point enchanting + // If after everything, output will be the same then no point enchanting: if (Target.IsEqual(Output)) { Output.Empty(); |