Cardinal-Components-API icon indicating copy to clipboard operation
Cardinal-Components-API copied to clipboard

Ticking doesn't work in component subclass

Open molniya0207 opened this issue 2 years ago • 2 comments

The README says:

If you want your component to tick alongside its provider, you can add the ServerTickingComponent or ClientTickingComponent (or both) to your component interface (here, IntComponent). If you'd rather add the ticking interface to a single component subclass, you can use one of the specific methods provided in the individual modules.

And the example shows adding ticking interface to component subclass. So, I tried implementing ServerTickingComponent in my component subclass:

public class PlayerManaComponent implements ManaComponent, AutoSyncedComponent, ServerTickingComponent
{
    @Override
    public void serverTick() {
        Magicat.LOGGER.info("PlayerManaComponent#serverTick");
    }
}

But it never ticked. But docs says you can add ServerTickingComponent to your component interface, so after seeking for help I found this out and did this:

public interface ManaComponent extends Component, ServerTickingComponent

(serverTick still in PlayerManaComponent class) And it worked. For some reason ticking doesn't work in component subclasses. Either it is wrong docs, or something wrong with the code.

molniya0207 avatar Mar 15 '22 12:03 molniya0207

Ah right, I guess this part could be improved :

If you want your component to tick alongside its provider, you can add the ServerTickingComponent or ClientTickingComponent (or both) to your component interface (here, IntComponent). If you'd rather add the ticking interface to a single component subclass, you can use one of the specific methods provided in the individual modules.

What this was supposed to mean is that if you put the ticking on a subtype, you must use registry.beginRegistration().impl(PlayerManaComponent.class)...

Pyrofab avatar Mar 15 '22 16:03 Pyrofab

Okay, with a bit trial and error, this works:

// old line:
registry.registerForPlayers(PLAYER, ModPlayer::new, RespawnCopyStrategy.ALWAYS_COPY);
// new line:
registry.beginRegistration(PlayerEntity.class, PLAYER).impl(ModPlayer.class).end(ModPlayer::new);

Thanks for the Thread and eventual documentation adjustment :)

alex-haas avatar Oct 08 '22 14:10 alex-haas