Jump to content

[1.13.2] Custom player capability not working after changing dimension


xerca

Recommended Posts

I have a strange problem where a capability that otherwise works perfectly well doesn't work after changing dimensions, such as going to the nether or back to overworld. I did some debugging and found where the error is but I don't understand why it exists.

 

  • When an entity is removed (such as when changing dimensions), it's invalidateCaps() method is called, so its valid field becomes false. This means when player.getCapability is called for whichever capability, it returns LazyOptional.empty():
  • public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable EnumFacing side)
    {
        final CapabilityDispatcher disp = getCapabilities();
        return !valid || disp == null ? LazyOptional.empty() : disp.getCapability(cap, side);
    }
  • Entity is also removed when it dies, but upon respawning the AttachCapabilitiesEvent is called again both on the client and the server threads, and the capability works fine.
  • However, when the entity changes dimensions, the AttachCapabilitiesEvent is only called on the client thread. I don't know if this has anything to do with the problem.

 

If anyone knows how to deal with this problem, I would appreciate the help.

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.