| 1 | package net.minecraft.client.resources.model;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import net.minecraft.util.EnumFacing;
|
| 6 | import net.minecraft.util.MathHelper;
|
| 7 | import org.lwjgl.util.vector.Matrix4f;
|
| 8 | import org.lwjgl.util.vector.Vector3f;
|
| 9 |
|
| 10 | public enum ModelRotation
|
| 11 | {
|
| 12 | X0_Y0(0, 0),
|
| 13 | X0_Y90(0, 90),
|
| 14 | X0_Y180(0, 180),
|
| 15 | X0_Y270(0, 270),
|
| 16 | X90_Y0(90, 0),
|
| 17 | X90_Y90(90, 90),
|
| 18 | X90_Y180(90, 180),
|
| 19 | X90_Y270(90, 270),
|
| 20 | X180_Y0(180, 0),
|
| 21 | X180_Y90(180, 90),
|
| 22 | X180_Y180(180, 180),
|
| 23 | X180_Y270(180, 270),
|
| 24 | X270_Y0(270, 0),
|
| 25 | X270_Y90(270, 90),
|
| 26 | X270_Y180(270, 180),
|
| 27 | X270_Y270(270, 270);
|
| 28 |
|
| 29 | private static final Map<Integer, ModelRotation> mapRotations = Maps.<Integer, ModelRotation>newHashMap();
|
| 30 | private final int combinedXY;
|
| 31 | private final Matrix4f matrix4d;
|
| 32 | private final int quartersX;
|
| 33 | private final int quartersY;
|
| 34 |
|
| 35 | private static int combineXY(int p_177521_0_, int p_177521_1_)
|
| 36 | {
|
| 37 | return p_177521_0_ * 360 + p_177521_1_;
|
| 38 | }
|
| 39 |
|
| 40 | private ModelRotation(int p_i46087_3_, int p_i46087_4_)
|
| 41 | {
|
| 42 | this.combinedXY = combineXY(p_i46087_3_, p_i46087_4_);
|
| 43 | this.matrix4d = new Matrix4f();
|
| 44 | Matrix4f matrix4f = new Matrix4f();
|
| 45 | matrix4f.setIdentity();
|
| 46 | Matrix4f.rotate((float)(-p_i46087_3_) * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), matrix4f, matrix4f);
|
| 47 | this.quartersX = MathHelper.abs_int(p_i46087_3_ / 90);
|
| 48 | Matrix4f matrix4f1 = new Matrix4f();
|
| 49 | matrix4f1.setIdentity();
|
| 50 | Matrix4f.rotate((float)(-p_i46087_4_) * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), matrix4f1, matrix4f1);
|
| 51 | this.quartersY = MathHelper.abs_int(p_i46087_4_ / 90);
|
| 52 | Matrix4f.mul(matrix4f1, matrix4f, this.matrix4d);
|
| 53 | }
|
| 54 |
|
| 55 | public Matrix4f getMatrix4d()
|
| 56 | {
|
| 57 | return this.matrix4d;
|
| 58 | }
|
| 59 |
|
| 60 | public EnumFacing rotateFace(EnumFacing p_177523_1_)
|
| 61 | {
|
| 62 | EnumFacing enumfacing = p_177523_1_;
|
| 63 |
|
| 64 | for (int i = 0; i < this.quartersX; ++i)
|
| 65 | {
|
| 66 | enumfacing = enumfacing.rotateAround(EnumFacing.Axis.X);
|
| 67 | }
|
| 68 |
|
| 69 | if (enumfacing.getAxis() != EnumFacing.Axis.Y)
|
| 70 | {
|
| 71 | for (int j = 0; j < this.quartersY; ++j)
|
| 72 | {
|
| 73 | enumfacing = enumfacing.rotateAround(EnumFacing.Axis.Y);
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | return enumfacing;
|
| 78 | }
|
| 79 |
|
| 80 | public int rotateVertex(EnumFacing facing, int vertexIndex)
|
| 81 | {
|
| 82 | int i = vertexIndex;
|
| 83 |
|
| 84 | if (facing.getAxis() == EnumFacing.Axis.X)
|
| 85 | {
|
| 86 | i = (vertexIndex + this.quartersX) % 4;
|
| 87 | }
|
| 88 |
|
| 89 | EnumFacing enumfacing = facing;
|
| 90 |
|
| 91 | for (int j = 0; j < this.quartersX; ++j)
|
| 92 | {
|
| 93 | enumfacing = enumfacing.rotateAround(EnumFacing.Axis.X);
|
| 94 | }
|
| 95 |
|
| 96 | if (enumfacing.getAxis() == EnumFacing.Axis.Y)
|
| 97 | {
|
| 98 | i = (i + this.quartersY) % 4;
|
| 99 | }
|
| 100 |
|
| 101 | return i;
|
| 102 | }
|
| 103 |
|
| 104 | public static ModelRotation getModelRotation(int p_177524_0_, int p_177524_1_)
|
| 105 | {
|
| 106 | return (ModelRotation)mapRotations.get(Integer.valueOf(combineXY(MathHelper.normalizeAngle(p_177524_0_, 360), MathHelper.normalizeAngle(p_177524_1_, 360))));
|
| 107 | }
|
| 108 |
|
| 109 | static {
|
| 110 | for (ModelRotation modelrotation : values())
|
| 111 | {
|
| 112 | mapRotations.put(Integer.valueOf(modelrotation.combinedXY), modelrotation);
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|