Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Saving data for player


Recommended Posts

Hi there,

I want to save 2 BlockPos for a player. They don't need to be saved when leaving and reentering the world. I thought of adding a Capability to the player but then i have to save something as NBT. Is there an easier way to save 2 BlockPos for a player?

Thanks for the help.

Edited by Meldexun
Link to post
Share on other sites

Yes I don't need to save the data. But how can I stop it from saving NBT data.

This is my provider class:

public class StructureDataProvider implements ICapabilitySerializable<NBTBase> {
	
	@CapabilityInject(IStructureData.class)
	public static final Capability<IStructureData> STRUCTURE_DATA = null;
	
	private IStructureData instance = STRUCTURE_DATA.getDefaultInstance();
	
	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
		return capability == STRUCTURE_DATA;
	}
	
	@Override
	public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
		return capability == STRUCTURE_DATA ? STRUCTURE_DATA.<T> cast(this.instance) : null;
	}
	
	@Override
	public NBTBase serializeNBT() {
		return STRUCTURE_DATA.getStorage().writeNBT(STRUCTURE_DATA, this.instance, null);
	}
	
	@Override
	public void deserializeNBT(NBTBase nbt) {
		STRUCTURE_DATA.getStorage().readNBT(STRUCTURE_DATA, this.instance, null, nbt);
	}
	
}

and this is my storage class:

public class StructureDataStorage implements IStorage<IStructureData> {

	@Override
	public NBTBase writeNBT(Capability<IStructureData> capability, IStructureData instance, EnumFacing side) {
		return new NBTTagInt(0);
	}

	@Override
	public void readNBT(Capability<IStructureData> capability, IStructureData instance, EnumFacing side, NBTBase nbt) {
		
	}

}

 

What i mean is that it now saves a NBTTagInt which is pointless because i don't use/need it. But I have to return a NBTBase. Can i change something to avoid this unnecessary data saving.

Link to post
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.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.