diff --git a/src/main/java/traben/entity_model_features/EMF.java b/src/main/java/traben/entity_model_features/EMF.java index 171c626a..02565c62 100644 --- a/src/main/java/traben/entity_model_features/EMF.java +++ b/src/main/java/traben/entity_model_features/EMF.java @@ -95,6 +95,14 @@ public String getSubTitle() { //register EMF physics mod hook //todo RagdollMapper.addHook(new EMFCustomRagDollHookTest()); + + + //#if FORGE && MC >= 12001 + if (ETF.isThisModLoaded("playeranimator")) { + EMFAnimationApi.registerPauseCondition(PALCompat::shouldPauseEntityAnim); + } + //#endif + //#if !FORGE && MC >= 12101 if (ETF.isThisModLoaded("player_animation_library")) { EMFAnimationApi.registerPauseCondition(PALCompat::shouldPauseEntityAnim); diff --git a/src/main/java/traben/entity_model_features/mod_compat/PALCompat.java b/src/main/java/traben/entity_model_features/mod_compat/PALCompat.java index 3c5c95fb..f7a2f70b 100644 --- a/src/main/java/traben/entity_model_features/mod_compat/PALCompat.java +++ b/src/main/java/traben/entity_model_features/mod_compat/PALCompat.java @@ -9,9 +9,19 @@ //$$ import com.zigythebird.playeranim.accessors.IAnimatedPlayer; //$$ import com.zigythebird.playeranim.animation.PlayerAnimManager; //#endif +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; import traben.entity_model_features.utils.EMFEntity; +import traben.entity_model_features.utils.EMFUtils; + +import java.lang.reflect.Method; public class PALCompat { + + private static boolean checkedIfIEmotePlayerExists = false; + private static Class iEmotePlayerEntityType = null; + private static Method isPlayingEmoteMethod = null; + public static boolean shouldPauseEntityAnim(EMFEntity entity) { //#if FORGE || MC <12100 //#elseif MC>=12109 @@ -25,6 +35,61 @@ public static boolean shouldPauseEntityAnim(EMFEntity entity) { //$$ return manager != null && manager.isActive(); //$$ } //#endif - return false; + + //EMFUtils.log("Emoting: " + isPlayerEmoting(entity)); + // When emoting with EMOTECRAFT mod, the player will be forced to his vanilla model to emote properly + return isPlayerEmoting(entity); + } + + // --------------------------------------------------------------------------------- + // ------------------------ EMOTECRAFT comptability section ------------------------ + + public static boolean isPlayerEmoting(EMFEntity entity) { + if (!(entity instanceof Player player)) return false; + + Method emoteMethod = getIsPlayingEmoteMethod(); + if (emoteMethod == null) return false; + + try { + return (boolean) emoteMethod.invoke(player); + } catch (Exception ignored) { + return false; + } + } + + private static @Nullable Class getIEmotePlayerEntityType() { + if (checkedIfIEmotePlayerExists) return iEmotePlayerEntityType; + checkedIfIEmotePlayerExists = true; + + try { + // Tries to get the IEmotePlayerEntity interface in order to access the isPlayingEmote() method + // https://github.com/KosmX/emotes/blob/1.20.1/executor/src/main/java/io/github/kosmx/emotes/executor/emotePlayer/IEmotePlayerEntity.java + // This type should always be found if EmoteCraft mod doesn't change it too much and the mod is actually loaded obv + iEmotePlayerEntityType = Class.forName("io.github.kosmx.emotes.executor.emotePlayer.IEmotePlayerEntity"); + } catch (ClassNotFoundException ignored) { + iEmotePlayerEntityType = null; + } + + return iEmotePlayerEntityType; + } + + private static @Nullable Method getIsPlayingEmoteMethod() { + if (isPlayingEmoteMethod != null) return isPlayingEmoteMethod; + + Class emotePlayerType = getIEmotePlayerEntityType(); + if (emotePlayerType == null) return null; + + try { + isPlayingEmoteMethod = emotePlayerType.getMethod("isPlayingEmote"); + } catch (NoSuchMethodException ignored) { + isPlayingEmoteMethod = null; + } + + return isPlayingEmoteMethod; } + + // -------------------- end of EMOTECRAFT comptability section --------------------- + // --------------------------------------------------------------------------------- + + } \ No newline at end of file diff --git a/src/main/java/traben/entity_model_features/models/animation/EMFAnimationEntityContext.java b/src/main/java/traben/entity_model_features/models/animation/EMFAnimationEntityContext.java index f20666b0..46adfe88 100644 --- a/src/main/java/traben/entity_model_features/models/animation/EMFAnimationEntityContext.java +++ b/src/main/java/traben/entity_model_features/models/animation/EMFAnimationEntityContext.java @@ -8,7 +8,6 @@ import it.unimi.dsi.fastutil.objects.ObjectSet; import net.minecraft.client.Minecraft; import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.nbt.CompoundTag; @@ -46,10 +45,8 @@ import org.jetbrains.annotations.Nullable; import traben.entity_model_features.EMF; import traben.entity_model_features.EMFManager; -import traben.entity_model_features.mixin.mixins.accessor.Mixin_GuiEntityTester; import traben.entity_model_features.mixin.mixins.accessor.MinecraftClientAccessor; import traben.entity_model_features.mod_compat.IrisShadowPassDetection; -import traben.entity_model_features.mod_compat.PALCompat; import traben.entity_model_features.models.EMFModelMappings; import traben.entity_model_features.models.EMFModel_ID; import traben.entity_model_features.models.animation.state.EMFEntityRenderState; @@ -63,7 +60,6 @@ //$$ import net.minecraft.world.entity.monster.illager.Vindicator; //#endif -import java.lang.reflect.Method; import java.util.*; import java.util.function.Function; @@ -101,10 +97,6 @@ public final class EMFAnimationEntityContext { private static boolean announceModels = false; private static float frameCounter = 0; - private static boolean checkedIfIEmotePlayerExists = false; - private static Class iEmotePlayerEntityType = null; - private static Method isPlayingEmoteMethod = null; - public static Object2ObjectOpenHashMap entitiesPausedParts = new Object2ObjectOpenHashMap<>(); public static ObjectSet entitiesPaused = new ObjectOpenHashSet<>(); public static List> pauseListeners = new ArrayList<>(); @@ -123,7 +115,6 @@ public static boolean isEntityAnimPaused() { // API for other mods to pause animations on specific entities var entity = emfState.emfEntity(); if (entity != null) { - if (isPlayerEmoting(entity)) return true; for (Function pauseListener : pauseListeners) { try { if (pauseListener.apply(entity)) return true; @@ -155,7 +146,6 @@ private static boolean isEntityAnimPausedBackupDontMixinToThisOneUseTheNewAPI() // API for other mods to pause animations on specific entities var entity = emfState.emfEntity(); if (entity != null) { - if (isPlayerEmoting(entity)) return true; for (Function pauseListener : pauseListeners) { try { if (pauseListener.apply(entity)) return true; @@ -166,51 +156,6 @@ private static boolean isEntityAnimPausedBackupDontMixinToThisOneUseTheNewAPI() return entitiesPaused.contains(emfState.uuid()); } - private static boolean isPlayerEmoting(EMFEntity entity) { - if (!(entity instanceof Player player)) return false; - - Method emoteMethod = getIsPlayingEmoteMethod(); - if (emoteMethod == null) return false; - - try { - return (boolean) emoteMethod.invoke(player); - } catch (Exception ignored) { - return false; - } - } - - private static @Nullable Class getIEmotePlayerEntityType() { - if (checkedIfIEmotePlayerExists) return iEmotePlayerEntityType; - checkedIfIEmotePlayerExists = true; - - try { - // Tries to get the IEmotePlayerEntity interface in order to access the isPlayingEmote() method - // https://github.com/KosmX/emotes/blob/1.20.1/executor/src/main/java/io/github/kosmx/emotes/executor/emotePlayer/IEmotePlayerEntity.java - // This type should always be found if EmoteCraft mod doesn't change it too much and the mod is actually loaded obv - iEmotePlayerEntityType = Class.forName("io.github.kosmx.emotes.executor.emotePlayer.IEmotePlayerEntity"); - } catch (ClassNotFoundException ignored) { - iEmotePlayerEntityType = null; - } - - return iEmotePlayerEntityType; - } - - private static @Nullable Method getIsPlayingEmoteMethod() { - if (isPlayingEmoteMethod != null) return isPlayingEmoteMethod; - - Class emotePlayerType = getIEmotePlayerEntityType(); - if (emotePlayerType == null) return null; - - try { - isPlayingEmoteMethod = emotePlayerType.getMethod("isPlayingEmote"); - } catch (NoSuchMethodException ignored) { - isPlayingEmoteMethod = null; - } - - return isPlayingEmoteMethod; - } - - public static @Nullable ModelPart[] getEntityPartsAnimPaused() { if (emfState == null) return null; var parts = entitiesPausedParts.get(emfState.uuid());