Skip to content

Commit c29edee

Browse files
committed
Fix broken state of ChunkAwareBlockCollisionSweeper caused by repeated nextSection() calls with hideLastCollision=false
#628
1 parent 517cfe8 commit c29edee

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

common/src/main/java/net/caffeinemc/mods/lithium/common/entity/movement/ChunkAwareBlockCollisionSweeper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,27 @@ private boolean nextSection() {
142142
this.chunkYIndex++;
143143
this.cachedChunkSection = this.cachedChunk.getSections()[this.chunkYIndex];
144144
} else {
145-
this.chunkYIndex = Mth.clamp(
146-
Pos.SectionYIndex.fromBlockCoord(this.world, expandMin(this.minY)),
147-
Pos.SectionYIndex.getMinYSectionIndex(this.world),
148-
Pos.SectionYIndex.getMaxYSectionIndexInclusive(this.world)
149-
);
150-
151145
if (this.chunkX < Pos.ChunkCoord.fromBlockCoord(expandMax(this.maxX))) {
152146
//first initialization takes this branch
153147
this.chunkX++;
154148
} else {
155-
this.chunkX = Pos.ChunkCoord.fromBlockCoord(expandMin(this.minX));
156-
157149
if (this.chunkZ < Pos.ChunkCoord.fromBlockCoord(expandMax(this.maxZ))) {
150+
this.chunkX = Pos.ChunkCoord.fromBlockCoord(expandMin(this.minX));
158151
this.chunkZ++;
159152
} else {
153+
//Important: No field assignment / mutation happens in the code path to this, so
154+
// consecutive nextSection calls keep returning false, instead of working on invalid data
155+
// Otherwise this additional chunk sections to be iterated wrongly: https://github.com/CaffeineMC/lithium/issues/628
160156
return false; //no more sections to iterate
161157
}
162158
}
163159
this.cachedChunk = this.world.getChunk(this.chunkX, this.chunkZ, ChunkStatus.FULL, false);
164160
if (this.cachedChunk != null) {
161+
this.chunkYIndex = Mth.clamp(
162+
Pos.SectionYIndex.fromBlockCoord(this.world, expandMin(this.minY)),
163+
Pos.SectionYIndex.getMinYSectionIndex(this.world),
164+
Pos.SectionYIndex.getMaxYSectionIndexInclusive(this.world)
165+
);
165166
this.cachedChunkSection = this.cachedChunk.getSections()[this.chunkYIndex];
166167
}
167168
}

0 commit comments

Comments
 (0)