diff options
author | Mattes D <github@xoft.cz> | 2019-10-11 11:02:53 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-10-28 10:45:43 +0100 |
commit | 61904af626b036b6e4e045ca219b2a361aa45a6e (patch) | |
tree | 60b99ab37c9ec87ca96d403b3254a4da023cf6ac /src/Entities | |
parent | Update README.md (#4423) (diff) | |
download | cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.gz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.bz2 cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.lz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.xz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.zst cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.zip |
Diffstat (limited to 'src/Entities')
-rw-r--r-- | src/Entities/ArrowEntity.cpp | 9 | ||||
-rw-r--r-- | src/Entities/Minecart.cpp | 15 |
2 files changed, 11 insertions, 13 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index adbee3cf8..ce0adcdcc 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -198,17 +198,16 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } } - int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); + auto relPos = a_Chunk.RelativeToAbsolute(m_HitBlockPos); + auto chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(relPos); - if (Chunk == nullptr) + if (chunk == nullptr) { // Inside an unloaded chunk, abort return; } - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + if (chunk->GetBlock(relPos) == E_BLOCK_AIR) // Block attached to was destroyed? { m_IsInGround = false; // Yes, begin simulating physics again } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 9ff8c04b6..01d89ceb4 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -136,10 +136,9 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) return; } - int RelPosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - if (Chunk == nullptr) + auto relPos = a_Chunk.AbsoluteToRelative(GetPosition()); + auto chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(relPos); + if (chunk == nullptr) { // Inside an unloaded chunk, bail out all processing return; @@ -147,12 +146,12 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) BLOCKTYPE InsideType; NIBBLETYPE InsideMeta; - Chunk->GetBlockTypeMeta(RelPosX, PosY, RelPosZ, InsideType, InsideMeta); + chunk->GetBlockTypeMeta(relPos, InsideType, InsideMeta); if (!IsBlockRail(InsideType)) { // When a descending minecart hits a flat rail, it goes through the ground; check for this - Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); + chunk->GetBlockTypeMeta(relPos.addedY(1), InsideType, InsideMeta); if (IsBlockRail(InsideType)) { // Push cart upwards @@ -192,12 +191,12 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { // Not on rail, default physics SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail - super::HandlePhysics(a_Dt, *Chunk); + super::HandlePhysics(a_Dt, *chunk); } if (m_bIsOnDetectorRail && !Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT).Equals(m_DetectorRailPosition)) { - m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); + m_World->SetBlock(m_DetectorRailPosition, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); m_bIsOnDetectorRail = false; } else if (WasDetectorRail) |