Comment and code style fix
+ Add static keyword - Don't capture everything in lambda
This commit is contained in:
parent
742e27ad2f
commit
d9cd2f741d
@ -137,14 +137,15 @@ void cMobSpawnerEntity::SpawnEntity(void)
|
|||||||
return;
|
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 & Random = GetRandomProvider();
|
||||||
|
auto EntitySpawnTally = NearbyEntities;
|
||||||
|
|
||||||
bool HaveSpawnedEntity = false;
|
bool HaveSpawnedEntity = false;
|
||||||
for (short I = 0; I < m_SpawnCount; I++)
|
for (short I = 0; I < m_SpawnCount; I++)
|
||||||
{
|
{
|
||||||
if (NearbyEntities >= m_MaxNearbyEntities)
|
if (EntitySpawnTally >= m_MaxNearbyEntities)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -177,7 +178,7 @@ void cMobSpawnerEntity::SpawnEntity(void)
|
|||||||
{
|
{
|
||||||
HaveSpawnedEntity = true;
|
HaveSpawnedEntity = true;
|
||||||
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_MOBSPAWN, AbsPos, 0);
|
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_MOBSPAWN, AbsPos, 0);
|
||||||
NearbyEntities++;
|
EntitySpawnTally++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +200,7 @@ int cMobSpawnerEntity::GetNearbyPlayersNum(void)
|
|||||||
{
|
{
|
||||||
int NumPlayers = 0;
|
int NumPlayers = 0;
|
||||||
|
|
||||||
auto Callback = [&] (cEntity & a_Entity)
|
auto Callback = [this, &NumPlayers](cEntity & a_Entity)
|
||||||
{
|
{
|
||||||
if (!a_Entity.IsPlayer())
|
if (!a_Entity.IsPlayer())
|
||||||
{
|
{
|
||||||
@ -212,8 +213,7 @@ int cMobSpawnerEntity::GetNearbyPlayersNum(void)
|
|||||||
return false;
|
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);
|
m_World->ForEachEntityInBox(PlayerBoundingBox, Callback);
|
||||||
|
|
||||||
return NumPlayers;
|
return NumPlayers;
|
||||||
@ -227,7 +227,7 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType)
|
|||||||
{
|
{
|
||||||
int NumEntities = 0;
|
int NumEntities = 0;
|
||||||
|
|
||||||
auto Callback = [&] (cEntity & a_Entity)
|
auto Callback = [this, &NumEntities](cEntity & a_Entity)
|
||||||
{
|
{
|
||||||
if (!a_Entity.IsMob())
|
if (!a_Entity.IsMob())
|
||||||
{
|
{
|
||||||
@ -242,13 +242,8 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType)
|
|||||||
return false;
|
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);
|
m_World->ForEachEntityInBox(EntityBoundingBox, Callback);
|
||||||
|
|
||||||
return NumEntities;
|
return NumEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
|
||||||
// BlockInfested.h
|
// BlockInfested.h
|
||||||
|
|
||||||
|
// Declares the cBlockInfestedHandler class representing the handler for Silverfish blocks (Mojang calls them Monster Eggs)
|
||||||
|
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
|
|
||||||
/* This Block Handler describes the blocks spawning silver fishes. Mojang calls them monster egg */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cBlockInfestedHandler final:
|
class cBlockInfestedHandler final:
|
||||||
public cBlockHandler
|
public cBlockHandler
|
||||||
@ -14,17 +18,17 @@ public:
|
|||||||
|
|
||||||
using Super::Super;
|
using Super::Super;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
static void SpawnSilverfish(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos)
|
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
|
// 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);
|
const auto Position = Vector3f(a_BlockPos.x + 0.5f, a_BlockPos.y, a_BlockPos.z + 0.5f);
|
||||||
// Play particle
|
a_WorldInterface.SpawnMob(Position.x, Position.y, Position.z, mtSilverfish, false);
|
||||||
a_WorldInterface.GetBroadcastManager().BroadcastParticleEffect("explode", Pos, Vector3f(), 0.1f, 50);
|
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
|
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))
|
if (ToolHasSilkTouch(a_Tool))
|
||||||
{
|
{
|
||||||
return cItem(E_BLOCK_STONE);
|
return { E_BLOCK_STONE };
|
||||||
}
|
}
|
||||||
else
|
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_COBBLESTONE: return { E_BLOCK_COBBLESTONE };
|
||||||
case E_META_SILVERFISH_EGG_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS);
|
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_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_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);
|
case E_META_SILVERFISH_EGG_CHISELED_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_ORNAMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual void OnBroken(
|
virtual void OnBroken(
|
||||||
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
||||||
Vector3i a_BlockPos,
|
Vector3i a_BlockPos,
|
||||||
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
||||||
const cEntity * a_Digger
|
const cEntity * a_Digger
|
||||||
) const override
|
) const override
|
||||||
{
|
{
|
||||||
if (a_Digger != nullptr)
|
if (a_Digger != nullptr)
|
||||||
@ -85,4 +87,3 @@ private:
|
|||||||
return 11;
|
return 11;
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -1892,7 +1892,7 @@ void cFinishGenOreNests::GenerateOre(
|
|||||||
!IsBiomeMountain(BiomeSampleTwo) &&
|
!IsBiomeMountain(BiomeSampleTwo) &&
|
||||||
!IsBiomeMountain(BiomeSampleThree) &&
|
!IsBiomeMountain(BiomeSampleThree) &&
|
||||||
!IsBiomeMountain(BiomeSampleFour)
|
!IsBiomeMountain(BiomeSampleFour)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
namespace Explodinator
|
namespace Explodinator
|
||||||
{
|
{
|
||||||
const auto StepUnit = 0.3f;
|
static const auto StepUnit = 0.3f;
|
||||||
const auto KnockbackFactor = 25U;
|
static const auto KnockbackFactor = 25U;
|
||||||
const auto StepAttenuation = 0.225f;
|
static const auto StepAttenuation = 0.225f;
|
||||||
const auto TraceCubeSideLength = 16U;
|
static const auto TraceCubeSideLength = 16U;
|
||||||
const auto BoundingBoxStepUnit = 0.5;
|
static const auto BoundingBoxStepUnit = 0.5;
|
||||||
|
|
||||||
/** Converts an absolute floating-point Position into a Chunk-relative one. */
|
/** Converts an absolute floating-point Position into a Chunk-relative one. */
|
||||||
static Vector3f AbsoluteToRelative(const Vector3f a_Position, const cChunkCoords a_ChunkPosition)
|
static Vector3f AbsoluteToRelative(const Vector3f a_Position, const cChunkCoords a_ChunkPosition)
|
||||||
|
@ -134,9 +134,9 @@ public:
|
|||||||
|
|
||||||
/** Writes the specified block position as a single encoded 64-bit BigEndian integer.
|
/** Writes the specified block position as a single encoded 64-bit BigEndian integer.
|
||||||
The three coordinates are written in XYZ order. */
|
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.
|
/** Writes the specified block position as a single encoded 64-bit BigEndian integer.
|
||||||
|
@ -1130,7 +1130,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
const cItem Target(*GetSlot(0, a_Player));
|
const cItem Target(*GetSlot(0, a_Player));
|
||||||
const cItem Sacrifice(*GetSlot(1, a_Player));
|
const cItem Sacrifice(*GetSlot(1, a_Player));
|
||||||
|
|
||||||
// Output initialised as copy of target
|
// Output initialised as copy of target.
|
||||||
cItem Output(Target);
|
cItem Output(Target);
|
||||||
|
|
||||||
if (Target.IsEmpty())
|
if (Target.IsEmpty())
|
||||||
@ -1148,9 +1148,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
int NeedExp = 0;
|
int NeedExp = 0;
|
||||||
if (!Sacrifice.IsEmpty())
|
if (!Sacrifice.IsEmpty())
|
||||||
{
|
{
|
||||||
bool IsEnchantBook = (Sacrifice.m_ItemType == E_ITEM_ENCHANTED_BOOK);
|
|
||||||
|
|
||||||
RepairCost += Sacrifice.m_RepairCost;
|
RepairCost += Sacrifice.m_RepairCost;
|
||||||
|
|
||||||
// Can we repair with sacrifce material?
|
// Can we repair with sacrifce material?
|
||||||
if (Target.IsDamageable() && cItemHandler::GetItemHandler(Target)->CanRepairWithRawMaterial(Sacrifice.m_ItemType))
|
if (Target.IsDamageable() && cItemHandler::GetItemHandler(Target)->CanRepairWithRawMaterial(Sacrifice.m_ItemType))
|
||||||
{
|
{
|
||||||
@ -1166,8 +1165,9 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumItemsConsumed = 0;
|
char NumItemsConsumed = 0;
|
||||||
// Repair until out of materials, or fully repaired
|
|
||||||
|
// Repair until out of materials, or fully repaired:
|
||||||
while ((DamageDiff > 0) && (NumItemsConsumed < Sacrifice.m_ItemCount))
|
while ((DamageDiff > 0) && (NumItemsConsumed < Sacrifice.m_ItemCount))
|
||||||
{
|
{
|
||||||
Output.m_ItemDamage -= DamageDiff;
|
Output.m_ItemDamage -= DamageDiff;
|
||||||
@ -1176,10 +1176,12 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
|
|
||||||
++NumItemsConsumed;
|
++NumItemsConsumed;
|
||||||
}
|
}
|
||||||
m_StackSizeToBeUsedInRepair = static_cast<char>(NumItemsConsumed);
|
m_StackSizeToBeUsedInRepair = NumItemsConsumed;
|
||||||
}
|
}
|
||||||
else // Combining tools / armour
|
else // Combining tools / armour
|
||||||
{
|
{
|
||||||
|
const bool IsEnchantBook = (Sacrifice.m_ItemType == E_ITEM_ENCHANTED_BOOK);
|
||||||
|
|
||||||
// No result if we can't combine the items
|
// No result if we can't combine the items
|
||||||
if (!IsEnchantBook && (!Target.IsSameType(Sacrifice) || !Target.IsDamageable()))
|
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
|
// Durability = MaxDamage - m_ItemDamage = how far from broken
|
||||||
const short TargetDurability = Target.GetMaxDamage() - Target.m_ItemDamage;
|
const short TargetDurability = Target.GetMaxDamage() - Target.m_ItemDamage;
|
||||||
const short SacrificeDurability = Sacrifice.GetMaxDamage() - Sacrifice.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;
|
const short RepairDurability = SacrificeDurability + Target.GetMaxDamage() * 12 / 100;
|
||||||
|
|
||||||
// Don't give item a negative damage:
|
// Don't give item a negative damage:
|
||||||
@ -1270,7 +1273,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
Output.m_RepairCost = RepairCost;
|
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))
|
if (Target.IsEqual(Output))
|
||||||
{
|
{
|
||||||
Output.Empty();
|
Output.Empty();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user