Skip to content

Commit

Permalink
Late init refresh animations. Fix #147
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Nov 8, 2023
1 parent e023777 commit 99fd631
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.tr7zw.notenoughanimations;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;

public class NEAnimationsMod extends NEAnimationsLoader implements ModInitializer {
@Override
public void onInitialize() {
onEnable();
ClientTickEvents.START_CLIENT_TICK.register(event -> this.clientTick());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.tr7zw.notenoughanimations;

import net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -23,6 +25,11 @@ public NEAnimationsModForge() {
ModLoadingContext.get().registerExtensionPoint(ConfigScreenFactory.class, () -> new ConfigScreenFactory((mc, screen) -> {
return createConfigScreen(screen);
}));
MinecraftForge.EVENT_BUS.addListener(this::doClientTick);
}

private void doClientTick(ClientTickEvent event) {
this.clientTick();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class NEAnimationsLoader {
public PlayerTransformer playerTransformer;
public HeldItemHandler heldItemHandler;
public AnimationProvider animationProvider;
private boolean lateInitCompleted = false;

public void onEnable() {
INSTANCE = this;
Expand Down Expand Up @@ -62,6 +63,18 @@ private void enable() {
heldItemHandler = new HeldItemHandler();
animationProvider = new AnimationProvider();
}

private void lateInit() {
animationProvider.refreshEnabledAnimations(); // refresh once after the game is loaded, so all other mods are done initializing
}

public void clientTick() {
// run this code later, so all other mods are done loading
if (!lateInitCompleted) {
lateInitCompleted = true;
lateInit();
}
}

public void writeConfig() {
if (settingsFile.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void apply(AbstractClientPlayer entity, PlayerData data, PlayerModel<Abst
}
HumanoidArm arm = part == BodyPart.LEFT_ARM ? HumanoidArm.LEFT : HumanoidArm.RIGHT;
float g = entity.getUseItemRemainingTicks() - delta + 1.0F;
float h = g / entity.getUseItem().getUseDuration();
// float h = g / entity.getUseItem().getUseDuration();
AnimationUtil.applyArmTransforms(model, arm,
-(Mth.lerp(-1f * (entity.getXRot() - 90f) / 180f, 1f, 2f)) + Mth.abs(Mth.cos(g / 4.0F * 3.1415927F) * 0.2F),
-0.3f, 0.3f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import dev.tr7zw.notenoughanimations.util.AnimationUtil;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;

public class NarutoRunningAnimation extends BasicAnimation {

Expand Down

0 comments on commit 99fd631

Please sign in to comment.