void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) { // Not an entity that interacts with an arrow return; } int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); if (m_IsCritical) { Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); } a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); // Broadcast successful hit sound m_World->BroadcastSoundEffect( "random.successful_hit", (int)std::floor(GetPosX() * 8.0), (int)std::floor(GetPosY() * 8.0), (int)std::floor(GetPosZ() * 8.0), 0.5f, 0.75f + ((float)((GetUniqueID() * 23) % 32)) / 64.0f ); Destroy(); }
virtual bool Item(cEntity * a_Entity) override { if (a_Entity->GetUniqueID() == m_Pusher->GetUniqueID()) { return false; } // we only push other mobs, boats and minecarts if ((a_Entity->GetEntityType() != etMonster) && (a_Entity->GetEntityType() != etMinecart) && (a_Entity->GetEntityType() != etBoat)) { return false; } // do not push a boat / minecart you're sitting in if (m_Pusher->IsAttachedTo(a_Entity)) { return false; } Vector3d v3Delta = a_Entity->GetPosition() - m_Pusher->GetPosition(); v3Delta.y = 0.0; // we only push sideways v3Delta *= 1.0 / (v3Delta.Length() + 0.01); // we push harder if we're close // QUESTION: is there an additional multiplier for this? current shoving seems a bit weak a_Entity->AddSpeed(v3Delta); return false; }
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { double Pos[3]; if (!LoadDoublesListFromNBT(Pos, 3, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Pos"))) { return false; } a_Entity.SetPosition(Pos[0], Pos[1], Pos[2]); double Speed[3]; if (!LoadDoublesListFromNBT(Speed, 3, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Motion"))) { return false; } a_Entity.SetSpeed(Speed[0], Speed[1], Speed[2]); double Rotation[3]; if (!LoadDoublesListFromNBT(Rotation, 2, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Rotation"))) { return false; } a_Entity.SetRotation(Rotation[0]); a_Entity.SetRoll (Rotation[1]); return true; }
char cProtocol125::GetEntityMetadataFlags(const cEntity & a_Entity) { char Flags = 0; if (a_Entity.IsOnFire()) { Flags |= 1; } if (a_Entity.IsCrouched()) { Flags |= 2; } if (a_Entity.IsRiding()) { Flags |= 4; } if (a_Entity.IsSprinting()) { Flags |= 8; } if (a_Entity.IsRclking()) { Flags |= 16; } return Flags; }
void cProtocol125::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_HEAD_LOOK); WriteInt (a_Entity.GetUniqueID()); WriteChar((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); Flush(); }
void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE); WriteInt (a_Entity.GetUniqueID()); WriteChar(a_RelX); WriteChar(a_RelY); WriteChar(a_RelZ); Flush(); }
void cProtocol125::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENTITY_VELOCITY); WriteInt (a_Entity.GetUniqueID()); WriteShort((short) (a_Entity.GetSpeedX() * 400)); //400 = 8000 / 20 WriteShort((short) (a_Entity.GetSpeedY() * 400)); WriteShort((short) (a_Entity.GetSpeedZ() * 400)); Flush(); }
void cProtocol125::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE_LOOK); WriteInt (a_Entity.GetUniqueID()); WriteByte(a_RelX); WriteByte(a_RelY); WriteByte(a_RelZ); WriteByte((char)((a_Entity.GetRotation() / 360.f) * 256)); WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); }
void cProtocol132::SendDestroyEntity(const cEntity & a_Entity) { if (a_Entity.GetUniqueID() == m_Client->GetPlayer()->GetUniqueID()) { // Do not send "destroy self" to the client, the client would crash (FS #254) return; } cCSLock Lock(m_CSPacket); WriteByte(PACKET_DESTROY_ENTITIES); WriteByte(1); // entity count WriteInt (a_Entity.GetUniqueID()); Flush(); }
void cProjectileEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { if (a_EntityHit.IsPawn() && (GetCreatorName() != "")) // If we're hitting a mob or a player and we were created by a player { class cNotifyWolves : public cEntityCallback { public: cPawn * m_EntityHit; cNotifyWolves(cPawn * a_Entity) : m_EntityHit(a_Entity) { } virtual bool Item(cEntity * a_Player) override { static_cast<cPlayer*>(a_Player)->NotifyFriendlyWolves(m_EntityHit); return true; } } Callback(static_cast<cPawn*>(&a_EntityHit)); m_World->DoWithEntityByID(GetCreatorUniqueID(), Callback); } }
void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { int TotalDamage = 0; if (a_EntityHit.IsMob()) { eMonsterType MobType = static_cast<cMonster &>(a_EntityHit).GetMobType(); if (MobType == mtBlaze) { TotalDamage = 3; } } // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); m_DestroyTimer = 5; }
void cProtocol125::SendDestroyEntity(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_DESTROY_ENTITY); WriteInt (a_Entity.GetUniqueID()); Flush(); }
void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ANIMATION); WriteInt (a_Entity.GetUniqueID()); WriteChar(a_Animation); Flush(); }
void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); // TODO: Some entities are immune to hits a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning }
void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_STATUS); WriteInt (a_Entity.GetUniqueID()); WriteChar(a_Status); Flush(); }
void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { int TotalDamage = 0; // If entity is an Ender Dragon or Ender Crystal, it is damaged. if ( (a_EntityHit.IsMob() && (static_cast<cMonster &>(a_EntityHit).GetMobType() == mtEnderDragon)) || a_EntityHit.IsEnderCrystal() ) { TotalDamage = 1; } TrySpawnChicken(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); m_DestroyTimer = 5; }
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer()) { // Not an entity that interacts with an arrow return; } int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); if (m_IsCritical) { Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); } a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); Destroy(); }
void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_REMOVE_ENTITY_EFFECT); WriteInt (a_Entity.GetUniqueID()); WriteChar((char)a_EffectID); Flush(); }
void cProtocol132::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_COLLECT_PICKUP); WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Player.GetUniqueID()); Flush(); }
void cProtocol125::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ATTACH_ENTITY); WriteInt(a_Entity.GetUniqueID()); WriteInt((a_Vehicle == NULL) ? -1 : a_Vehicle->GetUniqueID()); Flush(); }
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { super::OnHitEntity(a_EntityHit, a_HitPos); int Damage = static_cast<int>(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); if (m_IsCritical) { Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); } unsigned int PowerLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPower); if (PowerLevel > 0) { int ExtraDamage = static_cast<int>(ceil(0.25 * (PowerLevel + 1))); Damage += ExtraDamage; } // int KnockbackAmount = 1; unsigned int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { Vector3d LookVector = GetLookVector(); Vector3f FinalSpeed = Vector3f(0, 0, 0); switch (PunchLevel) { case 1: FinalSpeed = LookVector * Vector3d(5, 0.3, 5); break; case 2: FinalSpeed = LookVector * Vector3d(8, 0.3, 8); break; default: break; } a_EntityHit.SetSpeed(FinalSpeed); } // a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); // TODO fix knockback. a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 0); // Until knockback is fixed. if (IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming()) { a_EntityHit.StartBurning(100); } // Broadcast successful hit sound GetWorld()->BroadcastSoundEffect("random.successful_hit", GetPosX(), GetPosY(), GetPosZ(), 0.5, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)); Destroy(); }
void cProtocol125::SendEntityMetadata(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_METADATA); WriteInt (a_Entity.GetUniqueID()); AString MetaData = GetEntityMetaData(a_Entity); SendData(MetaData.data(), MetaData.size()); Flush(); }
void cProtocol_1_11_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteVarInt32(static_cast<UInt32>(a_Count)); }
void cProtocol132::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_ENTITY_EQUIPMENT); WriteInt (a_Entity.GetUniqueID()); WriteShort(a_SlotNum); WriteItem (a_Item); Flush(); }
void cProtocol161::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ATTACH_ENTITY); WriteInt(a_Entity.GetUniqueID()); WriteInt((a_Vehicle == NULL) ? -1 : a_Vehicle->GetUniqueID()); WriteBool(false); // TODO: "Should use leash?" -> no Flush(); }
void cProtocol125::SendEntityMetadata(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_METADATA); WriteInt (a_Entity.GetUniqueID()); WriteCommonMetadata(a_Entity); if (a_Entity.IsMob()) { WriteMobMetadata(((const cMonster &)a_Entity)); } else { WriteEntityMetadata(a_Entity); } WriteByte(0x7f); Flush(); }
void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it TrySpawnChicken(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); m_DestroyTimer = 5; }
void cWitherSkullEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1); // TODO: Explode // TODO: Apply wither effect to entity and others nearby Destroy(true); }
void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it TeleportCreator(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); m_DestroyTimer = 5; }
void cProtocol125::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_ENTITY_EFFECT); WriteInt (a_Entity.GetUniqueID()); WriteByte ((Byte)a_EffectID); WriteByte ((Byte)a_Amplifier); WriteShort(a_Duration); Flush(); }