1
0
Fork 0

Renamed "select..." methods to "set..." and better IsValidEffect() function.

This commit is contained in:
Howaner 2014-07-31 18:15:39 +02:00
parent c49d4fd215
commit 6b1f7e7a45
4 changed files with 19 additions and 55 deletions

View File

@ -64,54 +64,18 @@ char cBeaconEntity::CalculatePyramidLevel(void)
bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel)
{
if (a_Effect == cEntityEffect::effNoEffect)
switch (a_Effect)
{
return true;
case cEntityEffect::effRegeneration: return (a_BeaconLevel >= 4);
case cEntityEffect::effStrength: return (a_BeaconLevel >= 3);
case cEntityEffect::effResistance: return (a_BeaconLevel >= 2);
case cEntityEffect::effJumpBoost: return (a_BeaconLevel >= 2);
case cEntityEffect::effSpeed: return (a_BeaconLevel >= 1);
case cEntityEffect::effHaste: return (a_BeaconLevel >= 1);
case cEntityEffect::effNoEffect: return true;
}
switch (a_BeaconLevel)
{
case 4:
{
// Beacon level 4
if (a_Effect == cEntityEffect::effRegeneration)
{
return true;
}
}
case 3:
{
// Beacon level 3
if (a_Effect == cEntityEffect::effStrength)
{
return true;
}
}
case 2:
{
// Beacon level 2
switch (a_Effect)
{
case cEntityEffect::effResistance:
case cEntityEffect::effJumpBoost:
{
return true;
}
}
}
case 1:
{
// Beacon level 1
switch (a_Effect)
{
case cEntityEffect::effSpeed:
case cEntityEffect::effHaste:
{
return true;
}
}
}
}
LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect);
return false;
}
@ -119,7 +83,7 @@ bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLe
bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
bool cBeaconEntity::SetPrimaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
@ -140,7 +104,7 @@ bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
bool cBeaconEntity::SelectSecondaryEffect(cEntityEffect::eType a_Effect)
bool cBeaconEntity::SetSecondaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{

View File

@ -55,11 +55,11 @@ public:
cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
/** Select the primary effect. Returns false when the effect is invalid.*/
bool SelectPrimaryEffect(cEntityEffect::eType a_Effect);
/** Sets the primary effect. Returns false when the effect is invalid. */
bool SetPrimaryEffect(cEntityEffect::eType a_Effect);
/** Select the secondary effect. Returns false when the effect is invalid. */
bool SelectSecondaryEffect(cEntityEffect::eType a_Effect);
/** Sets the secondary effect. Returns false when the effect is invalid. */
bool SetSecondaryEffect(cEntityEffect::eType a_Effect);
/** Calculate the amount of layers the pyramid below the beacon has. */
char CalculatePyramidLevel(void);

View File

@ -792,8 +792,8 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
}
Window->SetSlot(*m_Player, 0, cItem());
BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect);
BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect);
BeaconWindow->GetBeaconEntity()->SetPrimaryEffect(PrimaryEffect);
BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect);
}

View File

@ -771,13 +771,13 @@ void cWSSAnvil::LoadBeaconFromNBT(cBlockEntityList & a_BlockEntities, const cPar
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
if (CurrentLine >= 0)
{
Beacon->SelectPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
Beacon->SetPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
if (CurrentLine >= 0)
{
Beacon->SelectSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
Beacon->SetSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
// We are better than mojang, we load/save the beacon inventory!