Skip to content

Commit b31ceb2

Browse files
committed
Refactor texture flipping logic
Moved texture group check to a utility function in `UT.java` to enhance readability and maintainability. Introduced a static `HashSet` in `CS.java` for texture groups that require flipping, replacing hardcoded strings.
1 parent 0eab107 commit b31ceb2

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
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: 2 additions & 2 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

@@ -292,8 +293,7 @@ public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRendere
292293
// double tMaxZ1 = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0);
293294
// double tMinZ1 = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0);
294295

295-
String textureGroup = aIcon.getIconName().substring(aIcon.getIconName().indexOf(":") + 1, aIcon.getIconName().indexOf("/"));
296-
boolean shouldFlipTexture = aChangedBlockBounds && (textureGroup.equals("machines") || textureGroup.equals("overlays")); // dirty hack, but works fine
296+
boolean shouldFlipTexture = shouldFlipNegYTextures(aIcon.getIconName(), aChangedBlockBounds);
297297

298298
double tMaxX1 = aIcon.getInterpolatedU(aRenderer.renderMaxX * 16.0);
299299
double tMinX1 = aIcon.getInterpolatedU(aRenderer.renderMinX * 16.0);

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)