| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.util.EnumMap;
|
| 4 | import java.util.Map;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.core.Direction;
|
| 8 | import net.minecraft.util.Util;
|
| 9 | import org.joml.Vector3f;
|
| 10 | import org.joml.Vector3fc;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public enum FaceInfo {
|
| 14 | DOWN(
|
| 15 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z),
|
| 16 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 17 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 18 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z)
|
| 19 | ),
|
| 20 | UP(
|
| 21 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z),
|
| 22 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z),
|
| 23 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z),
|
| 24 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z)
|
| 25 | ),
|
| 26 | NORTH(
|
| 27 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z),
|
| 28 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 29 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 30 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z)
|
| 31 | ),
|
| 32 | SOUTH(
|
| 33 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z),
|
| 34 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z),
|
| 35 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z),
|
| 36 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z)
|
| 37 | ),
|
| 38 | WEST(
|
| 39 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z),
|
| 40 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 41 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z),
|
| 42 | new FaceInfo.VertexInfo(FaceInfo.Extent.MIN_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z)
|
| 43 | ),
|
| 44 | EAST(
|
| 45 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MAX_Z),
|
| 46 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MAX_Z),
|
| 47 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MIN_Y, FaceInfo.Extent.MIN_Z),
|
| 48 | new FaceInfo.VertexInfo(FaceInfo.Extent.MAX_X, FaceInfo.Extent.MAX_Y, FaceInfo.Extent.MIN_Z)
|
| 49 | );
|
| 50 |
|
| 51 | private static final Map<Direction, FaceInfo> BY_FACING = Util.make(new EnumMap<>(Direction.class), map -> {
|
| 52 | map.put(Direction.DOWN, DOWN);
|
| 53 | map.put(Direction.UP, UP);
|
| 54 | map.put(Direction.NORTH, NORTH);
|
| 55 | map.put(Direction.SOUTH, SOUTH);
|
| 56 | map.put(Direction.WEST, WEST);
|
| 57 | map.put(Direction.EAST, EAST);
|
| 58 | });
|
| 59 | private final FaceInfo.VertexInfo[] infos;
|
| 60 |
|
| 61 | public static FaceInfo fromFacing(final Direction direction) {
|
| 62 | return BY_FACING.get(direction);
|
| 63 | }
|
| 64 |
|
| 65 | FaceInfo(final FaceInfo.VertexInfo... infos) {
|
| 66 | this.infos = infos;
|
| 67 | }
|
| 68 |
|
| 69 | public FaceInfo.VertexInfo getVertexInfo(final int index) {
|
| 70 | return this.infos[index];
|
| 71 | }
|
| 72 |
|
| 73 | @Environment(EnvType.CLIENT)
|
| 74 | public enum Extent {
|
| 75 | MIN_X,
|
| 76 | MIN_Y,
|
| 77 | MIN_Z,
|
| 78 | MAX_X,
|
| 79 | MAX_Y,
|
| 80 | MAX_Z;
|
| 81 |
|
| 82 | public float select(final Vector3fc min, final Vector3fc max) {
|
| 83 | return switch (this) {
|
| 84 | case MIN_X -> min.x();
|
| 85 | case MIN_Y -> min.y();
|
| 86 | case MIN_Z -> min.z();
|
| 87 | case MAX_X -> max.x();
|
| 88 | case MAX_Y -> max.y();
|
| 89 | case MAX_Z -> max.z();
|
| 90 | };
|
| 91 | }
|
| 92 |
|
| 93 | public float select(final float minX, final float minY, final float minZ, final float maxX, final float maxY, final float maxZ) {
|
| 94 | return switch (this) {
|
| 95 | case MIN_X -> minX;
|
| 96 | case MIN_Y -> minY;
|
| 97 | case MIN_Z -> minZ;
|
| 98 | case MAX_X -> maxX;
|
| 99 | case MAX_Y -> maxY;
|
| 100 | case MAX_Z -> maxZ;
|
| 101 | };
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | @Environment(EnvType.CLIENT)
|
| 106 | public record VertexInfo(FaceInfo.Extent xFace, FaceInfo.Extent yFace, FaceInfo.Extent zFace) {
|
| 107 | public Vector3f select(final Vector3fc min, final Vector3fc max) {
|
| 108 | return new Vector3f(this.xFace.select(min, max), this.yFace.select(min, max), this.zFace.select(min, max));
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 |
|