CuboidModelElement.java
net.minecraft.client.resources.model.cuboid.CuboidModelElement
信息
- 全限定名:net.minecraft.client.resources.model.cuboid.CuboidModelElement
- 类型:public record
- 包:net.minecraft.client.resources.model.cuboid
- 源码路径:src/main/java/net/minecraft/client/resources/model/cuboid/CuboidModelElement.java
- 起始行号:L23
- 职责:
TODO
字段/常量
-
DEFAULT_RESCALE- 类型:
boolean - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
MIN_EXTENT- 类型:
float - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
MAX_EXTENT- 类型:
float - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.resources.model.cuboid.CuboidModelElement.Deserializer- 类型:
class - 修饰符:
protected static - 源码定位:
L35 - 说明:
TODO
- 类型:
构造器
public CuboidModelElement(Vector3fc from, Vector3fc to, Map<Direction,CuboidFace> faces) @ L30
- 构造器名:CuboidModelElement
- 源码定位:L30
- 修饰符:public
参数:
- from: Vector3fc
- to: Vector3fc
- faces: Map<Direction,CuboidFace>
说明:
TODO
方法
下面的方法块按源码顺序生成。
- 无
代码
@OnlyIn(Dist.CLIENT)
public record CuboidModelElement(
Vector3fc from, Vector3fc to, Map<Direction, CuboidFace> faces, @Nullable CuboidRotation rotation, boolean shade, int lightEmission
) {
private static final boolean DEFAULT_RESCALE = false;
private static final float MIN_EXTENT = -16.0F;
private static final float MAX_EXTENT = 32.0F;
public CuboidModelElement(Vector3fc from, Vector3fc to, Map<Direction, CuboidFace> faces) {
this(from, to, faces, null, true, 0);
}
@OnlyIn(Dist.CLIENT)
protected static class Deserializer implements JsonDeserializer<CuboidModelElement> {
private static final boolean DEFAULT_SHADE = true;
private static final int DEFAULT_LIGHT_EMISSION = 0;
private static final String FIELD_SHADE = "shade";
private static final String FIELD_LIGHT_EMISSION = "light_emission";
private static final String FIELD_ROTATION = "rotation";
private static final String FIELD_ORIGIN = "origin";
private static final String FIELD_ANGLE = "angle";
private static final String FIELD_X = "x";
private static final String FIELD_Y = "y";
private static final String FIELD_Z = "z";
private static final String FIELD_AXIS = "axis";
private static final String FIELD_RESCALE = "rescale";
private static final String FIELD_FACES = "faces";
private static final String FIELD_TO = "to";
private static final String FIELD_FROM = "from";
public CuboidModelElement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject object = json.getAsJsonObject();
Vector3f from = getPosition(object, "from");
Vector3f to = getPosition(object, "to");
CuboidRotation rotation = this.getRotation(object);
Map<Direction, CuboidFace> faces = this.getFaces(context, object);
if (object.has("shade") && !GsonHelper.isBooleanValue(object, "shade")) {
throw new JsonParseException("Expected 'shade' to be a Boolean");
} else {
boolean shade = GsonHelper.getAsBoolean(object, "shade", true);
int lightEmission = 0;
if (object.has("light_emission")) {
boolean isNumber = GsonHelper.isNumberValue(object, "light_emission");
if (isNumber) {
lightEmission = GsonHelper.getAsInt(object, "light_emission");
}
if (!isNumber || lightEmission < 0 || lightEmission > 15) {
throw new JsonParseException("Expected 'light_emission' to be an Integer between (inclusive) 0 and 15");
}
}
return new CuboidModelElement(from, to, faces, rotation, shade, lightEmission);
}
}
private @Nullable CuboidRotation getRotation(JsonObject object) {
if (!object.has("rotation")) {
return null;
} else {
JsonObject rotationObject = GsonHelper.getAsJsonObject(object, "rotation");
Vector3f origin = getVector3f(rotationObject, "origin");
origin.mul(0.0625F);
CuboidRotation.RotationValue rotationValue;
if (!rotationObject.has("axis") && !rotationObject.has("angle")) {
if (!rotationObject.has("x") && !rotationObject.has("y") && !rotationObject.has("z")) {
throw new JsonParseException("Missing rotation value, expected either 'axis' and 'angle' or 'x', 'y' and 'z'");
}
float x = GsonHelper.getAsFloat(rotationObject, "x", 0.0F);
float y = GsonHelper.getAsFloat(rotationObject, "y", 0.0F);
float z = GsonHelper.getAsFloat(rotationObject, "z", 0.0F);
rotationValue = new CuboidRotation.EulerXYZRotation(x, y, z);
} else {
Direction.Axis axis = this.getAxis(rotationObject);
float angle = GsonHelper.getAsFloat(rotationObject, "angle");
rotationValue = new CuboidRotation.SingleAxisRotation(axis, angle);
}
boolean rescale = GsonHelper.getAsBoolean(rotationObject, "rescale", false);
return new CuboidRotation(origin, rotationValue, rescale);
}
}
private Direction.Axis getAxis(JsonObject object) {
String axisName = GsonHelper.getAsString(object, "axis");
Direction.Axis axis = Direction.Axis.byName(axisName.toLowerCase(Locale.ROOT));
if (axis == null) {
throw new JsonParseException("Invalid rotation axis: " + axisName);
} else {
return axis;
}
}
private Map<Direction, CuboidFace> getFaces(JsonDeserializationContext context, JsonObject object) {
Map<Direction, CuboidFace> faces = this.filterNullFromFaces(context, object);
if (faces.isEmpty()) {
throw new JsonParseException("Expected between 1 and 6 unique faces, got 0");
} else {
return faces;
}
}
private Map<Direction, CuboidFace> filterNullFromFaces(JsonDeserializationContext context, JsonObject object) {
Map<Direction, CuboidFace> result = Maps.newEnumMap(Direction.class);
JsonObject faceObjects = GsonHelper.getAsJsonObject(object, "faces");
for (Entry<String, JsonElement> entry : faceObjects.entrySet()) {
Direction direction = this.getFacing(entry.getKey());
result.put(direction, context.deserialize(entry.getValue(), CuboidFace.class));
}
return result;
}
private Direction getFacing(String name) {
Direction direction = Direction.byName(name);
if (direction == null) {
throw new JsonParseException("Unknown facing: " + name);
} else {
return direction;
}
}
private static Vector3f getPosition(JsonObject object, String key) {
Vector3f from = getVector3f(object, key);
if (!(from.x() < -16.0F) && !(from.y() < -16.0F) && !(from.z() < -16.0F) && !(from.x() > 32.0F) && !(from.y() > 32.0F) && !(from.z() > 32.0F)) {
return from;
} else {
throw new JsonParseException("'" + key + "' specifier exceeds the allowed boundaries: " + from);
}
}
private static Vector3f getVector3f(JsonObject object, String key) {
JsonArray vecArray = GsonHelper.getAsJsonArray(object, key);
if (vecArray.size() != 3) {
throw new JsonParseException("Expected 3 " + key + " values, found: " + vecArray.size());
} else {
float[] elements = new float[3];
for (int i = 0; i < elements.length; i++) {
elements[i] = GsonHelper.convertToFloat(vecArray.get(i), key + "[" + i + "]");
}
return new Vector3f(elements[0], elements[1], elements[2]);
}
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
CuboidRotation(), CuboidRotation.EulerXYZRotation(), CuboidRotation.SingleAxisRotation(), EulerXYZRotation(), SingleAxisRotation()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Direction.Axis.byName(), Direction.byName()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GsonHelper.convertToFloat(), GsonHelper.getAsBoolean(), GsonHelper.getAsFloat(), GsonHelper.getAsInt(), GsonHelper.getAsJsonArray(), GsonHelper.getAsJsonObject(), GsonHelper.getAsString(), GsonHelper.isBooleanValue(), GsonHelper.isNumberValue()
- 引用位置: