Skip to content

Commit 85e583d

Browse files
author
xCollateral
committed
Refactor level section indexing
1 parent ef64206 commit 85e583d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/main/java/net/vulkanmod/render/chunk/RenderSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public BuildTask createCompileTask(RenderRegionBuilder renderRegionCache) {
245245
Level level = WorldRenderer.getLevel();
246246
int secX = xOffset >> 4;
247247
int secZ = zOffset >> 4;
248-
int secY = (yOffset - level.getMinBuildHeight()) >> 4;
248+
int secY = yOffset >> 4;
249249

250250
if (!ChunkStatusMap.INSTANCE.chunkRenderReady(secX, secZ))
251251
return null;

src/main/java/net/vulkanmod/render/chunk/build/RenderRegion.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ public class RenderRegion implements BlockAndTintGetter {
4242
private TintCache tintCache;
4343

4444
private final Map<BlockPos, BlockEntity> blockEntityMap;
45-
private final int minHeight;
4645

4746
private final Function<BlockPos, BlockState> blockStateGetter;
4847

4948
RenderRegion(Level level, int x, int y, int z, PalettedContainer<BlockState>[] blockData, DataLayer[][] lightData, Map<BlockPos, BlockEntity> blockEntityMap) {
5049
this.level = level;
51-
this.minHeight = level.getMinBuildHeight();
5250

5351
this.minSecX = x - 1;
5452
this.minSecY = y - 1;
@@ -144,7 +142,7 @@ public LevelLightEngine getLightEngine() {
144142

145143
public int getBrightness(LightLayer lightLayer, BlockPos blockPos) {
146144
int secX = SectionPos.blockToSectionCoord(blockPos.getX()) - this.minSecX;
147-
int secY = SectionPos.blockToSectionCoord(blockPos.getY() - minHeight) - this.minSecY;
145+
int secY = SectionPos.blockToSectionCoord(blockPos.getY()) - this.minSecY;
148146
int secZ = SectionPos.blockToSectionCoord(blockPos.getZ()) - this.minSecZ;
149147

150148
DataLayer dataLayer = this.lightData[getSectionIdx(secX, secY, secZ)][lightLayer.ordinal()];
@@ -154,7 +152,7 @@ public int getBrightness(LightLayer lightLayer, BlockPos blockPos) {
154152

155153
public int getRawBrightness(BlockPos blockPos, int i) {
156154
int secX = SectionPos.blockToSectionCoord(blockPos.getX()) - this.minSecX;
157-
int secY = SectionPos.blockToSectionCoord(blockPos.getY() - minHeight) - this.minSecY;
155+
int secY = SectionPos.blockToSectionCoord(blockPos.getY()) - this.minSecY;
158156
int secZ = SectionPos.blockToSectionCoord(blockPos.getZ()) - this.minSecZ;
159157

160158
DataLayer[] dataLayers = this.lightData[getSectionIdx(secX, secY, secZ)];
@@ -199,7 +197,7 @@ public int getBlockIdx(int x, int y, int z) {
199197
}
200198

201199
public BlockState defaultBlockState(BlockPos blockPos) {
202-
return blockData[getBlockIdx(blockPos.getX(), blockPos.getY() - minHeight, blockPos.getZ())];
200+
return blockData[getBlockIdx(blockPos.getX(), blockPos.getY(), blockPos.getZ())];
203201
}
204202

205203
public BlockState debugBlockState(BlockPos blockPos) {

src/main/java/net/vulkanmod/render/chunk/build/RenderRegionBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class RenderRegionBuilder {
2222
public RenderRegion createRegion(Level level, int secX, int secY, int secZ) {
2323
LevelChunk levelChunk = getLevelChunk(level, secX, secZ);
2424
var sections = levelChunk.getSections();
25-
LevelChunkSection section = sections[secY];
25+
LevelChunkSection section = sections[level.getSectionIndexFromSectionY(secY)];
2626

2727
if(section == null || section.hasOnlyAir())
2828
return null;
@@ -47,7 +47,8 @@ public RenderRegion createRegion(Level level, int secX, int secY, int secZ) {
4747
sections = levelChunk1.getSections();
4848

4949
for(int y = minSecY; y <= maxSecY; ++y) {
50-
section = y >= 0 && y < sections.length ? sections[y] : null;
50+
int sectionIdx = y - minHeightSec;
51+
section = sectionIdx >= 0 && sectionIdx < sections.length ? sections[sectionIdx] : null;
5152

5253
final int relX = (x - minSecX), relY = (y - minSecY), relZ = (z - minSecZ);
5354
final int idx = (relY * RenderRegion.WIDTH + relZ) * RenderRegion.WIDTH + relX;
@@ -56,7 +57,7 @@ public RenderRegion createRegion(Level level, int secX, int secY, int secZ) {
5657

5758
blockData[idx] = values;
5859

59-
SectionPos pos = SectionPos.of(x, y + minHeightSec, z);
60+
SectionPos pos = SectionPos.of(x, y, z);
6061
DataLayer[] dataLayers = getSectionDataLayers(level, pos);
6162

6263
lightData[idx] = dataLayers;

0 commit comments

Comments
 (0)