Posted July 9, 20178 yr 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 July 9, 20178 yr by Bektor Developer of Primeval Forest.
July 9, 20178 yr https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ You need to copy them on PlayerCloneEvent.
July 9, 20178 yr Author 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.
July 9, 20178 yr Write your fields you need to store to nbt in the write method, and read them from nbt in the read method. nbt.setBoolean("tagname",boolean1); boolean1 = nbt.getBoolean("tagname");
July 9, 20178 yr Author Ok, I found out that my CapabilityProvider has to implement INBTSerializable and has to call my write and read NBT methods from my NBTTag. Developer of Primeval Forest.
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.