Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

I just need to save the 2 BlockPos on server side temporarily. But is this really the only/best way?

  • Author

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.

  • Author

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.