Skip to content

Commit 57cdda8

Browse files
committed
Add texture flipping support for negative Y faces
Introduced a utility method to determine if textures need flipping based on texture groups and block bounds. Updated rendering functions to use this logic, ensuring correct texture orientation for specific cases. Corrected UV coordinates for the negative y face rendering. These changes ensure proper texture alignment for bottom sides when using ambient occlusion (AO) and regular rendering.
1 parent 01dcf1b commit 57cdda8

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/main/java/gregapi/data/CS.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,4 +2326,11 @@ public static class SFX {
23262326

23272327
, RES_PATH_IC2 = MD.IC2.mID.toLowerCase() + ":"
23282328
;
2329+
2330+
public static final HashSet<String> SHOULD_FLIP_NEG_Y_TEXTURES = new HashSet<>();
2331+
2332+
static {
2333+
SHOULD_FLIP_NEG_Y_TEXTURES.add("machines");
2334+
SHOULD_FLIP_NEG_Y_TEXTURES.add("overlays");
2335+
}
23292336
}

src/main/java/gregapi/render/ITexture.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package gregapi.render;
2121

2222
import static gregapi.data.CS.*;
23+
import static gregapi.util.UT.shouldFlipNegYTextures;
2324

2425
import org.lwjgl.opengl.GL11;
2526

@@ -248,11 +249,11 @@ public static boolean doRenderYNeg(IIcon aIcon, RenderBlocks aRenderer, Block aB
248249
if (aBlock.getRenderBlockPass() > 0) {
249250
double tOldValue = aRenderer.renderMinY;
250251
aRenderer.renderMinY -= (aRenderer.renderFromInside?-1:+1)*OFFSET_Y_NEG;
251-
renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ);
252+
renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ, aChangedBlockBounds);
252253
aRenderer.renderMinY = tOldValue;
253254
OFFSET_Y_NEG += OFFSET_ADD;
254255
} else {
255-
renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ);
256+
renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ, aChangedBlockBounds);
256257
}
257258
return T;
258259
}
@@ -285,13 +286,15 @@ public static boolean doRenderZNeg(IIcon aIcon, RenderBlocks aRenderer, Block aB
285286
return T;
286287
}
287288

288-
public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
289+
public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, boolean aChangedBlockBounds) {
289290
if (aRenderer.hasOverrideBlockTexture()) aIcon = aRenderer.overrideBlockTexture;
290291
// double tMaxX1 = aIcon.getInterpolatedU(aRenderer.renderMaxX * 16.0);
291292
// double tMinX1 = aIcon.getInterpolatedU(aRenderer.renderMinX * 16.0);
292293
// double tMaxZ1 = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0);
293294
// double tMinZ1 = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0);
294-
295+
296+
boolean shouldFlipTexture = shouldFlipNegYTextures(aIcon.getIconName(), aChangedBlockBounds);
297+
295298
double tMaxX1 = aIcon.getInterpolatedU(aRenderer.renderMaxX * 16.0);
296299
double tMinX1 = aIcon.getInterpolatedU(aRenderer.renderMinX * 16.0);
297300
double tMaxZ1 = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0);
@@ -358,21 +361,21 @@ public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRendere
358361
if (aRenderer.enableAO) {
359362
Tessellator.instance.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft);
360363
Tessellator.instance.setBrightness(aRenderer.brightnessTopLeft);
361-
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, tMinZ2);
364+
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, shouldFlipTexture ? tMinZ2 : tMaxZ2);
362365
Tessellator.instance.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft);
363366
Tessellator.instance.setBrightness(aRenderer.brightnessBottomLeft);
364-
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, tMaxZ1);
367+
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, shouldFlipTexture ? tMaxZ1 : tMinZ1);
365368
Tessellator.instance.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight);
366369
Tessellator.instance.setBrightness(aRenderer.brightnessBottomRight);
367-
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, tMaxZ2);
370+
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, shouldFlipTexture ? tMaxZ2 : tMinZ2);
368371
Tessellator.instance.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight);
369372
Tessellator.instance.setBrightness(aRenderer.brightnessTopRight);
370-
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, tMinZ1);
373+
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, shouldFlipTexture ? tMinZ1 : tMaxZ1);
371374
} else {
372-
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, tMinZ2);
373-
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, tMaxZ1);
374-
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, tMaxZ2);
375-
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, tMinZ1);
375+
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, shouldFlipTexture ? tMinZ2 : tMaxZ2);
376+
Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, shouldFlipTexture ? tMaxZ1 : tMinZ1);
377+
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, shouldFlipTexture ? tMaxZ2 : tMinZ2);
378+
Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, shouldFlipTexture ? tMinZ1 : tMaxZ1);
376379
}
377380
}
378381

src/main/java/gregapi/util/UT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,4 +3568,14 @@ public static boolean finish() {
35683568
return F;
35693569
}
35703570
}
3571+
3572+
public static boolean shouldFlipNegYTextures(String textureName, boolean aChangedBlockBounds){
3573+
int start = textureName.indexOf(":");
3574+
int stop = textureName.indexOf("/");
3575+
if (start != -1 && stop != -1) {
3576+
String textureGroup = textureName.substring(start + 1, stop);
3577+
return aChangedBlockBounds && (SHOULD_FLIP_NEG_Y_TEXTURES.contains(textureGroup)); // dirty hack, but works fine
3578+
}
3579+
return false;
3580+
}
35713581
}

0 commit comments

Comments
 (0)