#variable animation

36 messages · Page 1 of 1 (latest)

balmy escarp
#

I register my variable using the API (registerSingletonAnimationVariable). I don't understand how to access it. Either I am registering it incorrectly, or I don't know what to do.

package net.axosotle.animation_fix;

import com.ibm.icu.message2.Mf2DataModel;
import com.mojang.logging.LogUtils;
import net.bettercombat.api.client.BetterCombatClientEvents;
import net.minecraft.util.valueproviders.SampledFloat;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import org.slf4j.Logger;
import traben.entity_model_features.EMFAnimationApi;

import java.util.function.BooleanSupplier;


@Mod(AnimationFix.MODID)
public class AnimationFix {

    public static final String MODID = "animation_fix";
    public static final Logger LOGGER = LogUtils.getLogger();

    public AnimationFix(IEventBus modEventBus, ModContainer modContainer) {
        modEventBus.addListener(this::onClientSetup);
    }

    public void onClientSetup(FMLClientSetupEvent event) {
        BooleanSupplier supplier = () -> {
            LOGGER.info("HFOURHFGRHGO");
            return Variable.BC_ATTACKING;
        };
        EMFAnimationApi.registerSingletonAnimationVariable(
                MODID,
                "bc_attacking",
                "True while Better Combat attack animation is playing",
                supplier
        );
    }

    @OnlyIn(Dist.CLIENT)
    public static class Variable {
        public static boolean BC_ATTACKING = false;
    }
}



#

NeoForge 1.21.1

balmy escarp
#

<@&950951012536033290>

#

sorry for ping 🥲

stoic willow
#

Does the variable work in model animations?

balmy escarp
stoic willow
#

the supplier will be called and its value read when it is used in an animation on an EMF jem model

#

this creepers head will double in size while the bc_attacking variable is true

#

it reads it 3 times per frame

balmy escarp
#

TRUTH HUGE THANKS I WAS STRUGGLING ALL EVENING YESTERDAY, but it turns out you just need to address it that way (I addressed it via varb.name)

#

❤️

stoic willow
#

varb's are your own variables made directly there in the model

#

typically to combine complex checks

balmy escarp
#

I am making Better Combat Spell Engine and Fresh Animations: Player Extension compatible.

stoic willow
#

nice

balmy escarp
# stoic willow nice

Is there a supported way to register a float variable from a NeoForge mod? The SampledFloat overload crashes with a ClassCastException due to classloader isolation.

stoic willow
#

should be the same way, what are you doing?

#

entity sound features has examples of this

#

i think it only adds functions though

balmy escarp
#
        
EMFAnimationApi.registerSingletonAnimationVariable(
                MODID,
                "bc_blend_out",
                "Blend out factor after Better Combat attack ends",
                (rand) -> 1
        );
#

For example, I register float virable, and Minecraft crashes. What am I doing wrong?

stoic willow
#

what is rand?

balmy escarp
#
 static void registerSingletonAnimationVariable(String sourceModId, String variableName, String variableExplanationTranslationKeyOrText, SampledFloat variableValueSupplier) {
        if (sourceModId != null && variableName != null && variableValueSupplier != null && variableExplanationTranslationKeyOrText != null) {
            VariableRegistry.getInstance().registerSimpleFloatVariable(variableName, variableExplanationTranslationKeyOrText, (MathValue.ResultSupplier)variableValueSupplier);
            EMFUtils.log("Successful registration of singleton variable:" + variableName + " from mod " + sourceModId);
        } else {
            EMFUtils.logError("Invalid registration of singleton variable:" + variableName + " from mod " + sourceModId);
        }

    }

EMF methot

#

in its arguments, it has SampledFloat variableValueSupplier

#

public interface SampledFloat {
    float sample(RandomSource var1);
}
stoic willow
balmy escarp
#

onClientSetup

    public AnimationFix(IEventBus modEventBus, ModContainer modContainer) {
        modEventBus.addListener(this::onClientSetup);
    }

    public void onClientSetup(FMLClientSetupEvent event) {
        BooleanSupplier supplier = () -> Variable.BC_ATTACKING;
        EMFAnimationApi.registerSingletonAnimationVariable(
                MODID,
                "bc_attacking",
                "True while Better Combat attack animation is playing",
                supplier
        );

        EMFAnimationApi.registerSingletonAnimationVariable(
                MODID,
                "bc_blend_out",
                "Blend out factor after Better Combat attack ends",
                (rand) -> 1
        );
    }

stoic willow
#

show the full crash

balmy escarp
stoic willow
#

ah that does appear to be on my end

balmy escarp
#

possibly )

stoic willow
#

seems when i did the api i accidentally made it the wrong value it isnt meant to be a SampledFloat

#

for now use VariableRegistry.getInstance().registerSimpleFloatVariable(variableName, variableExplanationTranslationKeyOrText, variableValueSupplier); that the api method itself calls

#

until i update the api

#

should have been Supplier<Float>