| 1 | package net.minecraft.client.model.effects;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.EntityModel;
|
| 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.entity.state.AvatarRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class SpinAttackEffectModel extends EntityModel<AvatarRenderState> {
|
| 17 | private static final int BOX_COUNT = 2;
|
| 18 | private final ModelPart[] boxes = new ModelPart[2];
|
| 19 |
|
| 20 | public SpinAttackEffectModel(final ModelPart root) {
|
| 21 | super(root);
|
| 22 |
|
| 23 | for (int i = 0; i < 2; i++) {
|
| 24 | this.boxes[i] = root.getChild(boxName(i));
|
| 25 | }
|
| 26 | }
|
| 27 |
|
| 28 | private static String boxName(final int i) {
|
| 29 | return "box" + i;
|
| 30 | }
|
| 31 |
|
| 32 | public static LayerDefinition createLayer() {
|
| 33 | MeshDefinition mesh = new MeshDefinition();
|
| 34 | PartDefinition root = mesh.getRoot();
|
| 35 |
|
| 36 | for (int i = 0; i < 2; i++) {
|
| 37 | float yOffset = -3.2F + 9.6F * (i + 1);
|
| 38 | float scale = 0.75F * (i + 1);
|
| 39 | root.addOrReplaceChild(
|
| 40 | boxName(i), CubeListBuilder.create().texOffs(0, 0).addBox(-8.0F, -16.0F + yOffset, -8.0F, 16.0F, 32.0F, 16.0F), PartPose.ZERO.withScale(scale)
|
| 41 | );
|
| 42 | }
|
| 43 |
|
| 44 | return LayerDefinition.create(mesh, 64, 64);
|
| 45 | }
|
| 46 |
|
| 47 | public void setupAnim(final AvatarRenderState state) {
|
| 48 | super.setupAnim(state);
|
| 49 |
|
| 50 | for (int i = 0; i < this.boxes.length; i++) {
|
| 51 | float angle = state.ageInTicks * -(45 + (i + 1) * 5);
|
| 52 | this.boxes[i].yRot = Mth.wrapDegrees(angle) * (float) (Math.PI / 180.0);
|
| 53 | }
|
| 54 | }
|
| 55 | }
|
| 56 |
|