| 10 | import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; |
| 11 | |
| 12 | public class ClientTools { |
| 13 | |
| 14 | private static void putVertex(BakedQuadBuilder builder, Vector3f normal, Vector4f vector, |
| 15 | float u, float v, TextureAtlasSprite sprite) { |
| 16 | |
| 17 | var elements = builder.getVertexFormat().getElements().asList(); |
| 18 | for (int j = 0 ; j < elements.size() ; j++) { |
| 19 | var e = elements.get(j); |
| 20 | switch (e.getUsage()) { |
| 21 | case POSITION -> builder.put(j, vector.x(), vector.y(), vector.z(), 1.0f); |
| 22 | case COLOR -> builder.put(j, 1.0f, 1.0f, 1.0f, 1.0f); |
| 23 | case UV -> putVertexUV(builder, u, v, sprite, j, e); |
| 24 | case NORMAL -> builder.put(j, normal.x(), normal.y(), normal.z()); |
| 25 | default -> builder.put(j); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | private static void putVertexUV(BakedQuadBuilder builder, float u, float v, TextureAtlasSprite sprite, int j, VertexFormatElement e) { |
| 31 | switch (e.getIndex()) { |
| 32 | case 0 -> builder.put(j, sprite.getU(u), sprite.getV(v)); |
| 33 | case 2 -> builder.put(j, (short) 0, (short) 0); |
| 34 | default -> builder.put(j); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public static BakedQuad createQuad(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f v4, Transformation rotation, TextureAtlasSprite sprite) { |
| 39 | Vector3f normal = v3.copy(); |
| 40 | normal.sub(v2); |
| 41 | Vector3f temp = v1.copy(); |
| 42 | temp.sub(v2); |
| 43 | normal.cross(temp); |
| 44 | normal.normalize(); |
| 45 | |
| 46 | int tw = sprite.getWidth(); |
| 47 | int th = sprite.getHeight(); |
| 48 | |
| 49 | rotation = rotation.blockCenterToCorner(); |
| 50 | rotation.transformNormal(normal); |
| 51 | |
| 52 | Vector4f vv1 = new Vector4f(v1); rotation.transformPosition(vv1); |
| 53 | Vector4f vv2 = new Vector4f(v2); rotation.transformPosition(vv2); |
| 54 | Vector4f vv3 = new Vector4f(v3); rotation.transformPosition(vv3); |
| 55 | Vector4f vv4 = new Vector4f(v4); rotation.transformPosition(vv4); |
| 56 | |
| 57 | var builder = new BakedQuadBuilder(sprite); |
| 58 | builder.setQuadOrientation(Direction.getNearest(normal.x(), normal.y(), normal.z())); |
| 59 | putVertex(builder, normal, vv1, 0, 0, sprite); |
| 60 | putVertex(builder, normal, vv2, 0, th, sprite); |
| 61 | putVertex(builder, normal, vv3, tw, th, sprite); |
| 62 | putVertex(builder, normal, vv4, tw, 0, sprite); |
| 63 | return builder.build(); |
| 64 | } |
| 65 | |
| 66 | public static Vector3f v(float x, float y, float z) { |
| 67 | return new Vector3f(x, y, z); |
| 68 | } |
| 69 | } |
nothing calls this directly
no outgoing calls
no test coverage detected