Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/traben/entity_model_features/EMF.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ---------------------
// ---------------------------------------------------------------------------------


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<UUID, ModelPart[]> entitiesPausedParts = new Object2ObjectOpenHashMap<>();
public static ObjectSet<UUID> entitiesPaused = new ObjectOpenHashSet<>();
public static List<Function<EMFEntity, Boolean>> pauseListeners = new ArrayList<>();
Expand All @@ -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<EMFEntity, Boolean> pauseListener : pauseListeners) {
try {
if (pauseListener.apply(entity)) return true;
Expand Down Expand Up @@ -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<EMFEntity, Boolean> pauseListener : pauseListeners) {
try {
if (pauseListener.apply(entity)) return true;
Expand All @@ -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());
Expand Down