Skip to content

Commit

Permalink
fix: Don't set direction of diagonal faces (CaffeineMC#171)
Browse files Browse the repository at this point in the history
Prevents improper culling.
  • Loading branch information
mrmangohands committed Feb 12, 2021
1 parent 0043e90 commit 8b80ea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public ChunkRenderBounds build(ChunkSectionPos origin) {
int z1 = origin.getMinZ() + leftBound(this.z);
int z2 = origin.getMinZ() + rightBound(this.z);

// Expand the bounding box by 8 blocks (half a chunk) in order to deal with diagonal surfaces
return new ChunkRenderBounds(
Math.max(x1, origin.getMinX()) - 8.0f,
Math.max(y1, origin.getMinY()) - 8.0f,
Math.max(z1, origin.getMinZ()) - 8.0f,
Math.max(x1, origin.getMinX()) - 0.5f,
Math.max(y1, origin.getMinY()) - 0.5f,
Math.max(z1, origin.getMinZ()) - 0.5f,

Math.min(x2, origin.getMaxX()) + 8.0f,
Math.min(y2, origin.getMaxY()) + 8.0f,
Math.min(z2, origin.getMaxZ()) + 8.0f
Math.min(x2, origin.getMaxX()) + 0.5f,
Math.min(y2, origin.getMaxY()) + 0.5f,
Math.min(z2, origin.getMaxZ()) + 0.5f
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
Vec3d velocity = fluidState.getVelocity(world, pos);

Sprite sprite;
ModelQuadFacing facing;
float u1, u2, u3, u4;
float v1, v2, v3, v4;

if (velocity.x == 0.0D && velocity.z == 0.0D) {
sprite = sprites[0];
facing = ModelQuadFacing.UP;
u1 = sprite.getFrameU(0.0D);
v1 = sprite.getFrameV(0.0D);
u2 = u1;
Expand All @@ -166,6 +168,7 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
v4 = v1;
} else {
sprite = sprites[1];
facing = ModelQuadFacing.NONE;
float dir = (float) MathHelper.atan2(velocity.z, velocity.x) - (1.5707964f);
float sin = MathHelper.sin(dir) * 0.25F;
float cos = MathHelper.cos(dir) * 0.25F;
Expand Down Expand Up @@ -202,14 +205,14 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
this.setVertex(quad, 3, 1.0F, 0.0f + h4, 0.0f, u4, v4);

this.calculateQuadColors(quad, world, pos, lighter, Direction.UP, 1.0F, !lava);
this.flushQuad(consumer, quad, Direction.UP, false);
this.flushQuad(consumer, quad, ModelQuadFacing.UP, false);

if (fluidState.method_15756(world, this.scratchPos.set(posX, posY + 1, posZ))) {
this.setVertex(quad, 3, 0.0f, 0.0f + h1, 0.0f, u1, v1);
this.setVertex(quad, 2, 0.0f, 0.0f + h2, 1.0F, u2, v2);
this.setVertex(quad, 1, 1.0F, 0.0f + h3, 1.0F, u3, v3);
this.setVertex(quad, 0, 1.0F, 0.0f + h4, 0.0f, u4, v4);
this.flushQuad(consumer, quad, Direction.DOWN, true);
this.flushQuad(consumer, quad, ModelQuadFacing.DOWN, true);
}

rendered = true;
Expand All @@ -230,7 +233,7 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
this.setVertex(quad, 3, 1.0F, 0.0f + yOffset, 1.0F, maxU, maxV);

this.calculateQuadColors(quad, world, pos, lighter, Direction.DOWN, 1.0F, !lava);
this.flushQuad(consumer, quad, Direction.DOWN, false);
this.flushQuad(consumer, quad, ModelQuadFacing.DOWN, false);

rendered = true;
}
Expand Down Expand Up @@ -330,15 +333,15 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
float br = dir.getAxis() == Direction.Axis.Z ? 0.8F : 0.6F;

this.calculateQuadColors(quad, world, pos, lighter, dir, br, !lava);
this.flushQuad(consumer, quad, dir, false);
this.flushQuad(consumer, quad, ModelQuadFacing.fromDirection(dir), false);

if (sprite != this.waterOverlaySprite) {
this.setVertex(quad, 0, x1, 0.0f + c1, z1, u1, v1);
this.setVertex(quad, 1, x1, 0.0f + yOffset, z1, u1, v3);
this.setVertex(quad, 2, x2, 0.0f + yOffset, z2, u2, v3);
this.setVertex(quad, 3, x2, 0.0f + c2, z2, u2, v2);

this.flushQuad(consumer, quad, dir, true);
this.flushQuad(consumer, quad, ModelQuadFacing.fromDirection(dir), true);
}

rendered = true;
Expand All @@ -363,7 +366,7 @@ private void calculateQuadColors(ModelQuadViewMutable quad, BlockRenderView worl
}
}

private void flushQuad(ModelQuadSinkDelegate consumer, ModelQuadViewMutable quad, Direction dir, boolean flip) {
private void flushQuad(ModelQuadSinkDelegate consumer, ModelQuadViewMutable quad, ModelQuadFacing facing, boolean flip) {
int vertexIdx, lightOrder;

if (flip) {
Expand All @@ -381,7 +384,7 @@ private void flushQuad(ModelQuadSinkDelegate consumer, ModelQuadViewMutable quad
vertexIdx += lightOrder;
}

consumer.get(ModelQuadFacing.fromDirection(dir))
consumer.get(facing)
.write(quad);
}

Expand Down

0 comments on commit 8b80ea3

Please sign in to comment.