From 9f7db50de0537ae9e918ab3a9cf49e01eda93cf1 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Thu, 8 Aug 2013 16:32:14 +0100 Subject: Fixed food handler for mushroom soup - proper food level and saturation are applied and the player receives a wooden bowl back after nomming --- source/Player.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index fb752ed87..6219523cf 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -400,7 +400,14 @@ void cPlayer::FinishEating(void) return; } ItemHandler->OnFoodEaten(m_World, this, &Item); + GetInventory().RemoveOneEquippedItem(); + + //if the food is mushroom soup, return a bowl to the inventory + if( Item.m_ItemType == E_ITEM_MUSHROOM_SOUP ) { + cItem emptyBowl(E_ITEM_BOWL, 1, 0, ""); + GetInventory().AddItem(emptyBowl, true, true); + } } -- cgit v1.2.3 From dace1f7bd2e661b4c771322162e9e1b52551dd56 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Fri, 9 Aug 2013 08:37:39 +0100 Subject: Added IsSwimming and IsSubmerged flags and access methods --- source/Player.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 6219523cf..eab6e08e5 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -61,6 +61,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_SprintingMaxSpeed(0.13) , m_IsCrouched(false) , m_IsSprinting(false) + , m_IsSwimming(false) + , m_IsSubmerged(false) , m_EatingFinishTick(-1) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", @@ -181,8 +183,11 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); - //handle air drowning stuff - HandleAir(a_Chunk); + // set player swimming state + SetSwimState( a_Chunk); + + // handle air drowning stuff + HandleAir(); if (m_bDirtyPosition) { @@ -1326,20 +1331,34 @@ void cPlayer::UseEquippedItem() GetInventory().DamageEquippedItem(); } - -void cPlayer::HandleAir(cChunk & a_Chunk) +void cPlayer::SetSwimState(cChunk & a_Chunk) { - // Ref.: http://www.minecraftwiki.net/wiki/Chunk_format - // see if the player is /submerged/ water (block above is water) - // Get the type of block the player's standing in: + BLOCKTYPE BlockIn; int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelY = (int)floor(m_LastPosY + 1.1); + int RelY = (int)floor(m_LastPosY + 0.1); int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; + // first we check if the player is swimming + // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)); - if (IsBlockWater(BlockIn)) + m_IsSwimming = IsBlockWater(BlockIn); + + // now we check if the player is submerged + + VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY+1, RelZ, BlockIn)); + + m_IsSubmerged = IsBlockWater(BlockIn); +} + +void cPlayer::HandleAir() +{ + // Ref.: http://www.minecraftwiki.net/wiki/Chunk_format + // see if the player is /submerged/ water (block above is water) + // Get the type of block the player's standing in: + + if (IsSubmerged()) { // either reduce air level or damage player if(m_AirLevel < 1) -- cgit v1.2.3 From ffce5d143fe2b6224ee7ff29e40c9a73af0463e4 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Fri, 9 Aug 2013 08:50:33 +0100 Subject: Removed the need to recalculate whether player is under water in ApplyFoodExhaustion --- source/Player.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index eab6e08e5..ba165989a 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -192,7 +192,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) if (m_bDirtyPosition) { // Apply food exhaustion from movement: - ApplyFoodExhaustionFromMovement(a_Chunk); + ApplyFoodExhaustionFromMovement(); cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this); BroadcastMovementUpdate(m_ClientHandle); @@ -1445,7 +1445,7 @@ void cPlayer::HandleFood(void) -void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk) +void cPlayer::ApplyFoodExhaustionFromMovement() { if (IsGameModeCreative()) { @@ -1463,14 +1463,6 @@ void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk) return; } - // Get the type of block the player's standing in: - BLOCKTYPE BlockIn; - int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelY = (int)floor(m_LastPosY + 0.1); - int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; - // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk - VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)); - // Apply the exhaustion based on distance travelled: double BaseExhaustion = Movement.Length(); if (IsSprinting()) @@ -1478,7 +1470,7 @@ void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk) // 0.1 pt per meter sprinted BaseExhaustion = BaseExhaustion * 0.1; } - else if (IsBlockWater(BlockIn)) + else if (IsSwimming()) { // 0.015 pt per meter swum BaseExhaustion = BaseExhaustion * 0.015; -- cgit v1.2.3 From 6963e8119ce879843f4bac9042a0d8c8e588c524 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Fri, 9 Aug 2013 08:57:24 +0100 Subject: Fixed some formatting issues I accidentally introduced --- source/Player.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index ba165989a..808976a6c 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -61,8 +61,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_SprintingMaxSpeed(0.13) , m_IsCrouched(false) , m_IsSprinting(false) - , m_IsSwimming(false) - , m_IsSubmerged(false) + , m_IsSwimming(false) + , m_IsSubmerged(false) , m_EatingFinishTick(-1) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", @@ -182,9 +182,9 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) } super::Tick(a_Dt, a_Chunk); - - // set player swimming state - SetSwimState( a_Chunk); + + // set player swimming state + SetSwimState( a_Chunk); // handle air drowning stuff HandleAir(); @@ -1338,18 +1338,19 @@ void cPlayer::SetSwimState(cChunk & a_Chunk) int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width; int RelY = (int)floor(m_LastPosY + 0.1); int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width; - // first we check if the player is swimming + + // first we check if the player is swimming // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn)); - m_IsSwimming = IsBlockWater(BlockIn); - - // now we check if the player is submerged + m_IsSwimming = IsBlockWater(BlockIn); + + // now we check if the player is submerged - VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY+1, RelZ, BlockIn)); + VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY+1, RelZ, BlockIn)); - m_IsSubmerged = IsBlockWater(BlockIn); + m_IsSubmerged = IsBlockWater(BlockIn); } void cPlayer::HandleAir() -- cgit v1.2.3