| 1 | package net.minecraft.client.model.object.bell;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.Model;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 9 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 13 | import net.minecraft.core.Direction;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 | import org.jspecify.annotations.Nullable;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class BellModel extends Model<BellModel.State> {
|
| 19 | private static final String BELL_BODY = "bell_body";
|
| 20 | private final ModelPart bellBody;
|
| 21 |
|
| 22 | public BellModel(final ModelPart root) {
|
| 23 | super(root, RenderTypes::entitySolid);
|
| 24 | this.bellBody = root.getChild("bell_body");
|
| 25 | }
|
| 26 |
|
| 27 | public static LayerDefinition createBodyLayer() {
|
| 28 | MeshDefinition mesh = new MeshDefinition();
|
| 29 | PartDefinition root = mesh.getRoot();
|
| 30 | PartDefinition bellBody = root.addOrReplaceChild(
|
| 31 | "bell_body", CubeListBuilder.create().texOffs(0, 0).addBox(-3.0F, -6.0F, -3.0F, 6.0F, 7.0F, 6.0F), PartPose.offset(8.0F, 12.0F, 8.0F)
|
| 32 | );
|
| 33 | bellBody.addOrReplaceChild(
|
| 34 | "bell_base", CubeListBuilder.create().texOffs(0, 13).addBox(4.0F, 4.0F, 4.0F, 8.0F, 2.0F, 8.0F), PartPose.offset(-8.0F, -12.0F, -8.0F)
|
| 35 | );
|
| 36 | return LayerDefinition.create(mesh, 32, 32);
|
| 37 | }
|
| 38 |
|
| 39 | public void setupAnim(final BellModel.State state) {
|
| 40 | super.setupAnim(state);
|
| 41 | float xRot = 0.0F;
|
| 42 | float zRot = 0.0F;
|
| 43 | if (state.shakeDirection != null) {
|
| 44 | float baseRot = Mth.sin(state.ticks / (float) Math.PI) / (4.0F + state.ticks / 3.0F);
|
| 45 | switch (state.shakeDirection) {
|
| 46 | case NORTH:
|
| 47 | xRot = -baseRot;
|
| 48 | break;
|
| 49 | case SOUTH:
|
| 50 | xRot = baseRot;
|
| 51 | break;
|
| 52 | case EAST:
|
| 53 | zRot = -baseRot;
|
| 54 | break;
|
| 55 | case WEST:
|
| 56 | zRot = baseRot;
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | this.bellBody.xRot = xRot;
|
| 61 | this.bellBody.zRot = zRot;
|
| 62 | }
|
| 63 |
|
| 64 | @Environment(EnvType.CLIENT)
|
| 65 | public record State(float ticks, @Nullable Direction shakeDirection) {
|
| 66 | }
|
| 67 | }
|
| 68 |
|