71 lines
2.6 KiB
Java
71 lines
2.6 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.joml.Matrix4f
|
|
* org.joml.Matrix4fc
|
|
*/
|
|
package net.minecraft.client.resources.model;
|
|
|
|
import com.mojang.math.OctahedralGroup;
|
|
import com.mojang.math.Transformation;
|
|
import java.util.EnumMap;
|
|
import java.util.Map;
|
|
import net.minecraft.client.resources.model.ModelState;
|
|
import net.minecraft.core.BlockMath;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.util.Util;
|
|
import org.joml.Matrix4f;
|
|
import org.joml.Matrix4fc;
|
|
|
|
public class BlockModelRotation
|
|
implements ModelState {
|
|
private static final Map<OctahedralGroup, BlockModelRotation> BY_GROUP_ORDINAL = Util.makeEnumMap(OctahedralGroup.class, BlockModelRotation::new);
|
|
public static final BlockModelRotation IDENTITY = BlockModelRotation.get(OctahedralGroup.IDENTITY);
|
|
private final Transformation transformation;
|
|
private final Map<Direction, Matrix4fc> faceMapping = new EnumMap<Direction, Matrix4fc>(Direction.class);
|
|
private final Map<Direction, Matrix4fc> inverseFaceMapping = new EnumMap<Direction, Matrix4fc>(Direction.class);
|
|
private final WithUvLock withUvLock = new WithUvLock(this);
|
|
|
|
private BlockModelRotation(OctahedralGroup actualRotation) {
|
|
this.transformation = actualRotation != OctahedralGroup.IDENTITY ? new Transformation((Matrix4fc)new Matrix4f(actualRotation.transformation())) : Transformation.identity();
|
|
for (Direction face : Direction.values()) {
|
|
Matrix4fc faceTransform = BlockMath.getFaceTransformation(this.transformation, face).getMatrix();
|
|
this.faceMapping.put(face, faceTransform);
|
|
this.inverseFaceMapping.put(face, (Matrix4fc)faceTransform.invertAffine(new Matrix4f()));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Transformation transformation() {
|
|
return this.transformation;
|
|
}
|
|
|
|
public static BlockModelRotation get(OctahedralGroup group) {
|
|
return BY_GROUP_ORDINAL.get(group);
|
|
}
|
|
|
|
public ModelState withUvLock() {
|
|
return this.withUvLock;
|
|
}
|
|
|
|
private record WithUvLock(BlockModelRotation parent) implements ModelState
|
|
{
|
|
@Override
|
|
public Transformation transformation() {
|
|
return this.parent.transformation;
|
|
}
|
|
|
|
@Override
|
|
public Matrix4fc faceTransformation(Direction face) {
|
|
return this.parent.faceMapping.getOrDefault(face, NO_TRANSFORM);
|
|
}
|
|
|
|
@Override
|
|
public Matrix4fc inverseFaceTransformation(Direction face) {
|
|
return this.parent.inverseFaceMapping.getOrDefault(face, NO_TRANSFORM);
|
|
}
|
|
}
|
|
}
|
|
|