From 6e80f7544d786443d3028308e244b04dd8d5abcb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 6 Apr 2021 16:09:16 +0100 Subject: Update entity sizes --- src/Entities/ArrowEntity.cpp | 2 +- src/Entities/Boat.cpp | 2 +- src/Entities/EnderCrystal.cpp | 4 ++-- src/Entities/Entity.cpp | 18 ++++++++++++++---- src/Entities/Entity.h | 21 ++++++++++++--------- src/Entities/ExpBottleEntity.cpp | 2 +- src/Entities/ExpOrb.cpp | 2 +- src/Entities/FallingBlock.cpp | 2 +- src/Entities/FireChargeEntity.cpp | 2 +- src/Entities/FireworkEntity.cpp | 2 +- src/Entities/Floater.cpp | 2 +- src/Entities/HangingEntity.cpp | 2 +- src/Entities/Minecart.cpp | 2 +- src/Entities/Pawn.cpp | 2 +- src/Entities/Pawn.h | 2 +- src/Entities/Pickup.cpp | 2 +- src/Entities/Player.cpp | 12 +----------- src/Entities/Player.h | 3 --- src/Entities/ProjectileEntity.cpp | 4 ++-- src/Entities/ProjectileEntity.h | 4 ++-- src/Entities/SplashPotionEntity.cpp | 2 +- src/Entities/TNTEntity.cpp | 2 +- src/Entities/ThrownEggEntity.cpp | 2 +- src/Entities/ThrownEnderPearlEntity.cpp | 2 +- src/Entities/ThrownSnowballEntity.cpp | 2 +- src/Entities/WitherSkullEntity.cpp | 2 +- 26 files changed, 52 insertions(+), 52 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index e72743b3a..c7c088361 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -10,7 +10,7 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkArrow, a_Creator, a_Pos, a_Speed, 0.5, 0.5), + Super(pkArrow, a_Creator, a_Pos, a_Speed, 0.5f, 0.5f), m_PickupState(psNoPickup), m_DamageCoeff(2), m_IsCritical(false), diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 9d804052d..1016773e9 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -15,7 +15,7 @@ cBoat::cBoat(Vector3d a_Pos, eMaterial a_Material) : - Super(etBoat, a_Pos, 0.98, 0.7), + Super(etBoat, a_Pos, 1.375f, 0.5625f), m_LastDamage(0), m_ForwardDirection(0), m_DamageTaken(0.0f), m_Material(a_Material), m_RightPaddleUsed(false), m_LeftPaddleUsed(false) diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp index defa396f5..07fd56dad 100644 --- a/src/Entities/EnderCrystal.cpp +++ b/src/Entities/EnderCrystal.cpp @@ -20,7 +20,7 @@ cEnderCrystal::cEnderCrystal(Vector3d a_Pos, bool a_ShowBottom) : cEnderCrystal::cEnderCrystal(Vector3d a_Pos, Vector3i a_BeamTarget, bool a_DisplayBeam, bool a_ShowBottom) : - Super(etEnderCrystal, a_Pos, 1.0, 1.0), + Super(etEnderCrystal, a_Pos, 2.0f, 2.0f), m_BeamTarget(a_BeamTarget), m_DisplayBeam(a_DisplayBeam), m_ShowBottom(a_ShowBottom) @@ -92,7 +92,7 @@ void cEnderCrystal::KilledBy(TakeDamageInfo & a_TDI) // Destroy first so the Explodinator doesn't find us (when iterating through entities): Destroy(); - m_World->DoExplosionAt(6.0, GetPosX(), GetPosY() + (GetHeight() / 2.0), GetPosZ(), true, esEnderCrystal, this); + m_World->DoExplosionAt(6.0, GetPosX(), GetPosY() + GetHeight() / 2, GetPosZ(), true, esEnderCrystal, this); const auto Position = GetPosition().Floor(); if (cChunkDef::IsValidHeight(Position.y)) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6c777aca4..c8a6b8ef9 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -33,7 +33,7 @@ static UInt32 GetNextUniqueID(void) //////////////////////////////////////////////////////////////////////////////// // cEntity: -cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, double a_Height): +cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height): m_UniqueID(GetNextUniqueID()), m_Health(1), m_MaxHealth(1), @@ -59,8 +59,6 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl m_IsInLava(false), m_IsInWater(false), m_IsHeadInWater(false), - m_Width(a_Width), - m_Height(a_Height), m_AirLevel(MAX_AIR_LEVEL), m_AirTickTimer(DROWNING_TICKS), m_TicksAlive(0), @@ -71,6 +69,8 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl m_Position(a_Pos), m_WaterSpeed(0, 0, 0), m_Mass (0.001), // Default 1g + m_Width(a_Width), + m_Height(a_Height), m_InvulnerableTicks(0) { m_WorldChangeInfo.m_NewWorld = nullptr; @@ -1098,7 +1098,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) NextPos = HitCoords; // Avoid movement in the direction of the blockface that has been hit and correct for collision box: - double HalfWidth = GetWidth() / 2.0; + const auto HalfWidth = GetWidth() / 2; switch (HitBlockFace) { case BLOCK_FACE_XM: @@ -1714,6 +1714,16 @@ void cEntity::SetIsTicking(bool a_IsTicking) +void cEntity::SetSize(const float a_Width, const float a_Height) +{ + m_Width = a_Width; + m_Height = a_Height; +} + + + + + void cEntity::HandleAir(void) { // Ref.: https://minecraft.gamepedia.com/Chunk_format diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 559f4eb66..c3ccaa228 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -169,7 +169,7 @@ public: static const UInt32 INVALID_ID = 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants. - cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, double a_Height); + cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height); virtual ~cEntity() = default; /** Spawns the entity in the world; returns true if spawned, false if not (plugin disallowed). @@ -225,7 +225,7 @@ public: cWorld * GetWorld(void) const { return m_World; } double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees - double GetHeight (void) const { return m_Height; } + float GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } double GetPosX (void) const { return m_Position.x; } double GetPosY (void) const { return m_Position.y; } @@ -237,7 +237,7 @@ public: double GetSpeedX (void) const { return m_Speed.x; } double GetSpeedY (void) const { return m_Speed.y; } double GetSpeedZ (void) const { return m_Speed.z; } - double GetWidth (void) const { return m_Width; } + float GetWidth (void) const { return m_Width; } int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); } int GetChunkZ(void) const { return FloorC(m_Position.z / cChunkDef::Width); } @@ -579,6 +579,9 @@ public: /** Set the entity's status to either ticking or not ticking. */ void SetIsTicking(bool a_IsTicking); + /** Update an entity's size, for example, on body stance changes. */ + void SetSize(float a_Width, float a_Height); + /** Adds a mob to the leashed list of mobs. */ void AddLeashedMob(cMonster * a_Monster); @@ -686,12 +689,6 @@ protected: /** If the entity's head is in a water block */ bool m_IsHeadInWater; - /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ - double m_Width; - - /** Height of the entity (Y axis). */ - double m_Height; - /** Air level of a mobile */ int m_AirLevel; int m_AirTickTimer; @@ -748,6 +745,12 @@ private: /** Measured in Kilograms (Kg) */ double m_Mass; + /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ + float m_Width; + + /** Height of the entity (Y axis). */ + float m_Height; + /** If a player hit a entity, the entity receive a invulnerable of 10 ticks. While this ticks, a player can't hit this entity. */ int m_InvulnerableTicks; diff --git a/src/Entities/ExpBottleEntity.cpp b/src/Entities/ExpBottleEntity.cpp index 96c063f4e..f089ecb18 100644 --- a/src/Entities/ExpBottleEntity.cpp +++ b/src/Entities/ExpBottleEntity.cpp @@ -9,7 +9,7 @@ cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) : - Super(pkExpBottle, a_Creator, a_Pos, 0.25, 0.25) + Super(pkExpBottle, a_Creator, a_Pos, 0.25f, 0.25f) { SetSpeed(a_Speed); } diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 5f1b5cbe2..125ea394a 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -6,7 +6,7 @@ cExpOrb::cExpOrb(Vector3d a_Pos, int a_Reward): - Super(etExpOrb, a_Pos, 0.98, 0.98), // TODO: Check size + Super(etExpOrb, a_Pos, 0.5f, 0.5f), m_Reward(a_Reward), m_Timer(0) { diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index dd3ba59cc..aa6baae82 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -12,7 +12,7 @@ cFallingBlock::cFallingBlock(Vector3d a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta): - Super(etFallingBlock, a_Position, 0.98, 0.98), + Super(etFallingBlock, a_Position, 0.98f, 0.98f), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta) { diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp index 3ac815ec6..7971c4cb7 100644 --- a/src/Entities/FireChargeEntity.cpp +++ b/src/Entities/FireChargeEntity.cpp @@ -8,7 +8,7 @@ cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkFireCharge, a_Creator, a_Pos, 0.3125, 0.3125) + Super(pkFireCharge, a_Creator, a_Pos, 0.3125f, 0.3125f) { SetSpeed(a_Speed); SetGravity(0); diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp index 987d5a329..eb386cdfc 100644 --- a/src/Entities/FireworkEntity.cpp +++ b/src/Entities/FireworkEntity.cpp @@ -9,7 +9,7 @@ cFireworkEntity::cFireworkEntity(cEntity * a_Creator, Vector3d a_Pos, const cItem & a_Item) : - Super(pkFirework, a_Creator, a_Pos, 0.25, 0.25), + Super(pkFirework, a_Creator, a_Pos, 0.25f, 0.25f), m_TicksToExplosion(a_Item.m_FireworkItem.m_FlightTimeInTicks), m_FireworkItem(a_Item) { diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 2738c12d3..73c364961 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -75,7 +75,7 @@ protected: cFloater::cFloater(Vector3d a_Pos, Vector3d a_Speed, UInt32 a_PlayerID, int a_CountDownTime) : - Super(etFloater, a_Pos, 0.2, 0.2), + Super(etFloater, a_Pos, 0.25f, 0.25f), m_BitePos(a_Pos), m_CanPickupItem(false), m_PickupCountDown(0), diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp index 20b751c74..c20415e36 100644 --- a/src/Entities/HangingEntity.cpp +++ b/src/Entities/HangingEntity.cpp @@ -10,7 +10,7 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Vector3d a_Pos) : - Super(a_EntityType, a_Pos, 0.8, 0.8), + Super(a_EntityType, a_Pos, 0.5f, 0.5f), m_Facing(cHangingEntity::BlockFaceToProtocolFace(a_Facing)) { SetMaxHealth(1); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index c4636c5b1..1f454c857 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -95,7 +95,7 @@ protected: // cMinecart: cMinecart::cMinecart(ePayload a_Payload, Vector3d a_Pos): - Super(etMinecart, a_Pos, 0.98, 0.7), + Super(etMinecart, a_Pos, 0.98f, 0.7f), m_Payload(a_Payload), m_LastDamage(0), m_DetectorRailPosition(0, 0, 0), diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index ef552d89d..cc11323e1 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -14,7 +14,7 @@ -cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : +cPawn::cPawn(eEntityType a_EntityType, float a_Width, float a_Height) : Super(a_EntityType, Vector3d(), a_Width, a_Height), m_EntityEffects(tEffectMap()), m_LastGroundHeight(0), diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index ab8d66a58..706c51e49 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -22,7 +22,7 @@ public: CLASS_PROTODEF(cPawn) - cPawn(eEntityType a_EntityType, double a_Width, double a_Height); + cPawn(eEntityType a_EntityType, float a_Width, float a_Height); virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void KilledBy(TakeDamageInfo & a_TDI) override; diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 4b05c2b9b..39fff913d 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -94,7 +94,7 @@ protected: // cPickup: cPickup::cPickup(Vector3d a_Pos, const cItem & a_Item, bool IsPlayerCreated, Vector3f a_Speed, int a_LifetimeTicks, bool a_CanCombine): - Super(etPickup, a_Pos, 0.2, 0.2), + Super(etPickup, a_Pos, 0.25f, 0.25f), m_Timer(0), m_Item(a_Item), m_bCollected(false), diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 9725118ee..8c047c533 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -104,7 +104,7 @@ cPlayer::BodyStanceGliding::BodyStanceGliding(cPlayer & a_Player) : cPlayer::cPlayer(const std::shared_ptr & a_Client) : - Super(etPlayer, 0.6, 1.8), + Super(etPlayer, 0.6f, 1.8f), m_BodyStance(BodyStanceStanding(*this)), m_FoodLevel(MAX_FOOD_LEVEL), m_FoodSaturationLevel(5.0), @@ -2821,16 +2821,6 @@ void cPlayer::AddKnownItem(const cItem & a_Item) -void cPlayer::SetSize(const float a_Width, const float a_Height) -{ - m_Width = a_Width; - m_Height = a_Height; -} - - - - - void cPlayer::AddKnownRecipe(UInt32 a_RecipeId) { auto Response = m_KnownRecipes.insert(a_RecipeId); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index fd4d22d84..8969099a1 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -592,9 +592,6 @@ public: If the item is already known, does nothing. */ void AddKnownItem(const cItem & a_Item); - /** Update a player's size, for example, on body stance changes. */ - void SetSize(float a_Width, float a_Height); - // cEntity overrides: virtual void AttachTo(cEntity * a_AttachTo) override; virtual void Detach(void) override; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index c72cebaaf..745f7de13 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -219,7 +219,7 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cProjectileEntity: -cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, double a_Width, double a_Height): +cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height): Super(etProjectile, a_Pos, a_Width, a_Height), m_ProjectileKind(a_Kind), m_CreatorData( @@ -237,7 +237,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d -cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, double a_Width, double a_Height): +cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, float a_Width, float a_Height): cProjectileEntity(a_Kind, a_Creator, a_Pos, a_Width, a_Height) { SetSpeed(a_Speed); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index ddd09f831..1c8c00854 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -48,8 +48,8 @@ public: CLASS_PROTODEF(cProjectileEntity) - cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, double a_Width, double a_Height); - cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, double a_Width, double a_Height); + cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height); + cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, float a_Width, float a_Height); /** Creates a new instance of the specified projectile entity. a_Item is the item from which the projectile originated (such as firework or arrow). */ diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index ce081aed1..bf23b8ffb 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -17,7 +17,7 @@ cSplashPotionEntity::cSplashPotionEntity( Vector3d a_Speed, const cItem & a_Item ): - Super(pkSplashPotion, a_Creator, a_Pos, 0.25, 0.25), + Super(pkSplashPotion, a_Creator, a_Pos, 0.25f, 0.25f), m_Item(a_Item), m_DestroyTimer(-1) { diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index ef013c347..0d7340513 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -9,7 +9,7 @@ cTNTEntity::cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks) : - Super(etTNT, a_Pos, 0.98, 0.98), + Super(etTNT, a_Pos, 0.98f, 0.98f), m_FuseTicks(a_FuseTicks) { SetGravity(-16.0f); diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp index bc5ed665e..b8289b64b 100644 --- a/src/Entities/ThrownEggEntity.cpp +++ b/src/Entities/ThrownEggEntity.cpp @@ -8,7 +8,7 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkEgg, a_Creator, a_Pos, 0.25, 0.25), + Super(pkEgg, a_Creator, a_Pos, 0.25f, 0.25f), m_DestroyTimer(-1) { SetSpeed(a_Speed); diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp index ec4af7a7c..e6d708917 100644 --- a/src/Entities/ThrownEnderPearlEntity.cpp +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -9,7 +9,7 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkEnderPearl, a_Creator, a_Pos, 0.25, 0.25), + Super(pkEnderPearl, a_Creator, a_Pos, 0.25f, 0.25f), m_DestroyTimer(-1) { SetSpeed(a_Speed); diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp index d10aaf25d..63068e69d 100644 --- a/src/Entities/ThrownSnowballEntity.cpp +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -8,7 +8,7 @@ cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkSnowball, a_Creator, a_Pos, 0.25, 0.25), + Super(pkSnowball, a_Creator, a_Pos, 0.25f, 0.25f), m_DestroyTimer(-1) { SetSpeed(a_Speed); diff --git a/src/Entities/WitherSkullEntity.cpp b/src/Entities/WitherSkullEntity.cpp index 1bb17ab2b..22e474395 100644 --- a/src/Entities/WitherSkullEntity.cpp +++ b/src/Entities/WitherSkullEntity.cpp @@ -13,7 +13,7 @@ cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed): - Super(pkWitherSkull, a_Creator, a_Pos, 0.25, 0.25) + Super(pkWitherSkull, a_Creator, a_Pos, 0.3125f, 0.3125f) { SetSpeed(a_Speed); SetGravity(0); -- cgit v1.2.3