Reformatted cItemPotionHandler.
This commit is contained in:
parent
cd1e6f8ef0
commit
64c8b0d51b
@ -319,7 +319,8 @@ enum ENUM_ITEM_ID
|
|||||||
E_ITEM_GHAST_TEAR = 370,
|
E_ITEM_GHAST_TEAR = 370,
|
||||||
E_ITEM_GOLD_NUGGET = 371,
|
E_ITEM_GOLD_NUGGET = 371,
|
||||||
E_ITEM_NETHER_WART = 372,
|
E_ITEM_NETHER_WART = 372,
|
||||||
E_ITEM_POTIONS = 373,
|
E_ITEM_POTION = 373,
|
||||||
|
E_ITEM_POTIONS = 373, // OBSOLETE, use E_ITEM_POTION instead
|
||||||
E_ITEM_GLASS_BOTTLE = 374,
|
E_ITEM_GLASS_BOTTLE = 374,
|
||||||
E_ITEM_SPIDER_EYE = 375,
|
E_ITEM_SPIDER_EYE = 375,
|
||||||
E_ITEM_FERMENTED_SPIDER_EYE = 376,
|
E_ITEM_FERMENTED_SPIDER_EYE = 376,
|
||||||
|
@ -9,52 +9,67 @@ class cItemPotionHandler:
|
|||||||
{
|
{
|
||||||
typedef cItemHandler super;
|
typedef cItemHandler super;
|
||||||
|
|
||||||
int GetPotionName(short a_ItemDamage)
|
public:
|
||||||
|
|
||||||
|
cItemPotionHandler():
|
||||||
|
super(E_ITEM_POTION)
|
||||||
{
|
{
|
||||||
// First six bits (least significant)
|
|
||||||
return a_ItemDamage & 0x3F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cEntityEffect::eType GetEntityEffectType(short a_ItemDamage)
|
|
||||||
|
/** Returns the potion particle type (used by the client for visuals), based on the potion's damage value */
|
||||||
|
static int GetPotionParticleType(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
// First four bits (least significant)
|
// Lowest six bits
|
||||||
|
return (a_ItemDamage & 0x3f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Translates the potion's damage value into the entity effect that the potion gives */
|
||||||
|
static cEntityEffect::eType GetEntityEffectType(short a_ItemDamage)
|
||||||
|
{
|
||||||
|
// Lowest four bits
|
||||||
// Potion effect bits are different from entity effect values
|
// Potion effect bits are different from entity effect values
|
||||||
// For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits
|
// For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits
|
||||||
switch (a_ItemDamage & 0xF)
|
switch (a_ItemDamage & 0x0f)
|
||||||
{
|
{
|
||||||
case 0x1: return cEntityEffect::effRegeneration;
|
case 0x01: return cEntityEffect::effRegeneration;
|
||||||
case 0x2: return cEntityEffect::effSpeed;
|
case 0x02: return cEntityEffect::effSpeed;
|
||||||
case 0x3: return cEntityEffect::effFireResistance;
|
case 0x03: return cEntityEffect::effFireResistance;
|
||||||
case 0x4: return cEntityEffect::effPoison;
|
case 0x04: return cEntityEffect::effPoison;
|
||||||
case 0x5: return cEntityEffect::effInstantHealth;
|
case 0x05: return cEntityEffect::effInstantHealth;
|
||||||
case 0x6: return cEntityEffect::effNightVision;
|
case 0x06: return cEntityEffect::effNightVision;
|
||||||
case 0x8: return cEntityEffect::effWeakness;
|
case 0x08: return cEntityEffect::effWeakness;
|
||||||
case 0x9: return cEntityEffect::effStrength;
|
case 0x09: return cEntityEffect::effStrength;
|
||||||
case 0xA: return cEntityEffect::effSlowness;
|
case 0x0a: return cEntityEffect::effSlowness;
|
||||||
case 0xC: return cEntityEffect::effInstantDamage;
|
case 0x0c: return cEntityEffect::effInstantDamage;
|
||||||
case 0xD: return cEntityEffect::effWaterBreathing;
|
case 0x0d: return cEntityEffect::effWaterBreathing;
|
||||||
case 0xE: return cEntityEffect::effInvisibility;
|
case 0x0e: return cEntityEffect::effInvisibility;
|
||||||
|
|
||||||
// No effect potions
|
// No effect potions
|
||||||
case 0x0:
|
case 0x00:
|
||||||
case 0x7:
|
case 0x07:
|
||||||
case 0xB: // Will be potion of leaping in 1.8
|
case 0x0b: // Will be potion of leaping in 1.8
|
||||||
case 0xF:
|
case 0x0f:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cEntityEffect::effNoEffect;
|
return cEntityEffect::effNoEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
short GetEntityEffectIntensity(short a_ItemDamage)
|
|
||||||
|
/** Retrieves the intensity level from the potion's damage value.
|
||||||
|
Returns 0 for level I potions, 1 for level II potions. */
|
||||||
|
static short GetEntityEffectIntensity(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
// Level II potion if fifth bit (from zero) is set
|
// Level II potion if the fifth lowest bit is set
|
||||||
return (a_ItemDamage & 0x20) ? 1 : 0;
|
return ((a_ItemDamage & 0x20) != 0) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetEntityEffectDuration(short a_ItemDamage)
|
|
||||||
|
/** Returns the effect duration, in ticks, based on the potion's damage value */
|
||||||
|
static int GetEntityEffectDuration(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
// Base duration in ticks
|
// Base duration in ticks
|
||||||
int base = 0;
|
int base = 0;
|
||||||
@ -88,42 +103,49 @@ class cItemPotionHandler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If potion is level 2, half the duration. If not, stays the same
|
// If potion is level II, half the duration. If not, stays the same
|
||||||
TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1;
|
TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1;
|
||||||
|
|
||||||
// If potion is extended, multiply duration by 8/3. If not, stays the same
|
// If potion is extended, multiply duration by 8/3. If not, stays the same
|
||||||
// Extended potion if sixth bit (from zero) is set
|
// Extended potion if sixth lowest bit is set
|
||||||
ExtCoeff = (a_ItemDamage & 0x40) ? (8.0/3.0) : 1;
|
ExtCoeff = (a_ItemDamage & 0x40) ? (8.0 / 3.0) : 1;
|
||||||
|
|
||||||
// If potion is splash potion, multiply duration by 3/4. If not, stays the same
|
// If potion is splash potion, multiply duration by 3/4. If not, stays the same
|
||||||
SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75;
|
SplashCoeff = IsPotionDrinkable(a_ItemDamage) ? 1 : 0.75;
|
||||||
|
|
||||||
// For reference: http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit
|
// Ref.:
|
||||||
|
// http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit
|
||||||
// http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit
|
// http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit
|
||||||
// http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit
|
// http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit
|
||||||
|
|
||||||
return (int)(base * TierCoeff * ExtCoeff * SplashCoeff);
|
return (int)(base * TierCoeff * ExtCoeff * SplashCoeff);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
cItemPotionHandler():
|
|
||||||
super(E_ITEM_POTIONS)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool IsDrinkable(short a_ItemDamage) override
|
/** Returns true if the potion with the given damage is drinkable */
|
||||||
|
static bool IsPotionDrinkable(short a_ItemDamage)
|
||||||
{
|
{
|
||||||
// Drinkable potion if 13th bit (from zero) is set
|
// Drinkable potion if 13th lowest bit is set
|
||||||
// For reference: http://minecraft.gamepedia.com/Potions#Data_value_table
|
// Ref.: http://minecraft.gamepedia.com/Potions#Data_value_table
|
||||||
return ((a_ItemDamage & 0x2000) != 0);
|
return ((a_ItemDamage & 0x2000) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// cItemHandler overrides:
|
||||||
|
virtual bool IsDrinkable(short a_ItemDamage) override
|
||||||
|
{
|
||||||
|
// Drinkable potion if 13th lowest bit is set
|
||||||
|
// Ref.: http://minecraft.gamepedia.com/Potions#Data_value_table
|
||||||
|
return IsPotionDrinkable(a_ItemDamage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
|
||||||
{
|
{
|
||||||
short PotionDamage = a_Item.m_ItemDamage;
|
short PotionDamage = a_Item.m_ItemDamage;
|
||||||
|
|
||||||
// Only called when potion is a splash potion
|
// Do not throw non-splash potions:
|
||||||
if (IsDrinkable(PotionDamage))
|
if (IsPotionDrinkable(PotionDamage))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -131,8 +153,11 @@ public:
|
|||||||
Vector3d Pos = a_Player->GetThrowStartPos();
|
Vector3d Pos = a_Player->GetThrowStartPos();
|
||||||
Vector3d Speed = a_Player->GetLookVector() * 7;
|
Vector3d Speed = a_Player->GetLookVector() * 7;
|
||||||
|
|
||||||
cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage)), GetPotionName(PotionDamage));
|
cSplashPotionEntity * Projectile = new cSplashPotionEntity(
|
||||||
|
a_Player, Pos.x, Pos.y, Pos.z, Speed,
|
||||||
|
GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage),
|
||||||
|
GetEntityEffectIntensity(PotionDamage)), GetPotionParticleType(PotionDamage)
|
||||||
|
);
|
||||||
if (Projectile == NULL)
|
if (Projectile == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -151,11 +176,12 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||||
{
|
{
|
||||||
short PotionDamage = a_Item->m_ItemDamage;
|
short PotionDamage = a_Item->m_ItemDamage;
|
||||||
|
|
||||||
// Only called when potion is a drinkable potion
|
// Do not drink undrinkable potions:
|
||||||
if (!IsDrinkable(a_Item->m_ItemDamage))
|
if (!IsDrinkable(a_Item->m_ItemDamage))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -167,3 +193,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user