Jump to content

Recommended Posts

Posted (edited)

So, I have a capability storing some data, so I want to keep the data when the player dies (if resetOnDeath is false) or when he comes back from the end dimension.

Here's my code:

    @SubscribeEvent
    public void onPlayerClone(PlayerEvent.@NotNull Clone event) {
        if (!event.isWasDeath() || !ServerConfig.resetOnDeath.get()) {
            Player original = event.getOriginal();
            original.reviveCaps();
            original.getCapability(PlayerCapabilityProvider.PLAYER_CAP).ifPresent(oldCap -> {
                event.getEntity().getCapability(PlayerCapabilityProvider.PLAYER_CAP).ifPresent(newCap -> {
                    newCap.setNBTData(oldCap.getNBTData());
                });
            });
            original.invalidateCaps();
        }
    }

Event is registered though the Forge EventBus, registration is located at FMLCommonSetupEvent.

When testing in a singleplayer world, everything seems to be perfectly working. When I join a server however and die, the respawn button does nothing. Any ideas?

PS: I'm using latest Forge version 43.1.43 for 1.19.2.

Edited by Darkorg69
PS
Posted
7 hours ago, Darkorg69 said:
PlayerEvent.@NotNull Clone

This is badly formatted.

7 hours ago, Darkorg69 said:

When I join a server however and die, the respawn button does nothing.

Do you mean the respawn button doesn't work? Or that the data isn't copied?

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.