Skip to content

Commit 206be46

Browse files
committed
Basic rendering and helper methods for projection field and scan lines
1 parent aeac9fc commit 206be46

File tree

1 file changed

+93
-68
lines changed

1 file changed

+93
-68
lines changed

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

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import net.minecraft.util.math.BlockPos;
1818
import net.minecraft.util.math.vector.Vector3d;
1919
import net.minecraft.util.math.vector.Vector3f;
20-
import net.minecraft.util.math.vector.Vector3i;
2120
import net.minecraftforge.client.model.ModelDataManager;
2221
import net.minecraftforge.client.model.data.IModelData;
2322

@@ -45,6 +44,7 @@ public int getSpeed() {
4544
}
4645

4746
private IBakedModel bakedModelCached;
47+
private final Color colorProjectionCube = new Color(255, 106, 0, 100);
4848

4949
public FieldProjectorRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
5050
super(rendererDispatcherIn);
@@ -55,13 +55,13 @@ public void render(FieldProjectorTile tile, float partialTicks, MatrixStack matr
5555
renderDish(tile, matrixStack, buffers, combinedLightIn, combinedOverlayIn);
5656

5757
Optional<BlockPos> c = tile.getCenter();
58-
if(c.isPresent()) {
58+
if (c.isPresent()) {
5959
BlockPos center = c.get();
6060
AxisAlignedBB cube = new AxisAlignedBB(center).grow(2);
6161

6262
renderFaces(tile, matrixStack, buffers, cube, 0);
6363

64-
if(tile.isMainProjector()) {
64+
if (tile.isMainProjector()) {
6565
drawScanLines(tile, matrixStack, buffers, cube, 2);
6666
renderProjectionCube(tile, matrixStack, buffers, cube, 2);
6767
}
@@ -90,6 +90,82 @@ private void addColoredVertex(IVertexBuilder renderer, MatrixStack stack, Color
9090
.endVertex();
9191
}
9292

93+
/**
94+
* Draws a cube given a vertex builder, matrix, color, and cube bounds.
95+
*
96+
* @param builder
97+
* @param mx
98+
* @param cube
99+
* @param color
100+
*/
101+
private void drawCube(IVertexBuilder builder, MatrixStack mx, AxisAlignedBB cube, Color color) {
102+
drawCubeFace(builder, mx, cube, color, Direction.NORTH);
103+
drawCubeFace(builder, mx, cube, color, Direction.SOUTH);
104+
drawCubeFace(builder, mx, cube, color, Direction.WEST);
105+
drawCubeFace(builder, mx, cube, color, Direction.EAST);
106+
drawCubeFace(builder, mx, cube, color, Direction.UP);
107+
drawCubeFace(builder, mx, cube, color, Direction.DOWN);
108+
}
109+
110+
private void drawCubeFace(IVertexBuilder builder, MatrixStack mx, AxisAlignedBB cube, Color color, Direction face) {
111+
Vector3f BOTTOM_RIGHT = null,
112+
TOP_RIGHT = null,
113+
TOP_LEFT = null,
114+
BOTTOM_LEFT = null;
115+
116+
switch (face) {
117+
case NORTH:
118+
BOTTOM_RIGHT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ);
119+
TOP_RIGHT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ);
120+
TOP_LEFT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ);
121+
BOTTOM_LEFT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ);
122+
break;
123+
124+
case SOUTH:
125+
BOTTOM_RIGHT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ);
126+
TOP_RIGHT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ);
127+
TOP_LEFT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ);
128+
BOTTOM_LEFT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ);
129+
break;
130+
131+
case WEST:
132+
BOTTOM_RIGHT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ);
133+
TOP_RIGHT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ);
134+
TOP_LEFT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ);
135+
BOTTOM_LEFT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ);
136+
break;
137+
138+
case EAST:
139+
BOTTOM_RIGHT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ);
140+
TOP_RIGHT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ);
141+
TOP_LEFT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ);
142+
BOTTOM_LEFT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ);
143+
break;
144+
145+
case UP:
146+
BOTTOM_RIGHT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ);
147+
TOP_RIGHT = new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ);
148+
TOP_LEFT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ);
149+
BOTTOM_LEFT = new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ);
150+
break;
151+
152+
case DOWN:
153+
BOTTOM_RIGHT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ);
154+
TOP_RIGHT = new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ);
155+
TOP_LEFT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ);
156+
BOTTOM_LEFT = new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ);
157+
break;
158+
}
159+
160+
if (BOTTOM_RIGHT == null)
161+
return;
162+
163+
addColoredVertex(builder, mx, color, BOTTOM_RIGHT);
164+
addColoredVertex(builder, mx, color, TOP_RIGHT);
165+
addColoredVertex(builder, mx, color, TOP_LEFT);
166+
addColoredVertex(builder, mx, color, BOTTOM_LEFT);
167+
}
168+
93169
private void renderDish(FieldProjectorTile te, MatrixStack mx, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) {
94170

95171
BlockState state = te.getBlockState();
@@ -132,14 +208,14 @@ private void renderDish(FieldProjectorTile te, MatrixStack mx, IRenderTypeBuffer
132208
* TODO - Main projector (single, NORTH projector)
133209
* TODO - render scan line animated over main crafting projection
134210
* TODO - render main crafting projection cube
135-
*
211+
* <p>
136212
* TODO - All projectors (individually)
137213
* TODO - render projection arc connecting projector to large cube
138214
*/
139215

140216
private void translateRendererToCube(FieldProjectorTile tile, MatrixStack mx, AxisAlignedBB cube, int cubeSize) {
141217
Optional<BlockPos> c = tile.getCenter();
142-
if(!c.isPresent())
218+
if (!c.isPresent())
143219
return;
144220

145221
BlockPos center = c.get();
@@ -154,6 +230,7 @@ private void translateRendererToCube(FieldProjectorTile tile, MatrixStack mx, Ax
154230

155231
mx.translate(offsetToCenter.getX(), offsetToCenter.getY(), offsetToCenter.getZ());
156232
}
233+
157234
/**
158235
* Handles rendering the main projection cube in the center of the projection area.
159236
* Should only be called by the main projector (typically the NORTH projector)
@@ -165,50 +242,7 @@ private void renderProjectionCube(FieldProjectorTile tile, MatrixStack mx, IRend
165242

166243
IVertexBuilder builder = buffers.getBuffer(RenderTypesExtensions.PROJECTION_FIELD_RENDERTYPE);
167244

168-
Color bounds = new Color(255, 106, 0, 100);
169-
170-
// Draw bounds of projection cube
171-
172-
// North face
173-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ));
174-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ));
175-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ));
176-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ));
177-
178-
// South face
179-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ));
180-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ));
181-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ));
182-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ));
183-
184-
// West face
185-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ));
186-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ));
187-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ));
188-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ));
189-
190-
// East face
191-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ));
192-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ));
193-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ));
194-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ));
195-
196-
// Top face
197-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.minZ));
198-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.maxY, (float) cube.maxZ));
199-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.maxZ));
200-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.maxY, (float) cube.minZ));
201-
202-
// Bottom face
203-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.maxZ));
204-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.minX, (float) cube.minY, (float) cube.minZ));
205-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.minZ));
206-
addColoredVertex(builder, mx, bounds, new Vector3f((float) cube.maxX, (float) cube.minY, (float) cube.maxZ));
207-
208-
209-
210-
211-
245+
drawCube(builder, mx, cube, colorProjectionCube);
212246

213247
mx.pop();
214248
}
@@ -267,37 +301,28 @@ private void drawScanLines(FieldProjectorTile tile, MatrixStack mx, IRenderTypeB
267301
IVertexBuilder builder = buffers.getBuffer(RenderType.getLines());
268302
Color fieldColor = new Color(255, 106, 0, 200);
269303

270-
float x1 = (float) cube.minX;
271-
float x2 = (float) cube.maxX;
272-
float y1 = (float) cube.minY;
273-
float y2 = (float) cube.maxY;
274-
float z1 = (float) cube.minZ;
275-
float z2 = (float) cube.maxZ;
276-
277304
// Draw the up and down bouncing lines on the sides
278-
double zAngle = ((Math.sin(Math.toDegrees(RenderTickCounter.renderTicks) / -5000) + 1.0d) / 2) * (y2 - y1);
279-
float y3 = (float) (y1 + zAngle);
280-
305+
double zAngle = ((Math.sin(Math.toDegrees(RenderTickCounter.renderTicks) / -5000) + 1.0d) / 2) * (cube.getYSize());
306+
float scanHeight = (float) (cube.minY + zAngle);
281307

282308

283309
// Scan Lines
284-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x1, y3, z1));
285-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x2, y3, z1));
310+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.minX, scanHeight, (float) cube.minZ));
311+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.maxX, scanHeight, (float) cube.minZ));
286312

287-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x1, y3, z1));
288-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x1, y3, z2));
313+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.minX, scanHeight, (float) cube.minZ));
314+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.minX, scanHeight, (float) cube.maxZ));
289315

290-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x2, y3, z2));
291-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x2, y3, z1));
316+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.maxX, scanHeight, (float) cube.maxZ));
317+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.maxX, scanHeight, (float) cube.minZ));
292318

293-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x1, y3, z2));
294-
addColoredVertex(builder, mx, fieldColor, new Vector3f(x2, y3, z2));
319+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.minX, scanHeight, (float) cube.maxZ));
320+
addColoredVertex(builder, mx, fieldColor, new Vector3f((float) cube.maxX, scanHeight, (float) cube.maxZ));
295321

296322
mx.pop();
297323
}
298324

299325
/**
300-
*
301326
* @param mx
302327
* @param buffer
303328
* @param cube

0 commit comments

Comments
 (0)