Cardinal Components API

Cardinal Components API

21M Downloads

Ticking doesn't work in component subclass

molniya0207 opened this issue ยท 2 comments

commented

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.

commented

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)...

commented

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 :)