| 1 | package net.minecraft.client.model.object.chest;
|
| 2 |
|
| 3 | import java.util.Set;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.Model;
|
| 7 | import net.minecraft.client.model.geom.ModelPart;
|
| 8 | import net.minecraft.client.model.geom.PartPose;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 10 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 13 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 14 | import net.minecraft.core.Direction;
|
| 15 | import net.minecraft.util.Util;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class ChestModel extends Model<Float> {
|
| 19 | private static final String BOTTOM = "bottom";
|
| 20 | private static final String LID = "lid";
|
| 21 | private static final String LOCK = "lock";
|
| 22 | private final ModelPart lid;
|
| 23 | private final ModelPart lock;
|
| 24 |
|
| 25 | public ChestModel(final ModelPart root) {
|
| 26 | super(root, RenderTypes::entityCutoutCull);
|
| 27 | this.lid = root.getChild("lid");
|
| 28 | this.lock = root.getChild("lock");
|
| 29 | }
|
| 30 |
|
| 31 | public static LayerDefinition createSingleBodyLayer() {
|
| 32 | MeshDefinition mesh = new MeshDefinition();
|
| 33 | PartDefinition root = mesh.getRoot();
|
| 34 | root.addOrReplaceChild("bottom", CubeListBuilder.create().texOffs(0, 19).addBox(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F), PartPose.ZERO);
|
| 35 | root.addOrReplaceChild("lid", CubeListBuilder.create().texOffs(0, 0).addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F), PartPose.offset(0.0F, 9.0F, 1.0F));
|
| 36 | root.addOrReplaceChild("lock", CubeListBuilder.create().texOffs(0, 0).addBox(7.0F, -2.0F, 14.0F, 2.0F, 4.0F, 1.0F), PartPose.offset(0.0F, 9.0F, 1.0F));
|
| 37 | return LayerDefinition.create(mesh, 64, 64);
|
| 38 | }
|
| 39 |
|
| 40 | public static LayerDefinition createDoubleBodyRightLayer() {
|
| 41 | MeshDefinition mesh = new MeshDefinition();
|
| 42 | PartDefinition root = mesh.getRoot();
|
| 43 | Set<Direction> visibleFaces = Util.allOfEnumExcept(Direction.EAST);
|
| 44 | root.addOrReplaceChild("bottom", CubeListBuilder.create().texOffs(0, 19).addBox(1.0F, 0.0F, 1.0F, 15.0F, 10.0F, 14.0F, visibleFaces), PartPose.ZERO);
|
| 45 | root.addOrReplaceChild(
|
| 46 | "lid", CubeListBuilder.create().texOffs(0, 0).addBox(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, visibleFaces), PartPose.offset(0.0F, 9.0F, 1.0F)
|
| 47 | );
|
| 48 | root.addOrReplaceChild(
|
| 49 | "lock", CubeListBuilder.create().texOffs(0, 0).addBox(15.0F, -2.0F, 14.0F, 1.0F, 4.0F, 1.0F, visibleFaces), PartPose.offset(0.0F, 9.0F, 1.0F)
|
| 50 | );
|
| 51 | return LayerDefinition.create(mesh, 64, 64);
|
| 52 | }
|
| 53 |
|
| 54 | public static LayerDefinition createDoubleBodyLeftLayer() {
|
| 55 | MeshDefinition mesh = new MeshDefinition();
|
| 56 | PartDefinition root = mesh.getRoot();
|
| 57 | Set<Direction> visibleFaces = Util.allOfEnumExcept(Direction.WEST);
|
| 58 | root.addOrReplaceChild("bottom", CubeListBuilder.create().texOffs(0, 19).addBox(0.0F, 0.0F, 1.0F, 15.0F, 10.0F, 14.0F, visibleFaces), PartPose.ZERO);
|
| 59 | root.addOrReplaceChild(
|
| 60 | "lid", CubeListBuilder.create().texOffs(0, 0).addBox(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, visibleFaces), PartPose.offset(0.0F, 9.0F, 1.0F)
|
| 61 | );
|
| 62 | root.addOrReplaceChild(
|
| 63 | "lock", CubeListBuilder.create().texOffs(0, 0).addBox(0.0F, -2.0F, 14.0F, 1.0F, 4.0F, 1.0F, visibleFaces), PartPose.offset(0.0F, 9.0F, 1.0F)
|
| 64 | );
|
| 65 | return LayerDefinition.create(mesh, 64, 64);
|
| 66 | }
|
| 67 |
|
| 68 | public void setupAnim(final Float open) {
|
| 69 | super.setupAnim(open);
|
| 70 | this.lid.xRot = -(open * (float) (Math.PI / 2));
|
| 71 | this.lock.xRot = this.lid.xRot;
|
| 72 | }
|
| 73 | }
|
| 74 |
|