1
0

Comment and code style fix

+ Add static keyword
- Don't capture everything in lambda
This commit is contained in:
Tiger Wang 2020-12-20 02:13:34 +00:00
parent 742e27ad2f
commit d9cd2f741d
6 changed files with 47 additions and 48 deletions

View File

@ -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;
}

View File

@ -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,26 +38,24 @@ 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,
@ -85,4 +87,3 @@ private:
return 11;
}
} ;

View File

@ -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)

View File

@ -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.

View File

@ -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();