Jump to content

[1.11.2] [SOLVED] Player Capabilities


Bektor

Recommended Posts

Hi,

 

I've got a player capability and I am wondering now how I can save the data so that when the player

dies the capability still exists for the player, but also when the world is reloaded or the client restarts.

 

Thx in advance.

Bektor

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Just now, pWn3d said:

https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

 

You need to copy them on PlayerCloneEvent.

Ok and what do I have to do when I reload the world or restart the client?

 

Just to note, I got this code for registering the capability, so NBT stuff is already there:

		CapabilityManager.INSTANCE.register(IStarpower.class, new Capability.IStorage<IStarpower>() 
		{
		    
            @Override
            public NBTBase writeNBT(Capability<IStarpower> capability, IStarpower instance, EnumFacing side) 
            {
                
                return new NBTTagInt(instance.getStarpower());
            }

            @Override
            public void readNBT(Capability<IStarpower> capability, IStarpower instance, EnumFacing side, NBTBase nbt) 
            {
                instance.set(((NBTPrimitive) nbt).getInt());
            }
		}, Starpower::new);

 

Developer of Primeval Forest.

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.