Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.

Posted (edited)

One last question. Do i still need my storage class? Because i don't use it but i need to pass an instance of a storage class when registering my Capability.

Edited by Meldexun

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.