diff options
Diffstat (limited to 'src/BlockEntities')
-rw-r--r-- | src/BlockEntities/BeaconEntity.cpp | 6 | ||||
-rw-r--r-- | src/BlockEntities/BlockEntity.h | 1 | ||||
-rw-r--r-- | src/BlockEntities/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/BlockEntities/FurnaceEntity.cpp | 42 | ||||
-rw-r--r-- | src/BlockEntities/FurnaceEntity.h | 8 | ||||
-rw-r--r-- | src/BlockEntities/MobSpawnerEntity.cpp | 18 | ||||
-rw-r--r-- | src/BlockEntities/NoteEntity.cpp | 11 |
7 files changed, 67 insertions, 24 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index fb3940ce9..a945c6ea9 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -77,7 +77,7 @@ bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLe default: { - LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect); + LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, static_cast<int>(a_Effect)); return false; } } @@ -228,9 +228,9 @@ void cBeaconEntity::GiveEffects(void) virtual bool Item(cPlayer * a_Player) { Vector3d PlayerPosition = Vector3d(a_Player->GetPosition()); - if (PlayerPosition.y > (double)m_PosY) + if (PlayerPosition.y > static_cast<double>(m_PosY)) { - PlayerPosition.y = (double)m_PosY; + PlayerPosition.y = static_cast<double>(m_PosY); } // TODO: Vanilla minecraft uses an AABB check instead of a radius one diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 85f75a523..71367efb6 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -85,6 +85,7 @@ public: // tolua_begin // Position, in absolute block coordinates: + Vector3i GetPos(void) const { return Vector3i{m_PosX, m_PosY, m_PosZ}; } int GetPosX(void) const { return m_PosX; } int GetPosY(void) const { return m_PosY; } int GetPosZ(void) const { return m_PosZ; } diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 5f4af288d..b0bfca5e4 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -41,6 +41,11 @@ SET (HDRS NoteEntity.h SignEntity.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum") + set_source_files_properties(NoteEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") +endif() + if(NOT MSVC) add_library(BlockEntities ${SRCS} ${HDRS}) endif() diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 2621b560b..d1588160d 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -32,7 +32,8 @@ cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY m_NeedCookTime(0), m_TimeCooked(0), m_FuelBurnTime(0), - m_TimeBurned(0) + m_TimeBurned(0), + m_IsLoading(false) { m_Contents.AddListener(*this); } @@ -178,20 +179,15 @@ void cFurnaceEntity::BurnNewFuel(void) { cFurnaceRecipe * FR = cRoot::Get()->GetFurnaceRecipe(); int NewTime = FR->GetBurnTime(m_Contents.GetSlot(fsFuel)); - if (NewTime == 0) + if ((NewTime == 0) || !CanCookInputToOutput()) { // The item in the fuel slot is not suitable + // or the input and output isn't available for cooking SetBurnTimes(0, 0); SetIsCooking(false); return; } - // Is the input and output ready for cooking? - if (!CanCookInputToOutput()) - { - return; - } - // Burn one new fuel: SetBurnTimes(NewTime, 0); SetIsCooking(true); @@ -218,6 +214,11 @@ void cFurnaceEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) return; } + if (m_IsLoading) + { + return; + } + ASSERT(a_ItemGrid == &m_Contents); switch (a_SlotNum) { @@ -238,7 +239,10 @@ void cFurnaceEntity::UpdateInput(void) if (!m_Contents.GetSlot(fsInput).IsEqual(m_LastInput)) { // The input is different from what we had before, reset the cooking time - m_TimeCooked = 0; + if (!m_IsLoading) + { + m_TimeCooked = 0; + } } m_LastInput = m_Contents.GetSlot(fsInput); @@ -253,13 +257,17 @@ void cFurnaceEntity::UpdateInput(void) else { m_NeedCookTime = m_CurrentRecipe->CookTime; - SetIsCooking(true); // Start burning new fuel if there's no flame now: if (GetFuelBurnTimeLeft() <= 0) { BurnNewFuel(); } + // Already burning, set cooking to ensure that cooking is occuring + else + { + SetIsCooking(true); + } } } @@ -293,11 +301,19 @@ void cFurnaceEntity::UpdateOutput(void) return; } - // No need to burn new fuel, the Tick() function will take care of that - // Can cook, start cooking if not already underway: m_NeedCookTime = m_CurrentRecipe->CookTime; - SetIsCooking(m_FuelBurnTime > 0); + + // Check if fuel needs to start a burn + if (GetFuelBurnTimeLeft() <= 0) + { + BurnNewFuel(); + } + // Already burning, set cooking to ensure that cooking is occuring + else + { + SetIsCooking(true); + } } diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 8b3ba3e36..8734d763c 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -101,6 +101,11 @@ public: m_TimeCooked = a_TimeCooked; } + void SetLoading(bool a_IsLoading) + { + m_IsLoading = a_IsLoading; + } + protected: /** Block meta of the block currently represented by this entity */ @@ -129,6 +134,9 @@ protected: /** Amount of ticks that the current fuel has been burning */ int m_TimeBurned; + + /** Is the block currently being loaded into the world? */ + bool m_IsLoading; /** Sends the specified progressbar value to all clients of the window */ void BroadcastProgress(short a_ProgressbarID, short a_Value); diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 764d7af84..1a0ce5b22 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -145,9 +145,9 @@ void cMobSpawnerEntity::SpawnEntity(void) break; } - int RelX = (int) (m_RelX + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + int RelX = static_cast<int>(m_RelX + static_cast<double>(Random.NextFloat() - Random.NextFloat()) * 4.0); int RelY = m_RelY + Random.NextInt(3) - 1; - int RelZ = (int) (m_RelZ + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + int RelZ = static_cast<int>(m_RelZ + static_cast<double>(Random.NextFloat() - Random.NextFloat()) * 4.0); cChunk * Chunk = a_Chunk->GetRelNeighborChunkAdjustCoords(RelX, RelZ); if ((Chunk == nullptr) || !Chunk->IsValid()) @@ -172,7 +172,13 @@ void cMobSpawnerEntity::SpawnEntity(void) if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != cEntity::INVALID_ID) { EntitiesSpawned = true; - Chunk->BroadcastSoundParticleEffect(2004, (int)(PosX * 8.0), (int)(RelY * 8.0), (int)(PosZ * 8.0), 0); + Chunk->BroadcastSoundParticleEffect( + 2004, + static_cast<int>(PosX * 8.0), + static_cast<int>(RelY * 8.0), + static_cast<int>(PosZ * 8.0), + 0 + ); m_NearbyEntitiesNum++; } } @@ -246,9 +252,9 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) class cCallback : public cChunkDataCallback { public: - cCallback(Vector3d a_SpawnerPos, eMonsterType a_EntityType, int & a_NumEntities) : + cCallback(Vector3d a_SpawnerPos, eMonsterType a_CallbackEntityType, int & a_NumEntities) : m_SpawnerPos(a_SpawnerPos), - m_EntityType(a_EntityType), + m_EntityType(a_CallbackEntityType), m_NumEntities(a_NumEntities) { } @@ -260,7 +266,7 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) return; } - cMonster * Mob = (cMonster *)a_Entity; + cMonster * Mob = static_cast<cMonster *>(a_Entity); if (Mob->GetMobType() != m_EntityType) { return; diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index a9af13c55..29839bae1 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -90,8 +90,15 @@ void cNoteEntity::MakeSound(void) m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, instrument, m_Pitch, E_BLOCK_NOTE_BLOCK); // TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all - float calcPitch = pow(2.0f, ((float)m_Pitch - 12.0f) / 12.0f); - m_World->BroadcastSoundEffect(sampleName, (double)m_PosX, (double)m_PosY, (double)m_PosZ, 3.0f, calcPitch); + float calcPitch = pow(2.0f, static_cast<float>(m_Pitch - 12.0f) / 12.0f); + m_World->BroadcastSoundEffect( + sampleName, + static_cast<double>(m_PosX), + static_cast<double>(m_PosY), + static_cast<double>(m_PosZ), + 3.0f, + calcPitch + ); } |