Skip to content

Commit

Permalink
Rascal idle animation, tweaked tuff golem sleep, format
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Oct 20, 2023
1 parent 9b0a279 commit 8fca1ba
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public static void animateKeyframe(
float f = getRunningSeconds(animation, runningTime);
Iterator var7 = animation.boneAnimations().entrySet().iterator();

while(var7.hasNext()) {
Map.Entry<String, List<Transformation>> entry = (Map.Entry)var7.next();
Optional<ModelPart> optional = model.getChild((String)entry.getKey());
List<Transformation> list = (List)entry.getValue();
while (var7.hasNext()) {
Map.Entry<String, List<Transformation>> entry = (Map.Entry) var7.next();
Optional<ModelPart> optional = model.getChild((String) entry.getKey());
List<Transformation> list = (List) entry.getValue();
optional.ifPresent((part) -> {
list.forEach((transformation) -> {
Keyframe[] keyframes = transformation.keyframes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.faboslav.friendsandfoes.client.render.entity.model;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.client.render.entity.animation.KeyframeAnimation;
import com.faboslav.friendsandfoes.client.render.entity.animation.animator.ModelAnimator;
import com.faboslav.friendsandfoes.entity.animation.AnimatedEntity;
import com.faboslav.friendsandfoes.mixin.ModelPartAccessor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.faboslav.friendsandfoes.client.render.entity.model;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.entity.TuffGolemEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.*;
import net.minecraft.util.math.MathHelper;

@Environment(EnvType.CLIENT)
public final class TuffGolemEntityModel<T extends TuffGolemEntity> extends AnimatedEntityModel<T>
Expand Down Expand Up @@ -72,15 +70,6 @@ public void setAngles(
float headYaw,
float headPitch
) {
/*
if(tuffGolem.isHoldingItem() && tuffGolem.hurtTime != 0) {
limbDistance = 1.0F;
limbAngle = 1.0F;
}
FriendsAndFoes.getLogger().info(String.valueOf(limbDistance));
FriendsAndFoes.getLogger().info(String.valueOf(limbAngle));*/

this.getPart().traverse().forEach(ModelPart::resetTransform);
this.updateMovementKeyframeAnimations(tuffGolem, limbAngle, limbDistance, 4.0F, 4F);
this.updateKeyframeAnimations(tuffGolem, animationProgress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public AnimationContextTracker getAnimationContextTracker() {
this.animationContextTracker.add(keyframeAnimation);
}

this.animationContextTracker.add(RascalAnimations.WALK);
this.animationContextTracker.add(this.getMovementAnimation());
}

return this.animationContextTracker;
Expand Down Expand Up @@ -197,21 +197,14 @@ public void tick() {
this.playReappearSound();
}

if (this.getWorld().isClient() == false && this.isAnyKeyframeAnimationRunning()) {
this.setKeyframeAnimationTicks(this.getKeyframeAnimationTicks() - 1);
if (this.getWorld().isClient() == false) {
this.updateKeyframeAnimationTicks();
}

KeyframeAnimation keyframeAnimationToStart = this.getKeyframeAnimationByPose();

if (
keyframeAnimationToStart != null
&& this.isKeyframeAnimationRunning(keyframeAnimationToStart) == false
) {
if (this.getWorld().isClient() == false) {
this.setKeyframeAnimationTicks(keyframeAnimationToStart.getAnimationLengthInTicks());
}

this.startKeyframeAnimation(keyframeAnimationToStart);
if (keyframeAnimationToStart != null) {
this.tryToStartKeyframeAnimation(keyframeAnimationToStart);
}

super.tick();
Expand All @@ -221,7 +214,7 @@ public void tick() {
private KeyframeAnimation getKeyframeAnimationByPose() {
KeyframeAnimation keyframeAnimation = null;

if (this.isInPose(RascalEntityPose.IDLE)) {
if (this.isInPose(RascalEntityPose.IDLE) && this.isMoving() == false) {
keyframeAnimation = RascalAnimations.IDLE;
} else if (this.isInPose(RascalEntityPose.NOD)) {
keyframeAnimation = RascalAnimations.NOD;
Expand All @@ -232,6 +225,18 @@ private KeyframeAnimation getKeyframeAnimationByPose() {
return keyframeAnimation;
}

private void tryToStartKeyframeAnimation(KeyframeAnimation keyframeAnimationToStart) {
if (this.isKeyframeAnimationRunning(keyframeAnimationToStart)) {
return;
}

if (this.getWorld().isClient() == false) {
this.setKeyframeAnimationTicks(keyframeAnimationToStart.getAnimationLengthInTicks());
}

this.startKeyframeAnimation(keyframeAnimationToStart);
}

private void startKeyframeAnimation(KeyframeAnimation keyframeAnimationToStart) {
for (KeyframeAnimation keyframeAnimation : this.getAnimations()) {
if (keyframeAnimation == keyframeAnimationToStart) {
Expand Down Expand Up @@ -393,6 +398,10 @@ public boolean isHidden() {
return this.getBrain().getOptionalMemory(MemoryModuleType.AVOID_TARGET).orElse(null) instanceof PlayerEntity;
}

public boolean isMoving() {
return this.isOnGround() && this.getVelocity().lengthSquared() >= 0.0001;
}

public int getCaughtCount() {
return this.dataTracker.get(CAUGHT_COUNT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.client.render.entity.animation.KeyframeAnimation;
import com.faboslav.friendsandfoes.client.render.entity.animation.RascalAnimations;
import com.faboslav.friendsandfoes.client.render.entity.animation.TuffGolemAnimations;
import com.faboslav.friendsandfoes.client.render.entity.animation.animator.context.AnimationContextTracker;
import com.faboslav.friendsandfoes.entity.ai.brain.TuffGolemBrain;
Expand All @@ -28,7 +27,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
Expand Down Expand Up @@ -103,7 +101,7 @@ public ArrayList<KeyframeAnimation> getAnimations() {

@Override
public KeyframeAnimation getMovementAnimation() {
if(this.isHoldingItem()) {
if (this.isHoldingItem()) {
return TuffGolemAnimations.WALK_WITH_ITEM;
}

Expand Down Expand Up @@ -833,10 +831,6 @@ public void stopMovement() {
this.upwardSpeed = 0.0F;
}

public boolean isMoving() {
return this.isOnGround() && this.getVelocity().lengthSquared() >= 0.0001;
}

public enum Color
{
RED("red"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ public static void setSleepCooldown(TuffGolemEntity tuffGolem) {
MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE,
FriendsAndFoesMemoryModuleTypes.TUFF_GOLEM_SLEEP_COOLDOWN.get()
);
SLEEP_COOLDOWN_PROVIDER = UniformIntProvider.create(2400, 7200);
SLEEP_COOLDOWN_PROVIDER = UniformIntProvider.create(6000, 8000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public final class TuffGolemSleepTask extends Task<TuffGolemEntity>
{
private final static int MIN_TICKS_TO_SLEEP = 2400;
private final static int MAX_TICKS_TO_SLEEP = 4800;
private final static int MIN_TICKS_TO_SLEEP = 6000;
private final static int MAX_TICKS_TO_SLEEP = 12000;

public TuffGolemSleepTask() {
super(ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.entity.animation;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.client.render.entity.animation.KeyframeAnimation;
import com.faboslav.friendsandfoes.client.render.entity.animation.animator.context.AnimationContextTracker;
import com.faboslav.friendsandfoes.client.render.entity.animation.animator.context.KeyframeAnimationContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.mixin;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.entity.pose.RascalEntityPose;
import com.faboslav.friendsandfoes.entity.pose.TuffGolemEntityPose;
import net.minecraft.entity.EntityPose;
Expand Down

0 comments on commit 8fca1ba

Please sign in to comment.