@Override public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float…
- User
@Override public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch, ageInTicks);
this.animateWalk(ModAnimationDefinitions.PENGUIN_WALK, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(((PenguinEntity) entity).idleAnimationState, ModAnimationDefinitions.PENGUIN_IDLE, ageInTicks, 1f); } private void applyHeadRotation(float pNetHeadYaw, float pHeadPitch, float pAgeInTicks) { pNetHeadYaw = Mth.clamp(pNetHeadYaw, -30.0F, 30.0F); pHeadPitch = Mth.clamp(pHeadPitch, -25.0F, 45.0F); this.head.yRot = pNetHeadYaw * ((float)Math.PI / 180F); this.head.xRot = pHeadPitch * ((float)Math.PI / 180F); } @Override public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { penguin.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); baby.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); } @Override public ModelPart root() { return penguin; }Can you add down here the swim animation it's PENGUIN_SWIM same location as idle and walk
And this is what I have in PenguinEntity
package net.mattias.oceancritteria.entity.custom;
import net.mattias.oceancritteria.entity.ModEntities; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.goal.; import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable;
public class PenguinEntity extends Animal { public PenguinEntity(EntityType<? extends Animal> pEntityType, Level pLevel) { super(pEntityType, pLevel); }
public final AnimationState idleAnimationState = new AnimationState(); private int idleAnimationTimeout = 0; @Override public void tick() { super.tick(); if(this.level().isClientSide()) { setupAnimationStates(); } } private void setupAnimationStates() { if(this.idleAnimationTimeout <= 0) { this.idleAnimationTimeout = this.random.nextInt(40) + 80; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } } @Override protected void updateWalkAnimation(float pPartialTick) { float f; if(this.getPose() == Pose.STANDING) { f = Math.min(pPartialTick * 6F, 1f); } else { f = 0f; } this.walkAnimation.update(f, 0.2f); } @Override protected void registerGoals() { this.goalSelector.addGoal(0, new FloatGoal(this)); // Ensure they float in water this.goalSelector.addGoal(1, new PanicGoal(this, 1.5D)); // Flee when hurt (priority 1) this.goalSelector.addGoal(2, new BreedGoal(this, 1.15D)); this.goalSelector.addGoal(3, new TemptGoal(this, 1.2D, Ingredient.of(Items.COD, Items.SALMON, Items.COOKED_SALMON, Items.COOKED_COD), false)); this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D)); this.goalSelector.addGoal(5, new RandomSwimmingGoal(this, 1.0D, 80)); // Swim in water this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 1.0D)); // Stroll on land this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 3f)); this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); } public static AttributeSupplier.Builder createAttributes() { return Animal.createLivingAttributes() .add(Attributes.MAX_HEALTH, 10D) .add(Attributes.MOVEMENT_SPEED, 0.15D) .add(Attributes.FOLLOW_RANGE, 24D); } @Override public void travel(Vec3 pTravelVector) { if (this.isEffectiveAi() && this.isInWater()) { this.moveRelative(0.1F, pTravelVector); this.move(MoverType.SELF, this.getDeltaMovement()); this.setDeltaMovement(this.getDeltaMovement().scale(0.9D)); } else { super.travel(pTravelVector); } } @Nullable @Override public AgeableMob getBreedOffspring(ServerLevel pLevel, AgeableMob pOtherParent) { return ModEntities.PENGUIN.get().create(pLevel); } @Override public boolean isFood(ItemStack pStack) { return pStack.is(Items.COD) || pStack.is(Items.SALMON) || pStack.is(Items.COOKED_COD) || pStack.is(Items.COOKED_SALMON); } @Nullable @Override protected SoundEvent getAmbientSound() { return SoundEvents.DOLPHIN_AMBIENT; } @Nullable @Override protected SoundEvent getHurtSound(DamageSource pDamageSource) { return SoundEvents.DOLPHIN_HURT; } @Nullable @Override protected SoundEvent getDeathSound() { return SoundEvents.DOLPHIN_DEATH; }}
Assistant
Looking at your code, I see you need to add the swim animation to both the model and the entity. Here's what needs to be updated:
1. Update PenguinEntity - Add the swim animation state:
public class PenguinEntity extends Animal { public PenguinEntity(EntityType<? extends Animal> pEntityType, Level pLevel) { super(pEntityType, pLevel); } public final AnimationState idleAnimationState = new AnimationState(); public final AnimationState swimAnimationState = new AnimationState(); // Add this private int idleAnimationTimeout = 0; @Override public void tick() { super.tick(); if(this.level().isClientSide()) { setupAnimationStates(); } } private void setupAnimationStates() { if(this.isInWater()) { // Stop idle animation and start swim animation when in water this.idleAnimationState.stop(); this.swimAnimationState.startIfStopped(this.tickCount); } else { // Stop swim animation when not in water this.swimAnimationState.stop(); // Handle idle animation if(this.idleAnimationTimeout <= 0) { this.idleAnimationTimeout = this.random.nextInt(40) + 80; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } } } // ... rest of your code remains the same }2. Update the Model's setupAnim method:
@Override public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch, ageInTicks); // Only animate walk when not swimming if (!entity.isInWater()) { this.animateWalk(ModAnimationDefinitions.PENGUIN_WALK, limbSwing, limbSwingAmount, 2f, 2.5f); } // Animate idle and swim based on their respective states this.animate(((PenguinEntity) entity).idleAnimationState, ModAnimationDefinitions.PENGUIN_IDLE, ageInTicks, 1f); this.animate(((PenguinEntity) entity).swimAnimationState, ModAnimationDefinitions.PENGUIN_SWIM, ageInTicks, 1f); }Key Changes:
- Added
swimAnimationStateto PenguinEntity to track swimming animation - Updated
setupAnimationStates()to properly switch between idle and swim animations based on whether the penguin is in water - Modified
setupAnim()in the model to:- Only play walk animation when NOT in water
- Added the swim animation using the new animation state
- Both idle and swim animations are included, but only one will be active at a time based on the entity's state
This setup ensures:
- When in water: swim animation plays, idle and walk animations stop
- When on land: idle animation plays when stationary, walk animation plays when moving
- Smooth transitions between animation states
The animations will now properly reflect whether the penguin is swimming or on land!
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.