Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticking doesn't work in component subclass #122

Open
molniya0207 opened this issue Mar 15, 2022 · 2 comments
Open

Ticking doesn't work in component subclass #122

molniya0207 opened this issue Mar 15, 2022 · 2 comments

Comments

@molniya0207
Copy link

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.

@Pyrofab
Copy link
Member

Pyrofab commented Mar 15, 2022

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

@alex-haas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants