Skip to content

Commit 901b2f8

Browse files
committed
First line rendered
1 parent f8ee33b commit 901b2f8

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

src/main/java/com/robotgryphon/compactcrafting/client/render/FieldProjectorRenderer.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
import net.minecraft.client.renderer.Atlases;
1111
import net.minecraft.client.renderer.BlockRendererDispatcher;
1212
import net.minecraft.client.renderer.IRenderTypeBuffer;
13+
import net.minecraft.client.renderer.RenderType;
1314
import net.minecraft.client.renderer.model.IBakedModel;
1415
import net.minecraft.client.renderer.model.ModelManager;
1516
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
1617
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
1718
import net.minecraft.util.Direction;
19+
import net.minecraft.util.math.AxisAlignedBB;
20+
import net.minecraft.util.math.vector.Matrix4f;
21+
import net.minecraft.util.math.vector.Vector3d;
1822
import net.minecraft.util.math.vector.Vector3f;
1923
import net.minecraftforge.client.model.ModelDataManager;
2024
import net.minecraftforge.client.model.data.IModelData;
2125

26+
import java.awt.*;
27+
2228
public class FieldProjectorRenderer extends TileEntityRenderer<FieldProjectorTile> {
2329

2430
enum RotationSpeed {
@@ -39,6 +45,12 @@ public int getSpeed() {
3945

4046
private IBakedModel bakedModelCached;
4147

48+
// RenderType t = RenderType.makeType("my_type", DefaultVertexFormats.POSITION_COLOR, 7, 256,
49+
// false, true, RenderType.State.getBuilder()
50+
// .transparency(TRANSLUCENT_TRANSPARENCY)
51+
// .writeMask(COLOR_DEPTH_WRITE)
52+
// .build(false));
53+
4254
public FieldProjectorRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
4355
super(rendererDispatcherIn);
4456

@@ -48,6 +60,9 @@ public FieldProjectorRenderer(TileEntityRendererDispatcher rendererDispatcherIn)
4860
@Override
4961
public void render(FieldProjectorTile tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
5062
renderDish(tileEntityIn, matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
63+
64+
AxisAlignedBB cube = new AxisAlignedBB(tileEntityIn.getPos()).grow(3);
65+
renderFaces(matrixStackIn, bufferIn, cube, 0);
5166
}
5267

5368
private IBakedModel getModel() {
@@ -64,6 +79,24 @@ private IBakedModel getModel() {
6479
return bakedModelCached;
6580
}
6681

82+
/**
83+
* Draw a coloured line from a starting vertex to an end vertex
84+
*
85+
* @param matrixPos the current transformation matrix
86+
* @param renderBuffer the vertex builder used to draw the line
87+
* @param startVertex
88+
* @param endVertex
89+
*/
90+
private static void drawLine(Matrix4f matrixPos, IVertexBuilder renderBuffer, Color color,
91+
Vector3d startVertex, Vector3d endVertex) {
92+
renderBuffer.pos(matrixPos, (float) startVertex.x, (float) startVertex.y, (float) startVertex.z)
93+
.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()) // there is also a version for floats (0 -> 1)
94+
.endVertex();
95+
renderBuffer.pos(matrixPos, (float) endVertex.getX(), (float) endVertex.getY(), (float) endVertex.getZ())
96+
.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()) // there is also a version for floats (0 -> 1)
97+
.endVertex();
98+
}
99+
67100
private void renderDish(FieldProjectorTile te, MatrixStack mx, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) {
68101

69102
BlockState state = te.getBlockState();
@@ -101,4 +134,96 @@ private void renderDish(FieldProjectorTile te, MatrixStack mx, IRenderTypeBuffer
101134

102135
mx.pop();
103136
}
137+
138+
private void renderFaces(MatrixStack mx, IRenderTypeBuffer buffer, AxisAlignedBB cube, double extraLength) {
139+
140+
try {
141+
IVertexBuilder lines = buffer.getBuffer(RenderType.getLines());
142+
143+
//region color and vertex positions
144+
int color = 0xFF6A00;
145+
float cR = (color >> 16 & 255) / 255.0f;
146+
float cG = (color >> 8 & 255) / 255.0f;
147+
float cB = (color & 255) / 255.0f;
148+
float cA = 0.15f;
149+
150+
double x1 = cube.minX;
151+
double x2 = cube.maxX;
152+
double y1 = cube.minY;
153+
double y2 = cube.maxY;
154+
double z1 = cube.minZ;
155+
double z2 = cube.maxZ;
156+
double radius = (cube.maxY - cube.minY) / 2;
157+
158+
double y4 = cube.maxY - radius + 0.3d;
159+
//endregion
160+
161+
// Draw the faces
162+
Vector3d start = new Vector3d(cube.minX, cube.minY, cube.minZ);
163+
Vector3d end = new Vector3d(cube.maxX, cube.maxY, cube.maxZ);
164+
165+
drawLine(mx.getLast().getMatrix(), lines, Color.orange, start, end);
166+
167+
// lines.pos(x1, y2, z1).color(cR, cG, cB, cA).endVertex();
168+
// lines.pos(x2, y2, z1).color(cR, cG, cB, cA).endVertex();
169+
// lines.pos(x2, y1, z1).color(cR, cG, cB, cA).endVertex();
170+
// lines.pos(x1, y1, z2).color(cR, cG, cB, cA).endVertex();
171+
// lines.pos(x2, y1, z2).color(cR, cG, cB, cA).endVertex();
172+
// lines.pos(x2, y2, z2).color(cR, cG, cB, cA).endVertex();
173+
// lines.pos(x1, y2, z2).color(cR, cG, cB, cA).endVertex();
174+
//
175+
// lines.pos(x1, y1, z1).color(cR, cG, cB, cA).endVertex();
176+
// lines.pos(x2, y1, z1).color(cR, cG, cB, cA).endVertex();
177+
// lines.pos(x2, y1, z2).color(cR, cG, cB, cA).endVertex();
178+
// lines.pos(x1, y1, z2).color(cR, cG, cB, cA).endVertex();
179+
// lines.pos(x1, y2, z1).color(cR, cG, cB, cA).endVertex();
180+
// lines.pos(x1, y2, z2).color(cR, cG, cB, cA).endVertex();
181+
// lines.pos(x2, y2, z2).color(cR, cG, cB, cA).endVertex();
182+
// lines.pos(x2, y2, z1).color(cR, cG, cB, cA).endVertex();
183+
//
184+
// lines.pos(x1, y1, z1).color(cR, cG, cB, cA).endVertex();
185+
// lines.pos(x1, y1, z2).color(cR, cG, cB, cA).endVertex();
186+
// lines.pos(x1, y2, z2).color(cR, cG, cB, cA).endVertex();
187+
// lines.pos(x1, y2, z1).color(cR, cG, cB, cA).endVertex();
188+
// lines.pos(x2, y1, z1).color(cR, cG, cB, cA).endVertex();
189+
// lines.pos(x2, y2, z1).color(cR, cG, cB, cA).endVertex();
190+
// lines.pos(x2, y2, z2).color(cR, cG, cB, cA).endVertex();
191+
// lines.pos(x2, y1, z2).color(cR, cG, cB, cA).endVertex();
192+
} catch (Exception ex) {
193+
}
194+
195+
// Render projection planes
196+
// double zAngle = ((Math.sin(Math.toDegrees(RenderTickCounter.renderTicks) / -5000) + 1.0d) / 2) * (cube.maxY - cube.minY);
197+
// double y3 = y1 + zAngle;
198+
// float cA2 = 0.105f;
199+
200+
// Ensure both sides of the plane are visible
201+
// GlStateManager.disableCull();
202+
// GL11.glDisable(GL11.GL_CULL_FACE);
203+
// // north -> south
204+
// buffer.pos(x1, y3, z1).color(cR, cG, cB, cA2).endVertex();
205+
// buffer.pos(x2, y3, z1).color(cR, cG, cB, cA2).endVertex();
206+
// buffer.pos(x2-(radius-0.2f), y4, z1-(radius+0.8f+extraLength)).color(cR, cG, cB, cA2).endVertex();
207+
// buffer.pos(x1+(radius-0.2f), y4, z1-(radius+0.8f+extraLength)).color(cR, cG, cB, cA2).endVertex();
208+
//
209+
// // east -> west
210+
// buffer.pos(x2, y3, z1).color(cR, cG, cB, cA2).endVertex();
211+
// buffer.pos(x2, y3, z2).color(cR, cG, cB, cA2).endVertex();
212+
// buffer.pos(x2+(radius+0.8f+extraLength), y4, z2-(radius-0.2f)).color(cR, cG, cB, cA2).endVertex();
213+
// buffer.pos(x2+(radius+0.8f+extraLength), y4, z1+(radius-0.2f)).color(cR, cG, cB, cA2).endVertex();
214+
//
215+
// // south -> north
216+
// buffer.pos(x1, y3, z2).color(cR, cG, cB, cA2).endVertex();
217+
// buffer.pos(x2, y3, z2).color(cR, cG, cB, cA2).endVertex();
218+
// buffer.pos(x2-(radius-0.2f), y4, z2+(radius+0.8f+extraLength)).color(cR, cG, cB, cA2).endVertex();
219+
// buffer.pos(x1+(radius-0.2f), y4, z2+(radius+0.8f+extraLength)).color(cR, cG, cB, cA2).endVertex();
220+
//
221+
// // west -> east
222+
// buffer.pos(x1, y3, z1).color(cR, cG, cB, cA2).endVertex();
223+
// buffer.pos(x1, y3, z2).color(cR, cG, cB, cA2).endVertex();
224+
// buffer.pos(x1-(radius+0.8f+extraLength), y4, z2-(radius-0.2f)).color(cR, cG, cB, cA2).endVertex();
225+
// buffer.pos(x1-(radius+0.8f+extraLength), y4, z1+(radius-0.2f)).color(cR, cG, cB, cA2).endVertex();
226+
227+
// GlStateManager.enableCull();
228+
}
104229
}

0 commit comments

Comments
 (0)