Skip to content

Commit

Permalink
Add lighting to fluid rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Kneelawk committed Apr 28, 2024
1 parent 87fde14 commit 571bea8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,29 @@ public FluidRenderFace(

public static void appendCuboid(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, EnumSet<Direction> faces,
List<FluidRenderFace> to
List<FluidRenderFace> to, int light
) {
appendCuboid(x0, y0, z0, x1, y1, z1, textureScale, faces, to, false);
appendCuboid(x0, y0, z0, x1, y1, z1, textureScale, faces, to, false, light);
}

public static void appendCuboid(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, EnumSet<Direction> faces,
List<FluidRenderFace> to, boolean flowing
List<FluidRenderFace> to, boolean flowing, int light
) {
for (Direction face : faces) {
to.add(createFlatFace(x0, y0, z0, x1, y1, z1, textureScale, face, flowing));
to.add(createFlatFace(x0, y0, z0, x1, y1, z1, textureScale, face, flowing, light));
}
}

public static FluidRenderFace createFlatFaceX(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive, int light
) {
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, positive, false);
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, positive, false, light);
}

public static FluidRenderFace createFlatFaceX(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive,
boolean flowing
boolean flowing, int light
) {
final double s = textureScale;
if (positive) {
Expand All @@ -164,28 +164,28 @@ public static FluidRenderFace createFlatFaceX(
x1, y1, z0, z0 * s, y1 * s, //
x1, y1, z1, z1 * s, y1 * s, //
x1, y0, z1, z1 * s, y0 * s, //
FULL_LIGHT, +1, 0, 0, flowing
light, +1, 0, 0, flowing
);
} else {
return new FluidRenderFace(
x0, y0, z0, z0 * s, y0 * s, //
x0, y0, z1, z1 * s, y0 * s, //
x0, y1, z1, z1 * s, y1 * s, //
x0, y1, z0, z0 * s, y1 * s, //
FULL_LIGHT, -1, 0, 0, flowing
light, -1, 0, 0, flowing
);
}
}

public static FluidRenderFace createFlatFaceY(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive, int light
) {
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, positive, false);
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, positive, false, light);
}

public static FluidRenderFace createFlatFaceY(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive,
boolean flowing
boolean flowing, int light
) {
final double s = textureScale;
if (positive) {
Expand All @@ -194,28 +194,28 @@ public static FluidRenderFace createFlatFaceY(
x0, y1, z1, x0 * s, z1 * s, //
x1, y1, z1, x1 * s, z1 * s, //
x1, y1, z0, x1 * s, z0 * s, //
FULL_LIGHT, 0, +1, 0, flowing
light, 0, +1, 0, flowing
);
} else {
return new FluidRenderFace(
x0, y0, z0, x0 * s, z0 * s, //
x1, y0, z0, x1 * s, z0 * s, //
x1, y0, z1, x1 * s, z1 * s, //
x0, y0, z1, x0 * s, z1 * s, //
FULL_LIGHT, 0, -1, 0, flowing
light, 0, -1, 0, flowing
);
}
}

public static FluidRenderFace createFlatFaceZ(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive, int light
) {
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, positive, false);
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, positive, false, light);
}

public static FluidRenderFace createFlatFaceZ(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, boolean positive,
boolean flowing
boolean flowing, int light
) {
final double s = textureScale;
if (positive) {
Expand All @@ -224,42 +224,42 @@ public static FluidRenderFace createFlatFaceZ(
x1, y0, z1, x1 * s, y0 * s, //
x1, y1, z1, x1 * s, y1 * s, //
x0, y1, z1, x0 * s, y1 * s, //
FULL_LIGHT, 0, 0, +1, flowing
light, 0, 0, +1, flowing
);
} else {
return new FluidRenderFace(
x0, y0, z0, x0 * s, y0 * s, //
x0, y1, z0, x0 * s, y1 * s, //
x1, y1, z0, x1 * s, y1 * s, //
x1, y0, z0, x1 * s, y0 * s, //
FULL_LIGHT, 0, 0, -1, flowing
light, 0, 0, -1, flowing
);
}
}

public static FluidRenderFace createFlatFace(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, Direction face
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, Direction face, int light
) {
return createFlatFace(x0, y0, z0, x1, y1, z1, textureScale, face, false);
return createFlatFace(x0, y0, z0, x1, y1, z1, textureScale, face, false, light);
}

public static FluidRenderFace createFlatFace(
double x0, double y0, double z0, double x1, double y1, double z1, double textureScale, Direction face,
boolean flowing
boolean flowing, int light
) {
switch (face) {
case DOWN:
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, false, flowing);
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, false, flowing, light);
case UP:
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, true, flowing);
return createFlatFaceY(x0, y0, z0, x1, y1, z1, textureScale, true, flowing, light);
case NORTH:
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, false, flowing);
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, false, flowing, light);
case SOUTH:
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, true, flowing);
return createFlatFaceZ(x0, y0, z0, x1, y1, z1, textureScale, true, flowing, light);
case WEST:
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, false, flowing);
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, false, flowing, light);
case EAST:
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, true, flowing);
return createFlatFaceX(x0, y0, z0, x1, y1, z1, textureScale, true, flowing, light);
default: {
throw new IllegalStateException("Unknown Direction " + face);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract void render(

public void renderGuiRectangle(FluidVolume fluid, double x0, double y0, double x1, double y1) {
List<FluidRenderFace> faces = new ArrayList<>();
faces.add(FluidRenderFace.createFlatFaceZ(0, 0, 0, x1 - x0, y1 - y0, 0, 1 / 16.0, false, false));
faces.add(FluidRenderFace.createFlatFaceZ(0, 0, 0, x1 - x0, y1 - y0, 0, 1 / 16.0, false, false, FluidRenderFace.FULL_LIGHT));

MatrixStack matrices = new MatrixStack();
matrices.translate(x0, y0, 0);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/changelog/0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Changes:
* Updated to Minecraft 1.20.5.
* Added support for potion fluids holding the potions' custom effects.
* Added support for inserting and extracting from bundles.
* Added ability for fluids to render with lighting.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FluidFaceSplitterTester {
public void printFace() {
double l = 0.25;
double h = 0.75;
FluidRenderFace face = FluidRenderFace.createFlatFaceZ(l, l, 0, h, h, 0, 1, true);
FluidRenderFace face = FluidRenderFace.createFlatFaceZ(l, l, 0, h, h, 0, 1, true, FluidRenderFace.FULL_LIGHT);
System.out.println(face);

System.out.println("SPLIT:");
Expand Down

0 comments on commit 571bea8

Please sign in to comment.