Jump to content

[1.18]How to add PlayerData


ocome

Recommended Posts

    @SubscribeEvent
    public  void onPlayerPreTick(final TickEvent.PlayerTickEvent  event ,final AttachCapabilitiesEvent<Entity> event1){
      Player player = event.player;
      boolean iof = player  instanceof Player;
        if (iof ==true) {
            LazyOptional<MyCapabilityInterface> stats1 = player.getCapability(MyCapability.INSTANCE);
            MyCapabilityInterface myCapabilityInterface = stats1.orElseThrow(IllegalStateException::new);
            myCapabilityInterface.tick(event.player);
            final MyCapabilityProviderEntity provider = new MyCapabilityProviderEntity(player);
            event1.addCapability(IDENTIFIER, provider);

Is this what you mean? I'm getting an error on this one, but...

 

Edited by ocome
Link to comment
Share on other sites

Do you mean to call Event instead of tickevent and get each item from there?

 

In the case of ManaOvarlay, it was good without using addCapability,

and I thought it would be the same way this time, but I couldn't figure out why this was bad

Edited by ocome
Link to comment
Share on other sites

no, you need both the TickEvent which calls your custom logic each Tick and the AttachCapabilitiesEvent which adds the Capability to all Entities which should hava your Capability.

Read the doc about Events it explains everything about how to use Events. If you don't know how to create a Event handler, I would recommend you to first learn the basics of java before modding minecraft 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.