1
0

Merge pull request #1224 from mc-server/fixes-potions

Fix for potion color after tossing
This commit is contained in:
Mattes D 2014-07-19 13:29:50 +02:00
commit e9a9bbf02e
5 changed files with 30 additions and 14 deletions

View File

@ -2,11 +2,15 @@
#include "SplashPotionEntity.h"
#include "Pawn.h"
#include "../ClientHandle.h"
/// Converts an angle in radians into a byte representation used by the network protocol
#define ANGLE_TO_PROTO(X) (Byte)(X * 255 / 360)
////////////////////////////////////////////////////////////////////////////////
// cSplashPotionEntityCallback:
@ -72,12 +76,12 @@ cSplashPotionEntity::cSplashPotionEntity(
const Vector3d & a_Speed,
cEntityEffect::eType a_EntityEffectType,
cEntityEffect a_EntityEffect,
int a_PotionParticleType
int a_PotionColor
) :
super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
m_EntityEffectType(a_EntityEffectType),
m_EntityEffect(a_EntityEffect),
m_PotionParticleType(a_PotionParticleType)
m_PotionColor(a_PotionColor)
{
SetSpeed(a_Speed);
}
@ -112,7 +116,17 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos)
cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect);
m_World->ForEachEntity(Callback);
m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionParticleType);
m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionColor);
}
void cSplashPotionEntity::SpawnOn(cClientHandle & a_Client)
{
a_Client.SendSpawnObject(*this, 73, m_PotionColor, ANGLE_TO_PROTO(GetYaw()), ANGLE_TO_PROTO(GetPitch()));
a_Client.SendEntityMetadata(*this);
}

View File

@ -31,22 +31,22 @@ public:
const Vector3d & a_Speed,
cEntityEffect::eType a_EntityEffectType,
cEntityEffect a_EntityEffect,
int a_PotionParticleType
int a_PotionColor
);
cEntityEffect::eType GetEntityEffectType (void) const { return m_EntityEffectType; }
cEntityEffect GetEntityEffect (void) const { return m_EntityEffect; }
int GetPotionParticleType(void) const { return m_PotionParticleType; }
cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; }
cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
int GetPotionColor(void) const { return m_PotionColor; }
void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; }
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
void SetPotionParticleType(int a_PotionParticleType) { m_PotionParticleType = a_PotionParticleType; }
void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; }
protected:
cEntityEffect::eType m_EntityEffectType;
cEntityEffect m_EntityEffect;
int m_PotionParticleType;
int m_PotionColor;
// cProjectileEntity overrides:
@ -56,4 +56,6 @@ protected:
/** Splashes the potion, fires its particle effects and sounds
@param a_HitPos The position where the potion will splash */
void Splash(const Vector3d & a_HitPos);
virtual void SpawnOn(cClientHandle & a_Client) override;
} ; // tolua_export

View File

@ -17,8 +17,8 @@ public:
}
/** Returns the potion particle type (used by the client for visuals), based on the potion's damage value */
static int GetPotionParticleType(short a_ItemDamage)
/** Returns the potion color (used by the client for visuals), based on the potion's damage value */
static int GetPotionColor(short a_ItemDamage)
{
// Lowest six bits
return (a_ItemDamage & 0x3f);
@ -156,7 +156,7 @@ public:
cSplashPotionEntity * Projectile = new cSplashPotionEntity(
a_Player, Pos.x, Pos.y, Pos.z, Speed,
GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage),
GetEntityEffectIntensity(PotionDamage)), GetPotionParticleType(PotionDamage)
GetEntityEffectIntensity(PotionDamage)), GetPotionColor(PotionDamage)
);
if (Projectile == NULL)
{

View File

@ -613,7 +613,7 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
m_Writer.AddInt("EffectDuration", (Int16)Potion->GetEntityEffect().GetDuration());
m_Writer.AddShort("EffectIntensity", Potion->GetEntityEffect().GetIntensity());
m_Writer.AddDouble("EffectDistanceModifier", Potion->GetEntityEffect().GetDistanceModifier());
m_Writer.AddInt("PotionName", Potion->GetPotionParticleType());
m_Writer.AddInt("PotionName", Potion->GetPotionColor());
}
case cProjectileEntity::pkGhastFireball:
{

View File

@ -1681,7 +1681,7 @@ void cWSSAnvil::LoadSplashPotionFromNBT(cEntityList & a_Entities, const cParsedN
SplashPotion->SetEntityEffectType((cEntityEffect::eType) a_NBT.FindChildByName(a_TagIdx, "EffectType"));
SplashPotion->SetEntityEffect(cEntityEffect(EffectDuration, EffectIntensity, EffectDistanceModifier));
SplashPotion->SetPotionParticleType(a_NBT.FindChildByName(a_TagIdx, "PotionName"));
SplashPotion->SetPotionColor(a_NBT.FindChildByName(a_TagIdx, "PotionName"));
// Store the new splash potion in the entities list:
a_Entities.push_back(SplashPotion.release());