Changed

Changed

184k Downloads

issues with the UniversalAbilitiesEvent

Foxyas opened this issue ยท 38 comments

commented

idk why and how but the event is not called when is need making the possibility to add new Universal Abilities be limited by mixins

2024-11-12.00-45-15.mp4
commented

idk why and how but the event is not called when is need making the possibility to add new Universal Abilities be limited by mixins

2024-11-12.00-45-15.mp4

What is this SubscribeEvent about?

The @SubscribeEvent is a Anotation that "say" that X method will be executed when the Event selected in the method is called

commented

That's not what I'm saying, I'm saying what is the event you're trying to call for?

commented

That's not what I'm saying, I'm saying what are you doing with the time you're trying to call?

Oh the code just add one new universal Ability if the Entitytype is A latexs and is not a partial Latex

commented

Check earlier in your logs, that event is fired when the variants are registered on game launch.

commented

Check earlier in your logs, that event is fired when the variants are registered on game launch.

i check it and still any of the loggers was called and i can see that the event is not called due the universal abilities not being add when the condition is applied

i check if was a issue with the events due my issues with them before [because i'm dumb] but all the others events of the API are working just fine

commented

image
image

commented

question, the MinecraftForge.EVENT_BUS.post(event); call the event and set the abilities list or just call the event?

commented

Can I see the code?

commented

Screenshots are fine too.

commented

Can I see the code?

The code is just a normal execution of the event like

//Imports here


@Mod.EventBusSubscriber
public static class className {
     @SubscribeEvent
     public static void CoolVoidName(TransfurVariant.UniversalAbilitiesEvent event){
    //A logger to show if the event is called
    // event.addAbility here
   }
}
commented

Can I see the code?

The video show the code aswell

commented

Did you register the custom SubscribeEvent? It doesn't look like it belongs to forge in any way

commented

be like:

public class CustomEvent extends Event {
    private final String message;

    public CustomEvent(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}
commented

the event was automatically registered as FORGE or atleast is what the logs say but i can try use a manual registry one

commented

be like:

public class CustomEvent extends Event {
    private final String message;

    public CustomEvent(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}

That would create a new event and i'm trying just to execute the event

commented

idk why and how but the event is not called when is need making the possibility to add new Universal Abilities be limited by mixins

2024-11-12.00-45-15.mp4

What is this SubscribeEvent about?

commented

i test using the own Changed Workspace and still the the event is not called

code location is
image

package net.ltxprogrammer.changed.TESTSTUFF;

import net.ltxprogrammer.changed.entity.variant.TransfurVariant;
import net.ltxprogrammer.changed.init.ChangedAbilities;
import net.ltxprogrammer.changed.init.ChangedTags;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class testClass {

    @SubscribeEvent
    public static void lol(TransfurVariant.UniversalAbilitiesEvent event){
        event.addAbility(event.isOfTag(ChangedTags.EntityTypes.LATEX),ChangedAbilities.PUDDLE);
    }
}
commented

maybe i find out why, the builder is not registered before the event be able to call, and i find out that because i try use a mixin to add a universal ability in the method "<init>" at "TAIL" and the objects [Builder and the Transfur Variants] was not even registered causing a crash

commented

i check it more and i saw that for some reason not matter where the event is posted the event will not be post

i try make the event be posted in the Build method but still is not called

commented

maybe a option to fix that would be adding a method to add a ability in the player TransfurVariantInstance?
add the universal abilities when the Instance is created or just create a method to add a Ability instance in the list

commented

i make it working BUT i move the Event to the TransfurVariantInstance Instead of the Builder Of the TransfurVariant, because for some REASON that i don't understand why yet the event is not called in the Build of the TransfurVariant

commented

the line that i change

public TransfurVariantInstance(TransfurVariant<T> parent, Player host) {
        this.parent = parent;
        this.entity = parent.generateForm(host, host.level);
        this.host = host;

        this.transfurMode = parent.transfurMode;

        var builder = new ImmutableMap.Builder<AbstractAbility<?>, AbstractAbilityInstance>();
        List<Function<EntityType<?>, ? extends AbstractAbility<?>>> list = new ArrayList<>(parent.abilities);
        var event = new TransfurVariant.UniversalAbilitiesEvent(list);
        MinecraftForge.EVENT_BUS.post(event);
        list.forEach(abilityFunction -> {
            var ability = abilityFunction.apply(this.parent.getEntityType());
            if (ability != null)
                builder.put(ability, ability.makeInstance(IAbstractChangedEntity.forPlayer(host)));
        });
        abilityInstances = builder.build();
        if (abilityInstances.size() > 0)
            selectedAbility = abilityInstances.keySet().asList().get(0);
    }
commented

and btw when i try use a mixin to Inject a ability in the TransfurVariant.Builder cause a crash saying that the Object don't was Registered

commented

anyway that fix that i make fix the issue with the event BUT maybe can cause a issue with variants that have a Selected Ability List and would not be the good idea to add a Ability for a Transfur that have a specific Ability list

commented

maybe a solution would have a boolean to lock the ability list but idk

commented

I think the event is being broadcasted to early in the mod loading process.

commented

I think the event is being broadcasted to early in the mod loading process.

I did some changes and that fixed but instead of Being in the builder of the transfur it's had to be in the Creation of the Transfurs Variant Instance

Idk if you would like that change but i make a pull request showing what i change in the code

commented

I saw that, but I wanted to have the event only happen once at launch.

commented

even mixins fail because the object was not registered when the mixin tried to add the code that apply the extra ability

commented

The MinecraftForge.EVENT_BUS is shutdown until the mods have completed loading.

commented

I saw that, but I wanted to have the event only happen once at launch.

I don't know if this is possible because I try to use several methods, like having the event be executed before the construction of the Builder of Transfur Variants and making return a list and with that list added to all variants that meet the criteria,add the event handle in the builder [public void i mean], and other kind of method like this but all my attempts fail

you have more experience than me so i guess that you can figure out something =/

commented

I swapped it to FMLJavaModLoadingContext.get().getModEventBus(), and I believe it will work.

hoping for good luck :D

commented

The MinecraftForge.EVENT_BUS is shutdown until the mods have completed loading.

oh so that explain alot of thing lol

commented

I swapped it to FMLJavaModLoadingContext.get().getModEventBus(), and I believe it will work.

commented

Hey btw could you add a method for add a Ability for a Transfur Variant Instance? :>

commented

Like a addAbility(), i'm thinking in create a feature where the old you get More Abilities you unlock and a method to add a Ability would help with that alot :>

commented

I had considered such a feature myself.

commented

I had considered such a feature myself.

That would make a little sense, wouldn't it? Like you wouldn't just know how use the specime power instantly after being transfurred