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

Capability not getting saved/loaded on world save/load. Using the same writeNBT and loadNBT methods for updating the client with changes works, so the methods themselves are writing to nbt and reading from it fine.

 

public class DefaultDrafter implements IDrafter{
        public static class DrafterStorage implements IStorage<IDrafter>{

	public static final DrafterStorage drafterStorage = new DrafterStorage();

	@Override
	public NBTBase writeNBT(Capability<IDrafter> capability, IDrafter instance, EnumFacing side) {
		NBTTagCompound nbtDrafterCapabilities = new NBTTagCompound();
		NBTTagCompound nbtLuxinLevel = new NBTTagCompound();
		NBTTagCompound nbtLuxinCap = new NBTTagCompound();
		NBTTagCompound nbtLuxinAvailable = new NBTTagCompound();
		NBTTagCompound nbtDraftables = new NBTTagCompound();
		nbtDrafterCapabilities.setFloat("draft_cap", ((DefaultDrafter)instance).draftCap);
		nbtDrafterCapabilities.setFloat("draft_used", ((DefaultDrafter)instance).draftUsed);
		nbtDrafterCapabilities.setInteger("sick_ticks", ((DefaultDrafter)instance).sickTicks);
		nbtDrafterCapabilities.setString("drafting_selection", ((DefaultDrafter)instance).draftingSelection);
		for(String luxin : ((DefaultDrafter)instance).luxinLevel.keySet())
		{
			nbtLuxinLevel.setFloat(luxin, ((DefaultDrafter)instance).luxinLevel.get(luxin));
			nbtLuxinCap.setFloat(luxin, ((DefaultDrafter)instance).luxinCap.get(luxin));
			nbtLuxinAvailable.setFloat(luxin, ((DefaultDrafter)instance).luxinAvailable.get(luxin));
		}
		for(String draft : ((DefaultDrafter)instance).draftables.keySet())
			nbtDraftables.setTag(draft, CoreFactory.saveNBT(((DefaultDrafter)instance).draftables.get(draft)));
		nbtDrafterCapabilities.setTag(CAP, nbtLuxinCap);
		nbtDrafterCapabilities.setTag(LEVEL, nbtLuxinLevel);
		nbtDrafterCapabilities.setTag(AVAILABLE, nbtLuxinAvailable);
		nbtDrafterCapabilities.setTag(DRAFTABLE, nbtDraftables);
		return nbtDrafterCapabilities;
	}

	@Override
	public void readNBT(Capability<IDrafter> capability, IDrafter instance, EnumFacing side, NBTBase nbt) {
		NBTTagCompound nbtExtendedProperties = (NBTTagCompound) nbt;
		NBTTagCompound nbtLuxinLevel = nbtExtendedProperties.getCompoundTag(LEVEL);
		NBTTagCompound nbtLuxinCap = nbtExtendedProperties.getCompoundTag(CAP);
		NBTTagCompound nbtLuxinAvailable = nbtExtendedProperties.getCompoundTag(AVAILABLE);
		NBTTagCompound nbtDraftables = nbtExtendedProperties.getCompoundTag(DRAFTABLE);
		((DefaultDrafter)instance).draftCap = nbtExtendedProperties.getFloat("draft_cap");
		((DefaultDrafter)instance).draftUsed = nbtExtendedProperties.getFloat("draft_used");
		((DefaultDrafter)instance).sickTicks = nbtExtendedProperties.getInteger("sick_ticks");
		((DefaultDrafter)instance).draftingSelection = nbtExtendedProperties.getString("drafting_selection");
		for(String luxin : nbtLuxinLevel.getKeySet())
		{
			((DefaultDrafter)instance).luxinLevel.put(luxin, nbtLuxinLevel.getFloat(luxin));
			((DefaultDrafter)instance).luxinCap.put(luxin, nbtLuxinCap.getFloat(luxin));
			((DefaultDrafter)instance).luxinAvailable.put(luxin, nbtLuxinAvailable.getFloat(luxin));
		}
		for(String draft : ((DefaultDrafter)instance).draftables.keySet())
			((DefaultDrafter)instance).draftables.put(draft, CoreFactory.loadNBT((NBTTagCompound) nbtDraftables.getTag(draft)));
	}

}
}

public class DraftingProvider implements ICapabilityProvider{

@CapabilityInject(IDrafter.class)
public static Capability<IDrafter> CHROMATPLAYER = null;

private IDrafter drafter = null;

public DraftingProvider(){}

public DraftingProvider(IDrafter drafter){
	this.drafter = drafter;
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
	return CHROMATPLAYER != null && capability == CHROMATPLAYER;
}

@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	if (CHROMATPLAYER != null && capability == CHROMATPLAYER) return (T)drafter;
	return null;
}

CommonProxy{
        public void preInit(){
                CapabilityManager.INSTANCE.register(IDrafter.class, DrafterStorage.drafterStorage, DefaultDrafter.class);
        }
}

 

and this in my EventHandler

@SubscribeEvent
public void AttachCapability(AttachCapabilitiesEvent.Entity e)
{
	if(!e.getEntity().hasCapability(DraftingProvider.CHROMATPLAYER, null) && e.getEntity() instanceof EntityPlayer)
		e.addCapability(Refs.DRAFTER, new DraftingProvider(new DefaultDrafter()));
}

 

is there something I am missing?

 

------------------------

Solution:

Implement INBTSerializable in your provider.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

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.