| 1 | package net.minecraft.client.renderer.block.model;
|
| 2 |
|
| 3 | import com.google.gson.JsonArray;
|
| 4 | import com.google.gson.JsonDeserializationContext;
|
| 5 | import com.google.gson.JsonDeserializer;
|
| 6 | import com.google.gson.JsonElement;
|
| 7 | import com.google.gson.JsonObject;
|
| 8 | import com.google.gson.JsonParseException;
|
| 9 | import java.lang.reflect.Type;
|
| 10 | import net.minecraft.util.JsonUtils;
|
| 11 | import net.minecraft.util.MathHelper;
|
| 12 | import org.lwjgl.util.vector.Vector3f;
|
| 13 |
|
| 14 | public class ItemTransformVec3f
|
| 15 | {
|
| 16 | public static final ItemTransformVec3f DEFAULT = new ItemTransformVec3f(new Vector3f(), new Vector3f(), new Vector3f(1.0F, 1.0F, 1.0F));
|
| 17 | public final Vector3f rotation;
|
| 18 | public final Vector3f translation;
|
| 19 | public final Vector3f scale;
|
| 20 |
|
| 21 | public ItemTransformVec3f(Vector3f rotation, Vector3f translation, Vector3f scale)
|
| 22 | {
|
| 23 | this.rotation = new Vector3f(rotation);
|
| 24 | this.translation = new Vector3f(translation);
|
| 25 | this.scale = new Vector3f(scale);
|
| 26 | }
|
| 27 |
|
| 28 | public boolean equals(Object p_equals_1_)
|
| 29 | {
|
| 30 | if (this == p_equals_1_)
|
| 31 | {
|
| 32 | return true;
|
| 33 | }
|
| 34 | else if (this.getClass() != p_equals_1_.getClass())
|
| 35 | {
|
| 36 | return false;
|
| 37 | }
|
| 38 | else
|
| 39 | {
|
| 40 | ItemTransformVec3f itemtransformvec3f = (ItemTransformVec3f)p_equals_1_;
|
| 41 | return !this.rotation.equals(itemtransformvec3f.rotation) ? false : (!this.scale.equals(itemtransformvec3f.scale) ? false : this.translation.equals(itemtransformvec3f.translation));
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | public int hashCode()
|
| 46 | {
|
| 47 | int i = this.rotation.hashCode();
|
| 48 | i = 31 * i + this.translation.hashCode();
|
| 49 | i = 31 * i + this.scale.hashCode();
|
| 50 | return i;
|
| 51 | }
|
| 52 |
|
| 53 | static class Deserializer implements JsonDeserializer<ItemTransformVec3f>
|
| 54 | {
|
| 55 | private static final Vector3f ROTATION_DEFAULT = new Vector3f(0.0F, 0.0F, 0.0F);
|
| 56 | private static final Vector3f TRANSLATION_DEFAULT = new Vector3f(0.0F, 0.0F, 0.0F);
|
| 57 | private static final Vector3f SCALE_DEFAULT = new Vector3f(1.0F, 1.0F, 1.0F);
|
| 58 |
|
| 59 | public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 60 | {
|
| 61 | JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
|
| 62 | Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT);
|
| 63 | Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT);
|
| 64 | vector3f1.scale(0.0625F);
|
| 65 | vector3f1.x = MathHelper.clamp_float(vector3f1.x, -1.5F, 1.5F);
|
| 66 | vector3f1.y = MathHelper.clamp_float(vector3f1.y, -1.5F, 1.5F);
|
| 67 | vector3f1.z = MathHelper.clamp_float(vector3f1.z, -1.5F, 1.5F);
|
| 68 | Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT);
|
| 69 | vector3f2.x = MathHelper.clamp_float(vector3f2.x, -4.0F, 4.0F);
|
| 70 | vector3f2.y = MathHelper.clamp_float(vector3f2.y, -4.0F, 4.0F);
|
| 71 | vector3f2.z = MathHelper.clamp_float(vector3f2.z, -4.0F, 4.0F);
|
| 72 | return new ItemTransformVec3f(vector3f, vector3f1, vector3f2);
|
| 73 | }
|
| 74 |
|
| 75 | private Vector3f parseVector3f(JsonObject jsonObject, String key, Vector3f defaultValue)
|
| 76 | {
|
| 77 | if (!jsonObject.has(key))
|
| 78 | {
|
| 79 | return defaultValue;
|
| 80 | }
|
| 81 | else
|
| 82 | {
|
| 83 | JsonArray jsonarray = JsonUtils.getJsonArray(jsonObject, key);
|
| 84 |
|
| 85 | if (jsonarray.size() != 3)
|
| 86 | {
|
| 87 | throw new JsonParseException("Expected 3 " + key + " values, found: " + jsonarray.size());
|
| 88 | }
|
| 89 | else
|
| 90 | {
|
| 91 | float[] afloat = new float[3];
|
| 92 |
|
| 93 | for (int i = 0; i < afloat.length; ++i)
|
| 94 | {
|
| 95 | afloat[i] = JsonUtils.getFloat(jsonarray.get(i), key + "[" + i + "]");
|
| 96 | }
|
| 97 |
|
| 98 | return new Vector3f(afloat[0], afloat[1], afloat[2]);
|
| 99 | }
|
| 100 | }
|
| 101 | }
|
| 102 | }
|
| 103 | }
|
| 104 |
|