Browse Source

Attempting to fix Rendering of Water

Gregorius Techneticies 2 months ago
parent
commit
53c2732996
Signed by: Gregorius Techneticies <gregoriustech@gmail.com> GPG Key ID: 1B693EA14F2FD70F

+ 2
- 1
src/main/java/gregapi/block/fluid/BlockBaseFluid.java View File

@@ -281,7 +281,8 @@ public class BlockBaseFluid extends BlockFluidFinite implements IBlock, IItemGT,
281 281
 		if (aBlock == this || aBlock.getMaterial() == Material.water || WD.visOpq(aBlock)) return F;
282 282
 		if (aBlock.isAir(aWorld, aX, aY, aZ)) return T;
283 283
 		TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
284
-		return !(tTileEntity instanceof ITileEntitySurface && !((ITileEntitySurface)tTileEntity).isSurfaceOpaque(OPPOSITES[aSide]));
284
+		if (tTileEntity instanceof ITileEntitySurface) return !((ITileEntitySurface)tTileEntity).isSurfaceOpaque(OPPOSITES[aSide]);
285
+		return T;
285 286
 	}
286 287
 	
287 288
 	@Override public Block getBlock() {return this;}

+ 83
- 69
src/main/java/gregapi/render/RendererBlockFluid.java View File

@@ -1,5 +1,5 @@
1 1
 /**
2
- * Copyright (c) 2020 GregTech-6 Team
2
+ * Copyright (c) 2021 GregTech-6 Team
3 3
  *
4 4
  * This file is part of GregTech.
5 5
  *
@@ -23,6 +23,7 @@ import static gregapi.data.CS.*;
23 23
 
24 24
 import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
25 25
 import gregapi.data.FL;
26
+import gregapi.old.Textures;
26 27
 import gregapi.util.UT;
27 28
 import net.minecraft.block.Block;
28 29
 import net.minecraft.client.renderer.RenderBlocks;
@@ -74,29 +75,43 @@ public class RendererBlockFluid implements ISimpleBlockRenderingHandler {
74 75
 	@Override
75 76
 	public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, int aModelID, RenderBlocks aRenderer) {
76 77
 		if (!(aBlock instanceof BlockFluidBase)) return F;
78
+		BlockFluidBase aFluid = (BlockFluidBase)aBlock;
77 79
 		
78
-		Tessellator tessellator = Tessellator.instance;
79
-		int color = aBlock.colorMultiplier(aWorld, aX, aY, aZ);
80
+		Tessellator tTesselator = Tessellator.instance;
81
+		int color = aFluid.colorMultiplier(aWorld, aX, aY, aZ);
80 82
 		float red = (color >> 16 & 255) / 255.0F;
81 83
 		float green = (color >> 8 & 255) / 255.0F;
82 84
 		float blue = (color & 255) / 255.0F;
83 85
 		
84
-		BlockFluidBase aFluid = (BlockFluidBase)aBlock;
85 86
 		int bMeta = aWorld.getBlockMetadata(aX, aY, aZ), aDir = FL.dir(aFluid);
86 87
 		
87 88
 		boolean renderTop = aWorld.getBlock(aX, aY - aDir, aZ) != aFluid;
88
-		boolean renderBottom = aBlock.shouldSideBeRendered(aWorld, aX, aY + aDir, aZ, 0) && aWorld.getBlock(aX, aY + aDir, aZ) != aFluid;
89
+		boolean renderBottom = aFluid.shouldSideBeRendered(aWorld, aX, aY + aDir, aZ, 0) && aWorld.getBlock(aX, aY + aDir, aZ) != aFluid;
89 90
 		
90 91
 		boolean[] renderSides = new boolean[] {
91
-			aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ - 1, 2),
92
-			aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ + 1, 3),
93
-			aBlock.shouldSideBeRendered(aWorld, aX - 1, aY, aZ, 4),
94
-			aBlock.shouldSideBeRendered(aWorld, aX + 1, aY, aZ, 5)
92
+			aFluid.shouldSideBeRendered(aWorld, aX, aY, aZ - 1, 2),
93
+			aFluid.shouldSideBeRendered(aWorld, aX, aY, aZ + 1, 3),
94
+			aFluid.shouldSideBeRendered(aWorld, aX - 1, aY, aZ, 4),
95
+			aFluid.shouldSideBeRendered(aWorld, aX + 1, aY, aZ, 5)
95 96
 		};
96 97
 		
97
-		if (!renderTop && !renderBottom && !renderSides[0] && !renderSides[1] && !renderSides[2] && !renderSides[3]) return F;
98
+		if (!renderTop && !renderBottom && !renderSides[0] && !renderSides[1] && !renderSides[2] && !renderSides[3]) {
99
+			IIcon tIcon = Textures.BlockIcons.VOID.getIcon(0);
100
+			double
101
+			u2 = tIcon.getInterpolatedU(0), v2 = tIcon.getInterpolatedV(0),
102
+			u1 = u2, v1 = tIcon.getInterpolatedV(16),
103
+			u4 = tIcon.getInterpolatedU(16), v4 = v1,
104
+			u3 = u4, v3 = v2;
105
+			
106
+			tTesselator.addVertexWithUV(0, -128, 0, u3, v3);
107
+			tTesselator.addVertexWithUV(0, -128, 0, u4, v4);
108
+			tTesselator.addVertexWithUV(0, -128, 0, u1, v1);
109
+			tTesselator.addVertexWithUV(0, -128, 0, u2, v2);
110
+			return T;
111
+		}
112
+		
98 113
 		double heightNW, heightSW, heightSE, heightNE;
99
-		float flow11 = getFluidHeightForRender(aWorld, aX, aY, aZ, aFluid, aBlock);
114
+		float flow11 = getFluidHeightForRender(aWorld, aX, aY, aZ, aFluid, aFluid);
100 115
 		boolean rRendered = F;
101 116
 		
102 117
 		if (flow11 != 1) {
@@ -108,7 +123,7 @@ public class RendererBlockFluid implements ISimpleBlockRenderingHandler {
108 123
 			float flow20 = getFluidHeightForRender(aWorld, aX + 1, aY, aZ - 1, aFluid, null);
109 124
 			float flow21 = getFluidHeightForRender(aWorld, aX + 1, aY, aZ,     aFluid, null);
110 125
 			float flow22 = getFluidHeightForRender(aWorld, aX + 1, aY, aZ + 1, aFluid, null);
111
-
126
+			
112 127
 			heightNW = getFluidHeightAverage(new float[] {flow00, flow01, flow10, flow11});
113 128
 			heightSW = getFluidHeightAverage(new float[] {flow01, flow02, flow12, flow11});
114 129
 			heightSE = getFluidHeightAverage(new float[] {flow12, flow21, flow22, flow11});
@@ -120,21 +135,20 @@ public class RendererBlockFluid implements ISimpleBlockRenderingHandler {
120 135
 			heightNE = flow11;
121 136
 		}
122 137
 		
123
-		boolean rises = aDir == 1;
124 138
 		if (aRenderer.renderAllFaces || renderTop) {
125 139
 			rRendered = T;
126
-			IIcon iconStill = aBlock.getIcon(1, bMeta);
140
+			IIcon iconStill = aFluid.getIcon(1, bMeta);
127 141
 			float flowDir = (float)BlockFluidBase.getFlowDirection(aWorld, aX, aY, aZ);
128 142
 			
129
-			if (flowDir > -999.0F) iconStill = aBlock.getIcon(2, bMeta);
143
+			if (flowDir > -999.0F) iconStill = aFluid.getIcon(2, bMeta);
130 144
 			
131 145
 			heightNW -= RENDER_OFFSET;
132 146
 			heightSW -= RENDER_OFFSET;
133 147
 			heightSE -= RENDER_OFFSET;
134 148
 			heightNE -= RENDER_OFFSET;
135
-
149
+			
136 150
 			double u1, u2, u3, u4, v1, v2, v3, v4;
137
-
151
+			
138 152
 			if (flowDir < -999.0F) {
139 153
 				u2 = iconStill.getInterpolatedU(0.0D);
140 154
 				v2 = iconStill.getInterpolatedV(0.0D);
@@ -156,57 +170,57 @@ public class RendererBlockFluid implements ISimpleBlockRenderingHandler {
156 170
 				u3 = iconStill.getInterpolatedU(8.0F + (+zFlow - xFlow) * 16.0F);
157 171
 				v3 = iconStill.getInterpolatedV(8.0F + (-zFlow - xFlow) * 16.0F);
158 172
 			}
159
-
160
-			tessellator.setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY, aZ));
161
-			tessellator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue);
162
-
163
-			if (!rises) {
164
-				tessellator.addVertexWithUV(aX + 0, aY + heightNW, aZ + 0, u2, v2);
165
-				tessellator.addVertexWithUV(aX + 0, aY + heightSW, aZ + 1, u1, v1);
166
-				tessellator.addVertexWithUV(aX + 1, aY + heightSE, aZ + 1, u4, v4);
167
-				tessellator.addVertexWithUV(aX + 1, aY + heightNE, aZ + 0, u3, v3);
173
+			
174
+			tTesselator.setBrightness(aFluid.getMixedBrightnessForBlock(aWorld, aX, aY, aZ));
175
+			tTesselator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue);
176
+			
177
+			if (aDir < 0) {
178
+				tTesselator.addVertexWithUV(aX + 0, aY + heightNW, aZ + 0, u2, v2);
179
+				tTesselator.addVertexWithUV(aX + 0, aY + heightSW, aZ + 1, u1, v1);
180
+				tTesselator.addVertexWithUV(aX + 1, aY + heightSE, aZ + 1, u4, v4);
181
+				tTesselator.addVertexWithUV(aX + 1, aY + heightNE, aZ + 0, u3, v3);
168 182
 				
169
-				tessellator.addVertexWithUV(aX + 0, aY + heightNW, aZ + 0, u2, v2);
170
-				tessellator.addVertexWithUV(aX + 1, aY + heightNE, aZ + 0, u3, v3);
171
-				tessellator.addVertexWithUV(aX + 1, aY + heightSE, aZ + 1, u4, v4);
172
-				tessellator.addVertexWithUV(aX + 0, aY + heightSW, aZ + 1, u1, v1);
183
+				tTesselator.addVertexWithUV(aX + 0, aY + heightNW, aZ + 0, u2, v2);
184
+				tTesselator.addVertexWithUV(aX + 1, aY + heightNE, aZ + 0, u3, v3);
185
+				tTesselator.addVertexWithUV(aX + 1, aY + heightSE, aZ + 1, u4, v4);
186
+				tTesselator.addVertexWithUV(aX + 0, aY + heightSW, aZ + 1, u1, v1);
173 187
 			} else {
174
-				tessellator.addVertexWithUV(aX + 1, aY + 1 - heightNE, aZ + 0, u3, v3);
175
-				tessellator.addVertexWithUV(aX + 1, aY + 1 - heightSE, aZ + 1, u4, v4);
176
-				tessellator.addVertexWithUV(aX + 0, aY + 1 - heightSW, aZ + 1, u1, v1);
177
-				tessellator.addVertexWithUV(aX + 0, aY + 1 - heightNW, aZ + 0, u2, v2);
188
+				tTesselator.addVertexWithUV(aX + 1, aY + 1 - heightNE, aZ + 0, u3, v3);
189
+				tTesselator.addVertexWithUV(aX + 1, aY + 1 - heightSE, aZ + 1, u4, v4);
190
+				tTesselator.addVertexWithUV(aX + 0, aY + 1 - heightSW, aZ + 1, u1, v1);
191
+				tTesselator.addVertexWithUV(aX + 0, aY + 1 - heightNW, aZ + 0, u2, v2);
178 192
 				
179
-				tessellator.addVertexWithUV(aX + 1, aY + 1 - heightNE, aZ + 0, u3, v3);
180
-				tessellator.addVertexWithUV(aX + 0, aY + 1 - heightNW, aZ + 0, u2, v2);
181
-				tessellator.addVertexWithUV(aX + 0, aY + 1 - heightSW, aZ + 1, u1, v1);
182
-				tessellator.addVertexWithUV(aX + 1, aY + 1 - heightSE, aZ + 1, u4, v4);
193
+				tTesselator.addVertexWithUV(aX + 1, aY + 1 - heightNE, aZ + 0, u3, v3);
194
+				tTesselator.addVertexWithUV(aX + 0, aY + 1 - heightNW, aZ + 0, u2, v2);
195
+				tTesselator.addVertexWithUV(aX + 0, aY + 1 - heightSW, aZ + 1, u1, v1);
196
+				tTesselator.addVertexWithUV(aX + 1, aY + 1 - heightSE, aZ + 1, u4, v4);
183 197
 			}
184 198
 		}
185 199
 		
186 200
 		if (aRenderer.renderAllFaces || renderBottom) {
187 201
 			rRendered = T;
188
-			tessellator.setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY - 1, aZ));
189
-			if (!rises) {
190
-				tessellator.setColorOpaque_F(LIGHT_Y_NEG * red, LIGHT_Y_NEG * green, LIGHT_Y_NEG * blue);
191
-				aRenderer.renderFaceYNeg(aBlock, aX, aY + RENDER_OFFSET, aZ, aBlock.getIcon(0, bMeta));
202
+			tTesselator.setBrightness(aFluid.getMixedBrightnessForBlock(aWorld, aX, aY - 1, aZ));
203
+			if (aDir < 0) {
204
+				tTesselator.setColorOpaque_F(LIGHT_Y_NEG * red, LIGHT_Y_NEG * green, LIGHT_Y_NEG * blue);
205
+				aRenderer.renderFaceYNeg(aFluid, aX, aY + RENDER_OFFSET, aZ, aFluid.getIcon(0, bMeta));
192 206
 			} else {
193
-				tessellator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue);
194
-				aRenderer.renderFaceYPos(aBlock, aX, aY + RENDER_OFFSET, aZ, aBlock.getIcon(1, bMeta));
207
+				tTesselator.setColorOpaque_F(LIGHT_Y_POS * red, LIGHT_Y_POS * green, LIGHT_Y_POS * blue);
208
+				aRenderer.renderFaceYPos(aFluid, aX, aY + RENDER_OFFSET, aZ, aFluid.getIcon(1, bMeta));
195 209
 			}
196 210
 		}
197 211
 		
198 212
 		for (int side = 0; side < 4; ++side) {
199 213
 			int x2 = aX;
200 214
 			int z2 = aZ;
201
-
215
+			
202 216
 			switch (side) {
203 217
 				case 0: --z2; break;
204 218
 				case 1: ++z2; break;
205 219
 				case 2: --x2; break;
206 220
 				case 3: ++x2; break;
207 221
 			}
208
-
209
-			IIcon iconFlow = aBlock.getIcon(side + 2, bMeta);
222
+			
223
+			IIcon iconFlow = aFluid.getIcon(side + 2, bMeta);
210 224
 			if (aRenderer.renderAllFaces || renderSides[side]) {
211 225
 				double ty1, tx1, ty2, tx2, tz1, tz2;
212 226
 				rRendered = T;
@@ -240,37 +254,37 @@ public class RendererBlockFluid implements ISimpleBlockRenderingHandler {
240 254
 					tz1 = aZ;
241 255
 					tz2 = aZ + 1;
242 256
 				}
243
-
257
+				
244 258
 				float u1Flow = iconFlow.getInterpolatedU(0.0D);
245 259
 				float u2Flow = iconFlow.getInterpolatedU(8.0D);
246 260
 				float v1Flow = iconFlow.getInterpolatedV((1.0D - ty1) * 16.0D * 0.5D);
247 261
 				float v2Flow = iconFlow.getInterpolatedV((1.0D - ty2) * 16.0D * 0.5D);
248 262
 				float v3Flow = iconFlow.getInterpolatedV(8.0D);
249
-				tessellator.setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, x2, aY, z2));
263
+				tTesselator.setBrightness(aFluid.getMixedBrightnessForBlock(aWorld, x2, aY, z2));
250 264
 				float sideLighting = (side < 2?LIGHT_XZ_NEG:LIGHT_XZ_POS);
265
+				
266
+				tTesselator.setColorOpaque_F(LIGHT_Y_POS * sideLighting * red, LIGHT_Y_POS * sideLighting * green, LIGHT_Y_POS * sideLighting * blue);
267
+				
268
+				if (aDir < 0) {
269
+					tTesselator.addVertexWithUV(tx1, aY + ty1, tz1, u1Flow, v1Flow);
270
+					tTesselator.addVertexWithUV(tx2, aY + ty2, tz2, u2Flow, v2Flow);
271
+					tTesselator.addVertexWithUV(tx2, aY +   0, tz2, u2Flow, v3Flow);
272
+					tTesselator.addVertexWithUV(tx1, aY +   0, tz1, u1Flow, v3Flow);
251 273
 
252
-				tessellator.setColorOpaque_F(LIGHT_Y_POS * sideLighting * red, LIGHT_Y_POS * sideLighting * green, LIGHT_Y_POS * sideLighting * blue);
253
-
254
-				if (!rises) {
255
-					tessellator.addVertexWithUV(tx1, aY + ty1, tz1, u1Flow, v1Flow);
256
-					tessellator.addVertexWithUV(tx2, aY + ty2, tz2, u2Flow, v2Flow);
257
-					tessellator.addVertexWithUV(tx2, aY + 0, tz2, u2Flow, v3Flow);
258
-					tessellator.addVertexWithUV(tx1, aY + 0, tz1, u1Flow, v3Flow);
259
-
260
-					tessellator.addVertexWithUV(tx1, aY + ty1, tz1, u1Flow, v1Flow);
261
-					tessellator.addVertexWithUV(tx1, aY + 0, tz1, u1Flow, v3Flow);
262
-					tessellator.addVertexWithUV(tx2, aY + 0, tz2, u2Flow, v3Flow);
263
-					tessellator.addVertexWithUV(tx2, aY + ty2, tz2, u2Flow, v2Flow);
274
+					tTesselator.addVertexWithUV(tx1, aY + ty1, tz1, u1Flow, v1Flow);
275
+					tTesselator.addVertexWithUV(tx1, aY +   0, tz1, u1Flow, v3Flow);
276
+					tTesselator.addVertexWithUV(tx2, aY +   0, tz2, u2Flow, v3Flow);
277
+					tTesselator.addVertexWithUV(tx2, aY + ty2, tz2, u2Flow, v2Flow);
264 278
 				} else {
265
-					tessellator.addVertexWithUV(tx1, aY + 1 - 0, tz1, u1Flow, v3Flow);
266
-					tessellator.addVertexWithUV(tx2, aY + 1 - 0, tz2, u2Flow, v3Flow);
267
-					tessellator.addVertexWithUV(tx2, aY + 1 - ty2, tz2, u2Flow, v2Flow);
268
-					tessellator.addVertexWithUV(tx1, aY + 1 - ty1, tz1, u1Flow, v1Flow);
279
+					tTesselator.addVertexWithUV(tx1, aY + 1 -   0, tz1, u1Flow, v3Flow);
280
+					tTesselator.addVertexWithUV(tx2, aY + 1 -   0, tz2, u2Flow, v3Flow);
281
+					tTesselator.addVertexWithUV(tx2, aY + 1 - ty2, tz2, u2Flow, v2Flow);
282
+					tTesselator.addVertexWithUV(tx1, aY + 1 - ty1, tz1, u1Flow, v1Flow);
269 283
 
270
-					tessellator.addVertexWithUV(tx1, aY + 1 - 0, tz1, u1Flow, v3Flow);
271
-					tessellator.addVertexWithUV(tx1, aY + 1 - ty1, tz1, u1Flow, v1Flow);
272
-					tessellator.addVertexWithUV(tx2, aY + 1 - ty2, tz2, u2Flow, v2Flow);
273
-					tessellator.addVertexWithUV(tx2, aY + 1 - 0, tz2, u2Flow, v3Flow);
284
+					tTesselator.addVertexWithUV(tx1, aY + 1 -   0, tz1, u1Flow, v3Flow);
285
+					tTesselator.addVertexWithUV(tx1, aY + 1 - ty1, tz1, u1Flow, v1Flow);
286
+					tTesselator.addVertexWithUV(tx2, aY + 1 - ty2, tz2, u2Flow, v2Flow);
287
+					tTesselator.addVertexWithUV(tx2, aY + 1 -   0, tz2, u2Flow, v3Flow);
274 288
 				}
275 289
 			}
276 290
 		}

+ 2
- 1
src/main/java/gregtech/blocks/fluids/BlockWaterlike.java View File

@@ -182,7 +182,8 @@ public abstract class BlockWaterlike extends BlockFluidClassic implements IBlock
182 182
 		if (aBlock.getMaterial() == Material.water || WD.visOpq(aBlock)) return F;
183 183
 		if (aBlock.isAir(aWorld, aX, aY, aZ)) return T;
184 184
 		TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
185
-		return !(tTileEntity instanceof ITileEntitySurface && !((ITileEntitySurface)tTileEntity).isSurfaceOpaque(OPPOSITES[aSide]));
185
+		if (tTileEntity instanceof ITileEntitySurface) return !((ITileEntitySurface)tTileEntity).isSurfaceOpaque(OPPOSITES[aSide]);
186
+		return T;
186 187
 	}
187 188
 	
188 189
 	@Override public boolean isSourceBlock(IBlockAccess aWorld, int aX, int aY, int aZ) {return aWorld.getBlock(aX, aY, aZ) instanceof BlockWaterlike && aWorld.getBlockMetadata(aX, aY, aZ) == 0;}

Loading…
Cancel
Save