-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract line rendering into an interface
- Loading branch information
1 parent
fd6b3b1
commit 7624d89
Showing
5 changed files
with
69 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/mods/railcraft/client/util/LineRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package mods.railcraft.client.util; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public interface LineRenderer { | ||
default void renderLine(PoseStack poseStack, int color, Vec3 from, Vec3 to) { | ||
renderLine(poseStack, | ||
RenderUtil.getRed(color), RenderUtil.getGreen(color), RenderUtil.getBlue(color), 1, | ||
(float) from.x, (float) from.y, (float) from.z, | ||
(float) to.x, (float) to.y, (float) to.z | ||
); | ||
} | ||
|
||
void renderLine(PoseStack poseStack, float r, float g, float b, float a, float x0, float y0, float z0, float x1, float y1, float z1); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/mods/railcraft/client/util/SimpleLineRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package mods.railcraft.client.util; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
public class SimpleLineRenderer implements LineRenderer { | ||
private final VertexConsumer consumer; | ||
|
||
public SimpleLineRenderer(MultiBufferSource bufferSource) { | ||
consumer = bufferSource.getBuffer(RenderType.lines()); | ||
} | ||
|
||
public void renderLine(PoseStack poseStack, float r, float g, float b, float a, float x0, float y0, float z0, float x1, float y1, float z1) { | ||
poseStack.pushPose(); | ||
var matrix = poseStack.last().pose(); | ||
var normal = poseStack.last().normal(); | ||
consumer | ||
.vertex(matrix, x0, y0, z0) | ||
.color(r, g, b, a) | ||
.normal(normal, 0, 0, 0) | ||
.endVertex(); | ||
consumer | ||
.vertex(matrix, x1, y1, z1) | ||
.color(r, g, b, a) | ||
.normal(normal, 0, 0, 0) | ||
.endVertex(); | ||
poseStack.popPose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters